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

2019/3/9

Scoreboard not working

R0b1n R0b1n

2019/3/9

#
i have made a score board for my game but it works in my level1 but not in my level2. can someone help. This one works:
public void pickFlowers()
    {
        if(canSee(Flower.class))
        {

            Flower flower = (Flower) getOneObjectAtOffset(0, 0, Flower.class);
            if(flower.getPoisonous())
            {
                removeObject (LittleRedCap.class);
                score=score-5;

            }else {
                score++;
            }
            removeObject (Flower.class);

            World world = getWorld();
            world.removeObjects(world.getObjects(ScoreBoard.class));
            world.addObject (new ScoreBoard(score), 75,25);

        }
    }
This one doesnt
 public void CoinGrab()
    {
       
        if(canSee(Coins.class))
        {
            Coins coins = (Coins) getOneObjectAtOffset(0, 0, Coins.class);
            score=score++;
        }
        removeObject(Coins.class);
        
        World world = getWorld();
        world.removeObjects(world.getObjects(ScoreBoard.class));
        world.addObject (new ScoreBoard(score), 75,50);
    }
some extra incase needed
public class ScoreBoard  extends Actor 
{
    // instance variables - replace the example below with your own
    private int score;
    public static final float FONTSIZE = 24.0f;
    public static final int WIDTH = 150;
    public static final int HEIGHT = 50;
    public static final int TRANSPARENCY = 128;
    public static final int RED = 255;
    public static final int GREEN = 255;
    public static final int BLUE = 255;

    public ScoreBoard(int scoreParameter) 
    {
        score=scoreParameter;    
        makeScoreBoard();

    }
  addObject(new ScoreBoard(0),75,50);
danpost danpost

2019/3/9

#
You have stuff inside the canSee if block in the working one that is outside in the not working one.
You need to login to post a reply.