LibGDX Stage vs SpriteBatch to draw a game

I have a big problem with drawing in LibGDX. Firstly, I do not use every physics or other things that complicate my game. I draw only sprites and put the Rectangles in it to detect collisions. I have 3 screens in my game: splash, menu and game. So I use Stage in the splash and menu screen, but I really don't use Stage in the game or draw with SpriteBatch? There really are professionals on the stage with actions, but this complicates the use of the Actors a bit. Are there any other ways to do this? I do not want to use World because it complicates the start of the game. What do I want to use for the game?

+4
source share
2 answers

In fact, you always draw with SpriteBatch, because it Stageuses its own SpriteBatch. If you think you need some benefits Scene2d Stage, such as Actions, Groupor other things, you should use Stage. In my opinion, it is very easy to use. You have your own objects that extend Imageor Actoroverride their methods update(delta), where you check whether it should move Actor(keypress or event for AI). You should also find collisions there and take care of them. Then, if you are expanding Image, you do not need to worry about drawing (but Imageneeds it Drawable, so you will have problems with Animations), if you are expanding Actorredefinedraw(SpriteBatch batch)where you call batch.draw(...). This is it. A big disadvantage Stageis sorting. Actor, which is drawn as the first, is in the background. The latter Actoroverloads everyone else and is in the foreground. You can sort them using z-Index, but this is not entirely accurate. Therefore, you can use your own Stage(this is more or less a list containing all Actors, and when updateor is called draw, it is called for everyone Actorin this list) and add your own sort. It depends on your game design, in your opinion and on your style. Take a look at some tutorials / examples and decide how you want to create your game.

+16
source

, , . SpriteBatch - Stage, . (, Stage SpriteBatch )
, Stage , - (, ..), scene2d.ui ( )

+12

Source: https://habr.com/ru/post/1530850/


All Articles