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

2016/7/30

Problems with setImage method

import greenfoot.*;

/**
 * Write a description of class Turtle here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CaveMan extends Animals
{
    private int lettuceEaten;
    private int counter;
    /**
     * Act - do whatever the Turtle wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public CaveMan ()
    {
        lettuceEaten = 0;
        counter= 0;
    }
    public void act() 
    {
        move (3);
        if ( Greenfoot.isKeyDown("left"))
        { 
            turn(-5);
        }
        if ( Greenfoot.isKeyDown("right"))
        { 
            turn(5);
        }
    
        if(isTouching(Burger.class))
        {
            removeTouching(Burger.class);
            Greenfoot.playSound("slurp.wav");
            
            lettuceEaten = lettuceEaten + 1;
            if (lettuceEaten == 1)
            {
                setImage("winner.png");
                setLocation (getX(), getY());
                Greenfoot.playSound("fanfare.wav");
                Greenfoot.stop();
        }
    }    
}
}
We never know if the win image will appear or if the lose image appears. When I commented out the setImage method it seemed more reliable. any thoughts on what might be the problem.
danpost danpost

2016/7/30

#
OfficerJelloKangaroo wrote...
< Code Omitted > We never know if the win image will appear or if the lose image appears. When I commented out the setImage method it seemed more reliable. any thoughts on what might be the problem.
How can a win or lose image appear when the line is commented out? You must have code elsewhere in your project that is relevant here.
You need to login to post a reply.