Copy link to clipboard
Copied
When velocity is greater than 4 , the ball should stop . i also tried the code if(xx>4) { ball.stop(); } inside score . and outside scope . . but does not work
// set gravity amount
var gravity:Number = .000098;
// set starting velcity
var xx:Number = 0.2;
// mark start time and add listener
var lastTime:int = getTimer();
addEventListener(Event.ENTER_FRAME, animateBall);
// step animation
function animateBall(event:Event) {
// get time difference
var timeDiff:int = getTimer()-lastTime;
lastTime += timeDiff;
// adjust vertical speed for gravity
xx+= gravity*timeDiff;
// move ball
ball.rotation += timeDiff*xx;
}
if(xx>4) {
ball.stop();
}
that code will stop the timeline of ball, but it won't stop ball from rotating.
if you want to stop ball from rotating when xx>4, use:
...
// set gravity amount
var gravity:Number = .000098;
// set starting velcity
var xx:Number = 0.2;
// mark start time and add listener
var lastTime:int = getTimer();
addEventListener(Event.ENTER_FRAME, animateBall);
// step animation
function animateBall(event:Event) {
// get time difference
var timeDiff:int = getTimer()-lastTime;
lastTime += timeDiff;
Copy link to clipboard
Copied
that code will stop the timeline of ball, but it won't stop ball from rotating.
if you want to stop ball from rotating when xx>4, use:
// set gravity amount
var gravity:Number = .000098;
// set starting velcity
var xx:Number = 0.2;
// mark start time and add listener
var lastTime:int = getTimer();
addEventListener(Event.ENTER_FRAME, animateBall);
// step animation
function animateBall(event:Event) {
// get time difference
var timeDiff:int = getTimer()-lastTime;
lastTime += timeDiff;
// adjust vertical speed for gravity
xx+= gravity*timeDiff;
// move ball
if(xx<=4){
ball.rotation += timeDiff*xx;
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now