I have a big problem with the drawing in LibGDX. First I don´t use every physics or other complicate things in my game. I only draw sprites and put Rectangles at this for Collision Detection. I have 3 Screens in my game: splash, menu and game. So I use a Stage in the splash and menu screen but I don´t really if I use Stage in the game too or I draw with SpriteBatch? The Stage have really pros with Actions but it a little bit more complicate to use Actors. Are there other ways to do this? I don´t want to use World, because its to complicate for the beginning of game developing. What I want to use for the game?
Actually you always draw with SpriteBatch
, as Stage
uses its own SpriteBatch
. If you think you could need some of the advantages of Scene2d
s Stage
, like Action
s, Group
s or other things, you should use Stage
. In my opinion it is really easy to use. You have your own objects, which extend Image
or Actor
, override their update(delta)
methods, where you check if the Actor
should move (Keypressed or an event for the AI). Also you should detect collisions there and take care about them. Then, if you are extending Image
you don't need to care about drawing (but Image
needs Drawable
s so you will have some problems with Animation
s), if you are extending Actor
override the draw(SpriteBatch batch)
, where you call batch.draw(...)
.
Thats it.
A big disadvantage of Stage
is the sorting. The Actor
, which is drawn as first is in the background. The last Actor
overdraws all others and is in foreground. You can sort them by using the z-Index, but it is not really sure.
So you may decide to use your own kind of Stage
(it is more or less a list, containing all Actor
s, and when update
or draw
is called, it is called for every Actor
in this list), and add your own sorting there.
It depends on your game design, on your opinion and on your style. Look at some tutorials/examples and decide how you want to create your game.
You can use either, it depends on what kind of game are you creating. But anyway, don't create multiple instances of SpriteBatch
— instead create only one and pass it to Stage
constructor, because it's heavy object. (Yes, Stage
uses a SpriteBatch
under the hood)
Also, Stage
may be extremely useful if you need any on-screen controls (buttons, joystick, etc), because you can use classes from scene2d.ui
and don't reinvent the wheel (some wheels are not very easy to reinvent properly)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With