Friday 8 February 2013

#5.2 Tutorial (LibGDX & MTX) World Scene2D


As you know, the GameManager has already created the main world and the world layers, but what are these exactly, how can we use these for games and live wallpapers.



















WORLD

Here is my main world that extends "AbstractWorldScene2D" of Mtx (AbstractWorldScene2D also extends LibGDX Scene2D Group). Basicly this is the main Scene2D Group that will hold all other world groups and actors. (Do not worry about GameState, I will talk about on next tutorial). I give reference to gameManager in each my world to provide connection among the world layers whenever is needed.





















WORLD LAYERS

World layers basicly same thing with main wolrd (Also extends AbstractWorldScene2D). Here is the example of "WorldLayer1"
  1. I set the bluish background
  2. I set bottom soils/grass
  3. I set the the clouds
Order is important, because its being added to this WorldLayer1 (Scene2D Group)










































OTHER WORLD LAYERS

WorldLayer order is also important, it defines what comes top/bottom.

WorldLayer2
  • I only set flying enemy objects
WorldLayer3
  • I only set snow effect




WHY MANY LAYERS

Of course, I could have done everything in a single layer, but I like cohesion/coupling, it gives me flexibility. I give a responsibility to each layer (Background layer, environment layer, enemy layer, player layer, shooting layer, menu layer, etc..). Then everything is easy to improve and maintain. It is best to avoid confusion and do a fast implementation.




SNOW EFFECT ON WORLDLAYER3

Again, I want to talk about my SmartModel for you envrionments. I believe you noticed that nice snowing effect which is natural and no-strecthing in any device.





































It took only a minute to set up this snow effect. I wanted my snow to with an angle, so I gave different direction to first half and second half of my snow flakes.

Direction is like;


























1 comment:

  1. hi can you help me plz with how to detect collision of two actors in different layer

    ReplyDelete