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

2018/2/28

Problem with changing the image of a text

HardToFindAName HardToFindAName

2018/2/28

#
Hello. I want to have a finish screen and I want to display some text, however when I run it and form the image, the image doesn't change.
river lume=new river();
            if (lume.getObjects(Counter.class).get(0).getValue()>100 && !adaugat){
                GreenfootImage imagine=new GreenfootImage("Felicitari",100,Color.GREEN,Color.GREEN);
                this.setImage(imagine);
                adaugat=true;
            }
I have the object added somewhere in the middle and I want it to display after it checks the value from the score board if it's bigger than 100. If yes, display that text, but it doesn't change.
danpost danpost

2018/2/28

#
You are creating an alternate world instance with the first line. You want the score from the real world. Use this for the first line
river lume = (river)getWorld();
Also, the code given must be executed while the actor is in the world. So, move it from the constructor -- override the 'addedToWorld(World)' method of the Actor class and add the code in it:
protected void addedToWorld(World world)
{
    river lume = (river)world;
    // etc.
}
You need to login to post a reply.