This site requires JavaScript, please enable it in your browser!
Greenfoot back
AniSusi
AniSusi wrote ...

2019/6/22

disable methods

AniSusi AniSusi

2019/6/22

#
is it possible to disable methods? not removing the actor, just disable some stuff, for example: if my enemy dies, he performs an animation, however he still fires and gets hit by bullets which causes problems.
Super_Hippo Super_Hippo

2019/6/22

#
You can exit the act method when it is dead after playing the animation.
AniSusi AniSusi

2019/6/22

#
how do I do that?
Super_Hippo Super_Hippo

2019/6/22

#
public void act()
{
    //do everything which should always happen even if it is dead, for example play animation
    
    if (hp<0) //if the object is dead
    {
        return; //exit the method and don't execute anything below
    }
    
    //rest of act method which should only be executed when the object is alive
}
AniSusi AniSusi

2019/6/22

#
Thank you so much! It worked!
You need to login to post a reply.