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

2015/1/30

display string from actor in world

Nizuka Nizuka

2015/1/30

#
so, im a bit new in greenfoot, and we had an project about making an asteroid shooter. it's almost done, but i need the amount on bullets the ship has on screen, and that wont work out for me. This is the code for the ship Actor
 private int energyLevel = 100;
    private int delta = 4;
    private int triggerCounter = 0;
       
        public void act() 
    {
      *stuff that doesnt really matter*
}
I want to display the energyLevel in my world, i already tried this
this.showText(Bullets left: " + String.valueOf(energyLevel), 500, 380);
but greenfoot doesnt know what to do with the "showText" pls help
Super_Hippo Super_Hippo

2015/1/30

#
'showText' is a method of world, not actor. (Just in case this is used in an Actor subclass, I can't see this in your code snippet.) In front of the word "Bullets" you need another double quote.
getWorld().showText("Bullets left: " + energyLevel, 500, 380);
You need to login to post a reply.