sprite和actor之间的libgdx区别 [英] libgdx difference between sprite and actor
问题描述
我只是在遍历有关libgdx的javadoc和各种教程,并且正处于试图弄清似乎与我相似或在libgdx中提供类似功能的各种概念之间的差异的阶段.
I'm just going through the javadoc and various tutorials on libgdx and I'm at the stage of trying to figure out differences between various concepts that seem similar to me or provide similar capabilities in libgdx.
起初,我以为scene2d是关于创建交互式项目(例如菜单等)的,但是我正在阅读的各种教程都将scene2d/actor用于主要游戏项目(例如,玩家等),而其他教程则仅使用精灵.
At first I thought scene2d was about creating interactive items such as menus, etc but various tutorials I'm reading use scene2d/actors for the main game items (i.e. the player, etc) and others just use sprites.
在游戏中使用Sprite和Actor(即Scene2D)到底有什么区别,什么时候应该选择?
What exactly is the difference between using Sprite and Actor (i.e. scene2D) in a game and when should you choose?
谢谢.
推荐答案
Sprite
本质上是具有位置,大小和旋转度的图像.您可以使用 SpriteBatch
,一旦有了Sprite
和SpriteBatch
,便有了一种简单的低级方法,可以在屏幕上的任意位置获取2D图像.其余的取决于您.
A Sprite
is basically an image with a position, size, and rotation. You draw it using SpriteBatch
, and once you have your your Sprite
s and your SpriteBatch
, you have a simple, low-level way to get 2D images on the screen anywhere you want. The rest is up to you.
Actor
是场景图的一部分.它是更高级别的,并且不仅定位图像,场景图还包含很多其他内容.场景图的根是Stage
,它本身不会显示. Stage
是添加到Actors
的容器,用于组织场景.特别是,输入事件通过Stage
向下传递到适当的Actor
,并且Stage
知道何时告诉Actor
进行绘制.例如,触摸事件仅发送到被触摸的Actor
.
Actor
, on the other hand, is part of a scene graph. It's higher-level, and there's a lot more that goes into a scene graph than just positioning images. The root of the scene graph is the Stage
, which is not itself displayed. The Stage
is a container for the Actors
that you add to it, and is used for organizing the scene. In particular, input events are passed down through the Stage
to the appropriate Actor
, and the Stage
knows when to tell the Actor
to draw itself. A touch event, for example, only gets sent to the Actor
that got touched.
但是请注意,Actor
不像Sprite
那样包含纹理.相反,您可能想使用 Actor
的子类,它可能比普通的Actor
更接近Sprite
. Actor
的其他子类包含文本,依此类推.
But note that Actor
does not contain a texture like Sprite
does. Instead you probably want to use Image
, a subclass of Actor
that's probably closer to Sprite
than just a plain Actor
. Other subclasses of Actor
contain text, and so on.
Actor
的另一个大优点是它们可以具有Action
个.这些是大话题,但实际上,它们允许您为该Actor
计划一系列事件(例如淡入,移动等),一旦设置它们,它们就会自行发生.
Another big advantage of Actor
s is that they can have Action
s. These are a big topic, but they essentially allow you to plan a sequence of events for that Actor
(like fading in, moving, etc) that will then happen on their own once you set them.
因此,基本上Actor
比Sprite
的功能要多得多,因为它是图形框架的一部分.
So basically Actor
does a lot more than Sprite
because it's part of a graphical framework.
这篇关于sprite和actor之间的libgdx区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!