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

2014/12/2

Spent an hour on it, still can't figure it out

Dillybar Dillybar

2014/12/2

#
Any and all help with this project is appreciated. I'm stuck right now in that the code for when he is walking left works perfectly, but when he is walking right it does not switch to imageMR (Even though it switches to imageR).
private void animateMario()
    {
        if (mLeft == true && Greenfoot.isKeyDown("a"))
        {
            if (getImage() == imageL && imageDelayCount >= imageTime)
            {
                setImage(imageML);
                imageDelayCount = 0;
            }
            if (getImage() == imageML && imageDelayCount >= imageTime)
            {
                setImage(imageL);
                imageDelayCount = 0;
            }
            if (getImage() == imageR)
            {
                setImage(imageL);
                imageDelayCount = 0;
            }
            if (getImage() == imageMR)
            {
                setImage(imageL);
                imageDelayCount = 0;
            }
        }
        if (mLeft == true && Greenfoot.isKeyDown("a") == false)
        {
            setImage(imageL);
        }
        
        if (mLeft == false && Greenfoot.isKeyDown("d"))
        {
            if (getImage() == imageR && imageDelayCount >= imageTime)
            {
                setImage(imageMR);
                imageDelayCount = 0;
            }
            if (getImage() == imageMR && imageDelayCount >= imageTime)
            {
                setImage(imageR);
                imageDelayCount = 0;
            }
            if (getImage() == imageL)
            {
                setImage(imageR);
                imageDelayCount = 0;
            }
            if (getImage() == imageML)
            {
                setImage(imageR);
                imageDelayCount = 0;
            }
        }
        if (mLeft == false && !Greenfoot.isKeyDown("d") == false)
        {
            setImage(imageR);
        }
    }
Please tell me why it works for left but not right. Thanks :)
danpost danpost

2014/12/2

#
Try 'else if' on line 20. When the condition for the previous block is true, it will change the image and then make the condition on this line true.
Dillybar Dillybar

2014/12/2

#
I Can't understand why it won't work. There is nothing wrong with the if statements, as when I put in move as a test, it works. There is an issue with the image itself I think but I cannot figure it out. When I try to set it to imageMR in another place, it still doesn't work. Here is how I define it:
private GreenfootImage imageMR;
public marioG()
{
imageMR = new GreenfootImage("mariogunMR.png");
}
In the images folder, it is named mariogunMR and it is a .png file. Thanks for your help :)
danpost danpost

2014/12/2

#
In line 54, you have 'if not "d" down is false'. That could screw up the works (it is not similar to the code at line 26).
You need to login to post a reply.