本文介绍了精灵和演员之间的libgdx区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是浏览了有关 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/actors作为主要游戏项目(即玩家等),而其他人只使用精灵.

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(即场景 2D)之间究竟有什么区别?什么时候应该选择?

What exactly is the difference between using Sprite and Actor (i.e. scene2D) in a game and when should you choose?

谢谢.

推荐答案

Sprite 基本上是一个具有位置、大小和旋转的图像.您使用 SpriteBatch,一旦你有了你的 Sprites 和你的 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 Sprites 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 那样包含纹理.相反,您可能想使用 ImageActor 的子类,它可能更接近于Sprite,而不仅仅是一个普通的Actor.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 Actors is that they can have Actions. 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.

所以基本上 ActorSprite 做的更多,因为它是图形框架的一部分.

So basically Actor does a lot more than Sprite because it's part of a graphical framework.

这篇关于精灵和演员之间的libgdx区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-18 16:38