9 Mayıs 2015 Cumartesi

android apk Tutorial (LibGDX & MTX) Test1_AbstractScreen

android apk Tutorial (LibGDX & MTX) Test1_AbstractScreen android game , android apk Tutorial (LibGDX & MTX) Test1_AbstractScreen android free download , android apk Tutorial (LibGDX & MTX) Test1_AbstractScreen mobile game android apk Tutorial (LibGDX & MTX) Test1_AbstractScreen android free download
Hello there!

I assume you downloaded the project files (MtxFramework2, MtxFramework2-android, MtxFramework2-desktop) and imported to eclipse.

We create our screen and extend to MTX framework's "AbstractScreen". It will handle the rest.
All mtx framework codes are documented, so you can read for more features



  • It creates stage for you - getStage()
  • You should set SCREEN_W & SCREEN_H for screen resolution in "AbstractScreen" class, once set and use it everywhere
  • It has state time for animations - getStateTime()
  • It sets input processor for you - Gdx.input.setInputProcessor(stage);
  • You can get seconds counting since its creation - getSecondsTime()
  • You can get formatted time since its creation - getScreenTime()
  • You can set back button active, and override the keyBackPressed() for back button


So less code, so much done:

  • Created the scene
  • Added background texture
  • Added Screen timer and Fps
  • Set the back key and override it

package com.mtx.tests;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.moribitotech.mtx.AbstractScreen;
import com.mtx.testassets.Assets;

public class Test1_AbstractScreen extends AbstractScreen {
private Label lblFps;
private Label lblScreenTime;

public Test1_AbstractScreen(Game game, String screenName) {
super(game, screenName);
}

@Override
public void setUpScreenElements() {
super.setUpScreenElements();

// #1.1 TEST
// Set background texture
// #########################################################
setBackgroundTexture(Assets.imgMtxBg);

// #1.2 TEST
// Set back button
// (Override keyBackPressed to do some action see very below)
// #########################################################
setBackButtonActive(true);

// #1.3 TEST
// Screen time / Fps
// Update by overriding render
// #########################################################
lblScreenTime = new Label("", Assets.getSkin());
lblFps = new Label("", Assets.getSkin());
lblScreenTime.setPosition(getStage().getWidth() - 80, getStage().getHeight() - 40);
lblFps.setPosition(getStage().getWidth() - 80, getStage().getHeight() - 60);
getStage().addActor(lblScreenTime);
getStage().addActor(lblFps);
}

@Override
public void keyBackPressed() {
super.keyBackPressed();
getGame().setScreen(new Test0_AllTestsScreen(getGame(), ""));
}

@Override
public void render(float delta) {
super.render(delta);
lblScreenTime.setText(getScreenTime());
lblFps.setText("Fps: " + Gdx.graphics.getFramesPerSecond());
}
}


0 yorum:

Yorum Gönder