Skip to content Skip to sidebar Skip to footer

Libgdx What Is The Proper Way To Copy An Actor?

I have a custom implementation of Image that animates. I want to make multiple copies of an instance of this class using the minimum memory and processor time for rendering and cop

Solution 1:

If you really want to take care about Memory you can give all actors the same Image. But if you change the image in some way and at one of the Actors it does change at all actors with it(I did it with a sprite and changed the TextureRegion. All my Monsters looked at the same direction). But if you simply just have the same Image the whole time you can create your Objects and give all the same reference to one Image. For example like this:

public ArrayList<Actor> generateImageActor(){
        ArrayList<Actor> temp = new ArrayList<Actor>();
        Image img = new Image(____);
        for(int i = 0; i <10; i++){
            MyActor act = new MyActor(img);
            temp.add(act);
        }
        return temp;
    }

The rendertime does not get any effect if you refare to one image or to always a new image. I simply does take the picture and its offsett and draws it. So if you refare to 1 image at 10 actors it has the same rendertime else if you would have 10 actors with a copy of the image. Hope this helps.

Post a Comment for "Libgdx What Is The Proper Way To Copy An Actor?"