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

2016/12/14

Slow Down Animation

Caynze Caynze

2016/12/14

#
We're trying to make a streetfighter game for class and right now the animation for the blast attack runs so fast you can't see it, we've tried 4 different ways to slow down the animation but it's not working. Any suggestions?
public void shoot(){
        setImage("blastPrep.png");
        animationCount++;
        if(animationCount==10){
            setImage("Blastshot.png");
        }
        getWorld().addObject(new RyuShot(), getX()+10, getY());
    }
Super_Hippo Super_Hippo

2016/12/14

#
I think line 7 should be after line 5 in the if-block. Then you can increase the animationCount to something higher. (10 is about a 0.2 seconds). Maybe you could check for a higher number to set it back to zero and change the image back.
Zamoht Zamoht

2016/12/14

#
How many images does the animation use? Right now it seems like you only use two. Do you ever reset "animationCount"? Please provide the animation code or explain further what you are trying to do in the posted lines.
davmac davmac

2016/12/14

#
One thing that seems to be missing from the code you posted is something that resets the "animationCount" variable back to 0. I assume you're using this variable to count down a delay until the blast shot fires. In that case you also need to avoid adding the shot object to the world until the timer has reached its limit. The above code should probably be changed to something like:
public void shoot(){
        setImage("blastPrep.png");
        animationCount++;
        if(animationCount==10){
            setImage("Blastshot.png");
            getWorld().addObject(new RyuShot(), getX()+10, getY());
            animationCount = 0;
        }
    }
However, there's important parts of the code that you haven't posted, so I'm not certain that will solve all the problems or work correctly. It is not clear to me when the shoot() method is called. If it triggers on a key down, you might want to change the trigger to (key down or animationCount != 0) so that you do not need to hold the key down in order to complete the animation.
Caynze Caynze

2016/12/15

#
So I tried the code that you provided, unfortunately it didn't help in slowing it down. The shoot animation is called when the key is down, but the animation count only ever gets to 1, because act only runs when the key is down.
public void checkKey(){
        if(Greenfoot.isKeyDown("w")==true)
        {
            jump();
        }
        else if(Greenfoot.isKeyDown("d")==true)
        {
            walkForward();
        }
        else if(Greenfoot.isKeyDown("a")==true)
        {
            walkBack();
        }
        else if(Greenfoot.isKeyDown("s")==true){
            crouch();
        }
        else if(Greenfoot.isKeyDown("f")==true && shot==0){
            shoot();
        }
public void shoot() {
        setImage("blastPrep.png");
        animationCount++;
        if(animationCount==10){
            setImage("Blastshot.png");
            getWorld().addObject(new RyuShot(), getX()+10, getY());
            animationCount = 0;
        }
    }


    }
Zamoht Zamoht

2016/12/15

#
Is "shot" ever set to anything else than 0? Maybe you could show the whole class.
Nosson1459 Nosson1459

2016/12/16

#
The shoot() method is only called if 'f' is the ONLY key down and if shot is equal to 0, I can't figure out the problem without the whole class code.
davmac wrote...
there's important parts of the code that you haven't posted, so I'm not certain that will solve all the problems or work correctly.
P. S. For checking if a boolean is true such as a key press you just have to do
if(Greenfoot.isKeyDown("w"))
without the equals true, and for equals false you can do
if (!booleanName)
. Why do you have "else if" after each loop? Now you can't shoot and walk at the same time I think it should be like this (but this is YOUR scenario):
public void checkKey()
{
    if(Greenfoot.isKeyDown("d"))
    {
        walkForward();
    }
    else if(Greenfoot.isKeyDown("a"))
    {
        walkBack();
    }
    if(Greenfoot.isKeyDown("w"))
    {
        jump();
    }
    else if(Greenfoot.isKeyDown("s"))
    {
        crouch();
    }
    if(Greenfoot.isKeyDown("f") && shot==0)
    {
        shoot();
    }
    
    public void shoot()
    {
        setImage("blastPrep.png");
        animationCount++;
        if(animationCount==10)
        {
            setImage("Blastshot.png");
            getWorld().addObject(new RyuShot(), getX()+10, getY());
            animationCount = 0;
        }
    }

}
danpost danpost

2016/12/16

#
You need to move the running of the animation counter to outside the 'shoot' method -- maybe in your 'checkKey method outside any 'if' blocks already there. Also 10 act cycles is usually quite a short amount of time (maybe one-sixth of a second) -- you may want to increase its limiting value in your line 23 above to slow it down.
You need to login to post a reply.