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

2013/5/12

CODE HELP PLZ

1
2
danpost danpost

2013/5/13

#
It is probably because of where you are setting the image.
danpost danpost

2013/5/13

#
You probably are setting the 'down' image in the 'setStunned' method. You should be setting the other image near the beginning of the act, as I gave:
// start your act method with
public void act()
{
    if (stunTimer > 0) // if frozen
    {
        stunTimer--;
        if (stunTimer > 0) return; // if timer not done, exit method
        setImage("up.png"); // restore normal image
    }
    // rest of act method
}
The image should not be set anywhere else (unless you are doing more with the image than I am aware of).
SWAG SWAG

2013/5/13

#
danpost wrote...
You probably are setting the 'down' image in the 'setStunned' method. You should be setting the other image near the beginning of the act, as I gave:
// start your act method with
public void act()
{
    if (stunTimer > 0) // if frozen
    {
        stunTimer--;
        if (stunTimer > 0) return; // if timer not done, exit method
        setImage("up.png"); // restore normal image
    }
    // rest of act method
}
The image should not be set anywhere else (unless you are doing more with the image than I am aware of).
My image "up" is a gif which is from the GifActor class
danpost danpost

2013/5/13

#
If you have an animated gif for your actor, you could probably just remove line 8 above.
SWAG SWAG

2013/5/14

#
danpost wrote...
If you have an animated gif for your actor, you could probably just remove line 8 above.
Everything works thanks for the help. I have one more question. How do I make so that if it is already stunned it can't get stunned
danpost danpost

2013/5/14

#
Put the code in your 'setStunned' method within an 'if', limiting it to executing only if stunTimer is zero.
SWAG SWAG

2013/5/14

#
danpost wrote...
Put the code in your 'setStunned' method within an 'if', limiting it to executing only if stunTimer is zero.
One more Question. How can I make it so that if enemy stunned the player can't die.
danpost danpost

2013/5/14

#
You could add an instance (mirror of stunTimer) 'invincibleTimer' in your player class . Set it to the same value that 'stunTimer' gets set to right after calling 'enemy.getStunned'.
// run timer in player act method
if (invincibleTimer > 0) invincibleTimer--;
// restrict the execution of the player dying
if (invincibleTimer == 0)
{
    // check player's death
}
You need to login to post a reply.
1
2