A Yo-Yo

This movie uses the sin function to make a ball bounce
Get Adobe Flash player
Experiment: can you make the ball go from side to side instead of up and down?
Can you make it move across the stage as it bounces?
//variables
var angle:Number=0;
var distance:Number=50;
var origY:Number=ball.y;
var rate:Number=0.5;

//initialize
this.addEventListener(Event.ENTER_FRAME,frames);

//functions
function frames(e:Event):void {
	ball.y=origY+Math.sin(angle)*distance;
	angle=angle+rate;
}//frames
Download the FLA file

INDEX, Math functions, Arrow follows cursor, A Yo-yo with sin function, Eyes follow the cursor
Next lesson: Random Numbers: Math.Random()

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

A Yo-yo with sin function