View Full Version : Bouncing Ball
birdshot
02-15-2003, 03:11 AM
Does anyone have actionscript code advice for bouncing a ball off of the stage borders? All I want to do is make the forward moving ball on the _x go backwards on the _x. Simple I guess but I've busted my hump trying to figure out how to get it out of the loop (it vibrates on the last _x pixel, and I can't figure out how to get it going backwards once the ball hits the edge.) Any help gladly appreciated.-birdshot
Goosey
02-15-2003, 11:12 AM
sounds to me like you just need a simple 'actions' movieclip with:
onClipEvent (Enterframe) {
//sorry dont know the property for the max frame x/y :/ u can set it easy enough tho.
if ( _root.ball._x >= framexlimit ) {
_root.ball.xspeed = -_root.ball.xspeed
}
}
sorry if i am wrong here :\ kind of a newby myself and its like almost 7am.. need sleeeeeeeeeeeep
birdshot
02-15-2003, 03:57 PM
ok, that was not really working because I'm only two weeks into action scripting and I'm not sure I wanna delve into new territory yet. Do you have a way to do it using only variables and conditions/loops, or would there be something else involved with variables and conditions/loops to make it work? If only Flash could translate all of my cartoons in scripting, now that would be truly amazing. Thanks Goosey.
Ricod
02-15-2003, 10:18 PM
Using just if statements and variables ? Lessee :
if (_root.ball._x < 5 || _root.ball._x > 635) {
_root.ballSpeed = -_root.ballSpeed;
}
But as you can see, it's pretty much the same. I've kept a margin of 5 (let's say the ball = 10 pixels wide) and your stage is 640 pixels wide. But you have to constantly check this, or else it won't detect. That's why Goosey suggested you put this action as a clipEvent on a mc (preferably the ball or an 'actions' mc)
birdshot
02-16-2003, 07:00 AM
Thanks, I'll check it out!
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.