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

2018/1/9

The text isnt updating ,help me please

PacArts PacArts

2018/1/9

#
I have programmed a game like Break Out, i want to make a lifecounter so, if the ball hits the bottom the "3 lifes" get -1, and when this happends the text should display "3 lifes"... look at my code and tell me whats wrong PS: Im german so "Leben" means "lifes" and "spielball" is the object from the ball:
public byte c=3;
---------------------
public void lifecounter(){
        if(c == 3){
            showText("3 Leben",300,500);
        }
        else{
            if(c == 2){
                showText("2 Leben",300,500);
            }
            else{
                if(c == 1){
                    showText("1 Leben",300,500);
                }
                else{
                    if(c == 0){
                        showText("GAME OVER",300,500);
                        Greenfoot.stop();
                    }
                }
            }
        }
    }
-----------------------
 public void lifemachine(){
         if(spielball.getY() > 780){
            c--;
        }
    }
I wrote this in the world subclass
PacArts PacArts

2018/1/9

#
What i forgot, at the beginning, in game it shows the text "3 Leben" but if the ball hits the ground nothing happens to the text
danpost danpost

2018/1/9

#
After line 27, you need to call 'lifecounter' to update the text.
PacArts PacArts

2018/1/9

#
like this? : if(spielball.getY() > 780){ c--; lifecounter();}
Yehuda Yehuda

2018/1/10

#
Yes. You need to execute the line of code which changes the display. Just changing the variable 'c' won't change the counter unless the 'lifeCounter' method is always being called (in the 'act' method).
You need to login to post a reply.