简体   繁体   中英

(libgdx/scene2d) Creating different stages with actors etc

I'm fairly new to game programming and just started looking into building my first 2d game with libgdx. I've already build a stage with actors that are drawn to the screen with movement, pathfinding and so on. But I'm a bit confused when it comes to the usage of the class "Stage", when creating several stages. Is the best solution just to create classes for every level that all extend Stage or is there no need for that, and the best solution is to have classes for each level and have a Stage-object in there? Hope this question isn't too confusing and thanks in advance!

I don't think it is necessary to extend Stage , holding one Stage as a reference and adding all Actor s to it should be enough.
Also you should not have 1 class for each level, you should have one class Level .
Then every level is an instance of the class Level , or even better, just have 1 instance of Level at a time, as you cannot play more then 1 Level at the same time.

So basicly you have a class Level , which is able to store all necessary informations, like all living Mob s, which could be subclasses of Actor , all Block s or Wall s (again subclasses of Actor ) and so on.
Then the difference between level1 and level2 could be, that level1 contains 1 Mob only, while in level2 you have to fight 5 Mob s.
Also the Level could hold an instance of Stage , to which you add all the Actor s ( Mob s, Block s, Player ...).

You should also read the tutorials from the libgdx wiki, they can help a lot!

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM