libgdx difference between sprite and actor

前端 未结 2 1236
夕颜
夕颜 2021-01-31 15:58

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

相关标签:
2条回答
  • 2021-01-31 16:45

    It is more or less matter of taste. If you want to use actions and stage, use actors. Actors cannot be drawn directly, you need to override draw method. Inside draw you can use sprites.

    0 讨论(0)
  • 2021-01-31 17:00

    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, 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.

    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.

    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.

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

    0 讨论(0)
提交回复
热议问题