Monday 28 January 2013

#3.4 Tutorial (LibGDX & MTX) Test_03_AbstractActors


AbstractActors are %100 same with Mtx v1.0 with additional features;

- New constructor with DIPActive (we talked about this previously...)
- Particle Ready




















POSITIONING AGAIN

Before moving on, I want to talk about positioning one more time to get things more clear

























In top picture, you see heart, fire and particle effects, it is all same actor (testActor).

As you know my target world dimensions in app settings is 960x540, for this world I wanted to set testActor to position 600x250.  But I want my actor to be same/similar position in every device on this planet. So, I multipled my position with;

600 * AppSettings.getWorldPositionXRatio()
250 * AppSettings.getWorldPositionYRatio()

So if my device resolution is 960x540 the position will be 600x250, if my device resolutuion is 800x480, actos position will be 600 * (800 / 960) for X-axis, and 250 * (480 / 540) for Y-axis. These will get me estimated positions for each device (But not perfect position because of many ratio differences in devices)

DIPActive constructor

Here example of extra new constructor for DIPActive calculations to auto-resize. There is no auto-positioning, it should be done manually like above example, if you need it.

testActor = new EmptyAbstractActor(150, 150, true);





ABSTRACTACTOR

As I said earlier it is same with Mtx v1.0. You can set everything for actors now

- Texture
- Animation
- Animation Momentary
- Particles

Here example of adding particle:






















Particles created by particle editor, You can export the particle data (example: particle.p), and add them to
Android projects Assets/Data folder (If you use image in your particle add image as well)

Particle Editor: http://code.google.com/p/libgdx/wiki/ParticleEditor
























5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hey moribito,
    I used your mtx framework v 2.0 and in the very first step i just want to set an image as background, but the game shows me only red color. I tried everything and still no success with the background image, can u plz help me why this basic step is not working. Here is the code
    public class MenuScreen extends AbstractScreen implements IScreen {

    public MenuScreen(Game game, String screenName) {
    super(game, screenName);
    setUpScreenElements();
    }
    @Override
    public void setUpScreenElements() {
    TextureAtlas atlas = new TextureAtlas("img.pack");
    TextureRegion region = atlas.findRegion("r");
    setBackgroundTexture(region);
    setBackButtonActive(false);
    }

    ReplyDelete
    Replies
    1. Red means, everything is working. Beacuse in "AbstractScreen", I render background red with opengl.

      if a textureregion is null for background, you will see red background. It means the problem is about your textureregion or textureatlas. Atlas path may be wrong, texture name could be wrong.

      Delete
    2. but when i use the same code with spritebatch and draw,,it works,,it also works with my private stage

      Delete
    3. Hmm, its weird. So you are %100 sure there is no Null condition here! Propably you changed something in mtx code, or you do not loading right asset file, or you did not chose the right asset file. There could me many things.

      To understand the problem, you should have log every step and find the error.

      Delete