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

2019/2/25

setting actor's image

petyritonel petyritonel

2019/2/25

#
so i have a 3 level game that has to change the background for each level, and i have a background actor to do this. the problem is that when i start the second level, the background image is still initially the first one and it takes a quick second for it to change to the second one. i would like to know if there's a way to have it set to the second picture by the time the second level starts.
danpost danpost

2019/2/25

#
petyritonel wrote...
so i have a 3 level game that has to change the background for each level, and i have a background actor to do this. the problem is that when i start the second level, the background image is still initially the first one and it takes a quick second for it to change to the second one. i would like to know if there's a way to have it set to the second picture by the time the second level starts.
You will need to show your codes for review.
petyritonel petyritonel

2019/2/25

#
I have thisin my background actor:
public static GreenfootImage picture; 
    public void act() 
    {
        setImage(picture);
}
this in level1's act:
background.picture = new GreenfootImage ("background1.png"); 
and this in level2's act:
background.picture = new GreenfootImage ("background2.png"); 
initially the background is set to "background1.png"; after level1 is over, level2 starts, and it changes the picture, but for the first frame it still shows the first image...
danpost danpost

2019/2/25

#
petyritonel wrote...
I have thisin my background actor: << Codes Omitted >> initially the background is set to "background1.png"; after level1 is over, level2 starts, and it changes the picture, but for the first frame it still shows the first image...
You should just set the image when the level changes instead of changing the field value (background.picture). The you would not need the field or setting the image every act cycle.
petyritonel petyritonel

2019/2/25

#
how could i change that in the level2 world?
danpost danpost

2019/2/26

#
petyritonel wrote...
how could i change that in the level2 world?
Show code changing worlds.
Zestix Zestix

2019/2/26

#
You could just use multiple worlds instead of actors for that. If you complete a level, let's say you have to touch a specific object, set a condition e.g.
if (isTouching(object.class))
{
    Greenfoot.setWorld(new Level2());
}
Each world has a different Background
petyritonel petyritonel

2019/2/26

#
Zestix wrote...
You could just use multiple worlds instead of actors for that. If you complete a level, let's say you have to touch a specific object, set a condition e.g.
if (isTouching(object.class))
{
    Greenfoot.setWorld(new Level2());
}
Each world has a different Background
\i do have different worlds, but the background is moving, that's why i'm using an actor
petyritonel petyritonel

2019/2/26

#
danpost wrote...
petyritonel wrote...
how could i change that in the level2 world?
Show code changing worlds.
this reminded me that i should change the picture when setting the new world, not once it's set. thank you.
You need to login to post a reply.