LibGdx复制Actor的正确方法是什么? [英] LibGdx What is the proper way to copy an Actor?

查看:126
本文介绍了LibGdx复制Actor的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的Image动画实现.我想使用最少的内存和处理器时间来渲染和复制该类实例的多个副本.我该怎么办?每当我需要另一个时,重新创建它只是最简单的方法,还是有一些适当的或建议的方法来复制Image实例.我之所以这样问,是因为找不到副本构造函数,也不知道.clone()是否在Image中实现.

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 copying. How do I go about it? Is it just easiest to recreate it whenever I need another one or is there some proper or suggested method for copying Image instances. I ask this because I can't find a copy constructor and I don't know if .clone() is implemented in Image.

推荐答案

如果您真的想照顾内存,可以为所有演员提供相同的图像.但是,如果您以某种方式更改图像,并且在其中一个Actor上,它的确会在所有actor上更改(我使用Sprite进行了更改,并更改了TextureRegion.我的所有Monsters都朝同一方向看).但是,如果您始终只是拥有相同的Image,则可以创建对象并为一个Image提供所有相同的引用.
例如这样的例子:

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;
    }


如果您引用一个图像或始终引用一个新图像,则渲染时间不会产生任何效果.我只是简单地拍摄照片及其偏移量并绘制它.因此,如果您拒绝10个演员的1个图像,则它具有相同的渲染时间,否则,如果您有10个演员及其图像的副本,则渲染时间相同.
希望这会有所帮助.


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.

这篇关于LibGdx复制Actor的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆