当libgdx使用的演员?有什么缺点和优点? [英] When to use actors in libgdx? What are cons and pros?

查看:185
本文介绍了当libgdx使用的演员?有什么缺点和优点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写简单的太阳能系统模拟器。 这是我第一次libgdx的项目。我使用的主菜单的舞台和演员,是pretty的方便尤其是触摸事件处理。但是...看我看没人用在实际的游戏逻辑演员的例子。我徘徊,如果我应该用演员的星球类的父,母或只写我自己的类器的。 行星不会触摸和它们将被移至仅在帧之间以便行动MoveBy的第三个参数将必须是帧之间的时间。 这是缺点。有哪些优点,使用演员?

I'm writing simple solar system simulator. This is my first libgdx project. I'm using a Stage and Actors for the main menu and is pretty handy especially touch events handling. But ... looking at the examples i see nobody uses actors in actual game logic. I wander if i should use actor as a parent of planet class or just write my own class tor that. The planets won't be touchable and they will be moved only between the frames so the third parameter of action MoveBy will have to be time between frames. That are the cons. What are the pros for using Actors?

推荐答案

对于演员的主要优点是操作,点击测试和触摸事件,和组演员。

The main pros for Actors are Actions, Hit testing and touch events, and Groups of Actors.

行动作出快速,轻松补间,如果你的游戏逻辑需要的。

Actions make quick and easy tweening if your game logic needs that.

您可以随时拨打stage.hit(X,Y​​),以返回到任何打逻辑分析,你写的(一般是检查范围与X,Y,宽,高)返回true的第一个演员。返回该演员或空通过演员的命中方法寻找一击的演员,以保持迭代。如果没有演员被击中则返回null。

You can call stage.hit(x, y) at any time to return the first actor that returns true to whatever hit logic you wrote for it (usually checking bounds with x, y, width, height). return this actor or null to keep iterating through the actors' hit methods looking for a hit actor. Null is returned if no actor is hit.

命中用于舞台的触摸事件。演员的触摸方法传递局部坐标,并在舞台处理重叠的物体,如如果一个演员涵盖了另一位演员这样,其他演员不应该接受着陆,返回true上的覆盖演员停止触地调用上的演员之下。这也会设置焦点上,这样演员的润色将被调用时返回true演员。

Hit is used for the Stage's touch events. The actor's touch methods are passed local coordinates, and the Stage handles overlapping of objects, e.g. if an actor covers another actor such that the other actor shouldn't receive touchDown, return true on the covering actor to stop the calling of touchDown on actors "beneath". This also sets 'focus' on the actor that returns true so that Actor's touchUp will be called.

您可以组演员一起进行操作,触摸事件等对演员的整个集团作为一个单元。

You can group actors together to perform Actions, touch events, etc on the entire Group of Actors as a single unit.

一些缺点: 演员需要一个阶段,这在一定程度限制了功能。许多codeRS使用其他逻辑来确定游戏对象的状态,而不是scene2d操作(如Bo​​x2D的)。如果您使用的演员为游戏对象,你可能会想要两个阶段,一个是用户界面和一个用于游戏世界。如果你不使用他们,你很可能会使用自己的SpriteBatch和照相机无论如何虽然。而且请记住,演员只有一个抽象的Draw方法,所以你仍然需要无论如何创建绘制逻辑。你可能会保持一个TextureRegion或雪碧作为私人领域的演员。如果你想使用自己的更新逻辑,您可以覆盖行为(浮动三角洲)方法来获得增量时间(调用super.act(增量)如果你使用操作)。

Some Cons: Actors require a stage which limits functionality somewhat. Many coders use other logic to determine game object state, rather than the scene2d Actions (e.g. box2d). If you use Actors for game objects, you will probably want two Stages, one for ui and one for game world. If you don't use them you'll probably be using your own SpriteBatch and Camera anyway though. And keep in mind that Actors only have an abstract Draw method so you will still need to create draw logic anyway. You'll probably keep a TextureRegion or Sprite as a private field for the Actor. If you want to use your own update logic, you can override the act(float delta) method to get the delta time (call super.act(delta) if you use Actions).

所以,如果你有自己的逻辑,并不会用太多的哪个阶段,所提供的,节省一些资源,推出自己的应用程序特定的解决方案。如果你可以使用一些专业人士的不限制所需要的功能,然后去第二个阶段的游戏逻辑。

So if you have your own logic and won't use much of what Stage has to offer, save some resources and roll your own application-specific solution. If you can use some of the pros without limiting needed functionality then go for a second Stage for the game logic.

这篇关于当libgdx使用的演员?有什么缺点和优点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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