Groups | Blog | Home
all groups > flash actionscript > august 2005 >

flash actionscript : Movie clip problem



t-juice-t
8/12/2005 10:45:23 PM
I've programmed a movie clip to move slowly towards the bottom of the screen.
When it gets there, you're supposed to lose a life and it goes back to the top.
It moves towards the bottom of the screen, but when it gets there, it just
keeps going and no lives are lost. (I have some more script counting the
number of lives in another movie clip).

onClipEvent (enterFrame) {
speed = 1;
_y += speed;
if (y == 290) {
Lives = PreLives - 1;
PreLives = Lives;
y = 0;
}
if (Lives == 0) {
gotoAndPlay("Game Over", 1);
}
}
Rothrock
8/12/2005 11:28:31 PM
First thing I notice is that you are check if y is equal to 290. Shouldn't that
be _y?

But generally you should never count on a clip hitting an exact pixel
position. There are oh so many reasons why. So instead do this.

if(_y>-290){}

Also I would put the check for lives inside of the earlier if statement. As it
is, you are checking it every time the onEnterFrame runs ? which I'm guessing
is a lot. By nesting it in the other if statement, it will only run each time
the clip gets to the bottom.
t-juice-t
8/13/2005 12:33:26 AM
Thanks, that did the trick. I also found an easier way to do lives. When you
lose one, instead of changing variables, and throwing numbers around, I just
use _root.play and it plays a life loss sequence and then stops until you lose
a life again. This also ads about a second of invulnurability after you lose a
life. Thanks again,

juice
AddThis Social Bookmark Button