Question

Hi i have an issues with my AS2 code when the health reaches zero it should go to the next scene called "gameOver" but it seems to do nothing but it is working because it is tracing the output "hello".

I don't know why the actual function is not working but here is the code that i have used

In the Home scene:

    userScore = 0;
    userHealth = 100;
    stop();

In the movie clip object

    onClipEvent(enterFrame){
           if (this.hitTest(_root.enemy) && _root.userHealth <= 0)
{
    nextScene();
}
                           }

In the enemy movie clip object

    onClipEvent (enterFrame) {

if (this.hitTest(_root.ball))
{
    _root.userHealth -= 10;
}
    }

There is a stop in the gameOver scene as well so that it doesn't just jump onto the next scene.

I am still a beginner so do take it easy on me haha thanks

Was it helpful?

Solution

I believe this will fix it.

 onClipEvent(enterframe)
 {
    if (this.hitTest(_root.enemy) && _root.userHealth <= 0)
    {
    gotoAndPlay(scene # of gameover frame);
    }
 }

I had a similar bug when I was creating PAC-MAN and that fixed mine. Good luck. Cheers! Also I suggest you have all your variable declaration on the first frame, the write the game on frame two. It will help with initializing and stop from resets.

Another thing, why do you have...

 if (this.hitTest(_root.enemy) && _root.userHealth <= 0)

It is saying if this hits the enemy and your health is 0, game over. I suggest you have...

 if (this.hitTest(_root.enemy) || _root.userHealth <= 0)

Note: || means OR.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top