Skip to content
This repository has been archived by the owner on Dec 26, 2018. It is now read-only.

[3.0] 5: Custom scene

Yuya Matsuo edited this page Sep 27, 2016 · 1 revision

It is recommended to encapsulate scene specific logic into subclass of Scene.

Scene is corresponding to Activity in typical Android application. Multiple scene represents different state in app.

You would create some Scenes. For example:

  • Title scene
  • Menu scene
  • Content playing scene
  • Ending scene
import org.meganekkovr.FrameInput;
import org.meganekkovr.Scene;

public class MyScene extends Scene {

    private Entity background;
    private Entity cursor;

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

        // init() will be called at first time before rendering. (From first onStartRendering() call)
        // Typically get Entities with findById() here for later use.
        background = findById(R.id.background);
        cursor = findById(R.id.cursor);
    }

    @Override
    public void onStartRendering() {
        super.onStartRendering(); // Don't forget this
        // onStartRendering() will be called when scene is set by MeganekkoApp.setScene()
    }

    @Override
    public void onStopRendering() {
        super.onStopRendering(); // Don't forget this
        // onStartRendering() will be called when other scene is set by MeganekkoApp.setScene()
    }

    @Override
    public void update(FrameInput frame) {

        // update() will be called at every frame update. (About 60 times per second)

        // Respond to touch event
        if(JoyButton.contains(frame.getButtonReleased(), JoyButton.BUTTON_TOUCH_SINGLE)){
            // Do something
        }

        // Don't forget to call super.update()
        super.update(frame);
    }
}
Clone this wiki locally