-
bounce effect
I have this code to make a ball bounce. it works fine, however, everything on the stage bounces. I only want the ball to bounce.
Here is my code
Code:
/* Actionscript 3.0 Bounce Effect. ball = movieclip instance name*/
var velocity = 0;
var gravity = 2;
var speed = 0.03;
var ground = 300;
Object(this).ball.addEventListener(Event.ENTER_FRAME, fl_bounce);
function fl_bounce(event:Event) {
velocity += gravity;
velocity -= speed * velocity;
y += velocity;
if (y > ground) {
y = ground;
velocity *= -0.9;
}
}
Thanks
A Fool is someone who keeps repeating the same thing, the same way, over, and over and expecting a different result
-
PHP Code:
/* Actionscript 3.0 Bounce Effect. ball = movieclip instance name*/ var velocity = 0; var gravity = 2; var speed = 0.03; var ground = 300; ball.addEventListener(Event.ENTER_FRAME, fl_bounce); function fl_bounce(event:Event) { velocity += gravity; velocity -= speed * velocity; ball.y += velocity; if (ball.y > ground) { ball.y = ground; velocity *= -0.9; } }
-
I just tried your code, and it doesn't work.
A Fool is someone who keeps repeating the same thing, the same way, over, and over and expecting a different result
-
there's nothing wrong with the code. your original script was using "y" without a qualifier - that means the entire move was programmed to move. making assumptions based on what you had, i set it so that the movie clip in that scope with the instance name of "ball" would be the only thing that moved. apparently your problem lies elsewhere.
i don't know why you'd use this: Object(this).ball - but maybe you can try using that instead of "ball".
yw
-
I copied the script you wrote, and applied it and it does not work. The ball just sits there. I'm gonna try to call the ball from the library instead of placing it on the stage, and see if that works. Thanks.
A Fool is someone who keeps repeating the same thing, the same way, over, and over and expecting a different result
-
Never mind I got it to work Thanks for your help
A Fool is someone who keeps repeating the same thing, the same way, over, and over and expecting a different result
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|