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

2012/10/6

save background

actinium actinium

2012/10/6

#
How do i save the background from the screen. I draw a grid map, the cells are made up of actors, problem is i can pick up the individual cells with mouse, i want the cells to be permanently attached to the screen.
Gevater_Tod4711 Gevater_Tod4711

2012/10/6

#
If you want the actors to stay at a position you could save the coordinates of the actors and let them move to this coordinates (using setLocation). You just have to write it in the act method.
actinium actinium

2012/10/6

#
Thanks for taking time out to reply Gevater_Tod4711, i just realised when i run the scenario you cant move the cells. Silly me.
danpost danpost

2012/10/6

#
Is it neccessary that the cells still be actors? If not, add the following code (I will use the class name 'Cell' for your actor)
// In the world class, after actors are placed
actorsToBackground(Cell.class);
// repeat for different classes (in paint order)
//
// In the world class, add the following method
private void actorsToBackground(Class class)
{
    for (Object obj : getObjects(class))
    {
        Actor actor = (Actor) obj;
        int xLoc = actor.getX() - actor.getImage().getWidth() / 2;
        int yLoc = actor.getY() - actor.getImage().getHeight() / 2;
        getBackground().drawImage(actor.getImage(), xLoc, yLoc);
        removeObject(actor)
    }
}
actinium actinium

2012/10/6

#
Thanks danpost, its the drawInage method i was seeking out.
You need to login to post a reply.