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

2013/2/5

Changing images based off certain actions

r4indr0ps r4indr0ps

2013/2/5

#
I was wondering if anyone could help me with how to change an image based off of certain actions... My project is to turn one image into another after hitting a certain block on the world. I ran into this code:
public Man()
    {
        Man1 = new GreenfootImage("Man1");
        Man2 = new GreenfootImage("Man2");
    }
    
    private boolean normalMan()
    {
        setImage(Man1);
    }
    
    private boolean manOnFire()
    {
        setImage(Man2);
    }
but I'm not sure what that really means and or how I can adjust this to change from Man1 to Man2. Hopefully this isn't too confusing. Haha
danpost danpost

2013/2/5

#
I am not sure what it really means, either. I am quite sure it would not even compile as written. The methods 'normalMan' and 'manOnFire' are both showing that they are to return a boolean type value, but no values are being returned at all. Change both occurances of 'boolean' to 'void' and it will compile. Then, you will need an 'act' method to check for collision; and when the collision occurs call one of the two methods. You should call the other method in the constructor block to initially set the image of the actor.
You need to login to post a reply.