繁体   English   中英

在舞台上添加无限数量的演员(libGDX)

[英]Add unlimited number of actors on stage (libGDX)

^ h嗷嗷我可以增添无限的图像(演员)的球员加入,他希望在舞台上任意数量的形象

例如:假设演员是这张图片 在此处输入图片说明 ,并且玩家希望将其从舞台坐标的任何点添加到任何点。 作为开发人员,我不知道要在舞台上添加多少个图像。

  • 也许5张图片

在此处输入图片说明

  • 也许是4张图片

在此处输入图片说明

我知道以下代码不完整:(在render方法中)

 Vector2 position = stage.screenToStageCoordinates(new Vector2(Gdx.input.getX(), Gdx.input.getY()));
 image.setPosition(position.x, position.y);
 stage.addActor(image);

任何人都有主意..?

关于演员数的舞台没有限制(尽管您应该注意,许多演员会影响表演),因此您可以在编写时在render方法中创建它们。 如果要在用户输入和某些条件下创建它们则应使用InputListener

要做的是创建一个类似“ Buil House”的按钮,然后单击它,检查玩家是否有足够的钱, 然后创建新的actor并将其添加到舞台上 -重要的是,您不能两次添加同一actor

     Button button = new Button(skin, "buildButton");

     button.addListener(buildListener);

     ...

     ClickListener buildListener = new ClickListener()
            {
                public void clicked(InputEvent event, float x, float y) 
                {
                    if( cash > BUILDING_COST )
                    {
                        Image building = createBuildig(); //it can be also some class inherits actor if you want it to have some more informations
                        building.setPosition(position.x, position.y); //some position

                        //you can also add actor to some array to process it lateer somehow...

                        stage.addActor( building );
                    }
                }
    };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM