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); } }
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.
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
Don't see what you're looking for? Try a search.
|