Ask a Question related to Macromedia Flash Sitedesign, Design and Development.
-
zecka3 #1
Bouncing Ball... Help
I used to have a problem controling a ball with the key up, then someone
gave me the following script to resolve the problem (thank's TRALFAZ) :
onLoad = function() {
dir = -1; // up
inMotion = 0;
}
// move ball from 350 y to 150 y when key up is pressed
onEnterFrame = function() {
// up key only works when ball is not in motion
if(!inMotion && Key.isDown(Key.UP))
inMotion = 1;
if(inMotion)
{
// simulated gravity.
// slow down when approaching apex at 150
// minimum speed is 2
speed = 2 + (ball._y - 150) * .3;
ball._y += (speed * dir);
if(ball._y <= 150) // at the apex, change direction
{
dir = 1; // change direction to down
}
else if(ball._y >= 350) // at the bottom, stop (should bounce)
{
inMotion = 0; // stop motion
dir = -1; // changed direction to up
}
}
}
....and it did, but now i can't make the ball land in the same _y twice, as I
inteded ( it should always land on _y = 250)...
can someone please help me...
much appreciated
zecka3 Guest
-
Age old table bouncing question
Hi, I started designing in CSS a few months back after doing it in tables for a few years. Recently got a request to update a site for a friend... -
Bouncing mail
How can i get the bouncing mail ids from the coldfusion log file? let me know whether the incoming and outgoing details will be there? Thanks in... -
Bouncing mails
Al Kaibala DO YOU READ THIS? List members, As administrator of the Linux SIG List, I am getting bounces for mail addressed to kabalg@localhost... -
bouncing ball
hi, if you check out this link : http://www.atreyuonline.com/flash/gravity.html You will see i've got a bouncing ball and a red bar across... -
bouncing objects
Im looking for a good tutorial for making bouncing objects with colisions, does anyone know a good one ? -
tralfaz #2
Re: Bouncing Ball... Help
I> ...and it did, but now i can't make the ball land in the same _y twice, asThe example code made the object bounce up from 350y up to 150y and back> inteded ( it should always land on _y = 250)...
> can someone please help me...
down to 350y. If you want the bottom at 250, just change all the 350s to
250s. You can set the 150s to a smaller number if you want the ball to move
higher.
good luck,
tf
tralfaz Guest
-
zecka3 #3
Re: Bouncing Ball... Help
"tralfaz" <tralfazmx@yahoo.cam> wrote in message
news:buig46$1ge$1@forums.macromedia.com...as>> > ...and it did, but now i can't make the ball land in the same _y twice,move> I>> > inteded ( it should always land on _y = 250)...
> > can someone please help me...
> The example code made the object bounce up from 350y up to 150y and back
> down to 350y. If you want the bottom at 250, just change all the 350s to
> 250s. You can set the 150s to a smaller number if you want the ball toI'm sorry for trouble you but, the thing is that the freeking ball> higher.
> good luck,
> tf
>
doesn't land in the same _y pos twice , it keeps on changing if you don't
mind i put an example here [url]http://jdf.planetaclix.pt/exp.html[/url] if you could
take a look to it I´d appreciated.
Thank´s
zecka3 Guest
-
tralfaz #4
Re: Bouncing Ball... Help
When the movieclip is rotating it affects the _Y value if the registration
point is not exactly in the center. If you can't easily fix that, you could
try using a variable to track the y position like this:
onLoad = function() {
dir = -1; // up
pos = 300; // position tracking variable
}
// move ball from 300 y to 150 y when key up is pressed
onEnterFrame = function() {
// up key only works when ball is not in motion
if(!inMotion && Key.isDown(Key.UP))
inMotion = 1;
if(inMotion)
{
// simulated gravity.
// slow down when approaching apex at 150
// minimum speed is 2
speed = 2 + (ball._y - 150) * .3;
pos += (speed * dir); // update the tracking var
ball._y = pos; // make the clip the same as pos
if(pos <= 150)
{
dir = 1; // change direction to down
}
else if(pos >= 300) // check the var instead of the clip
{
ball._y = pos; // force the clip to position 300
inMotion = 0; // stop motion
dir = -1; // changed direction to up
}
}
}
I hope that will do it for ya,
tf
don't> I'm sorry for trouble you but, the thing is that the freeking ball
> doesn't land in the same _y pos twice , it keeps on changing if you> mind i put an example here [url]http://jdf.planetaclix.pt/exp.html[/url] if you could
> take a look to it I´d appreciated.
>
> Thank´s
tralfaz Guest



Reply With Quote

