コード例 #1
0
  @Override
  public Scene onLoadScene() {
    EventBus.clear();
    EventBus.register(this);

    CollisionHandler.instance().clear();
    this.getEngine().registerUpdateHandler(CollisionHandler.instance());

    ObjectHandler.clear();

    setupNetwork();

    final FPSLogger fpsLogger = new FPSLogger();
    this.mEngine.registerUpdateHandler(fpsLogger);

    GameScene scene = new GameScene(this.camera);

    final ChangeableText fpsText =
        new ChangeableText(5, 5, Fonts.gameFont16p, "FPS:", "FPS: XXXXX".length());
    this.camera.getHUD().getTopLayer().addEntity(fpsText);
    scene.registerUpdateHandler(
        new TimerHandler(
            1 / 20.0f,
            true,
            new ITimerCallback() {
              @Override
              public void onTimePassed(final TimerHandler pTimerHandler) {
                fpsText.setText("FPS: " + fpsLogger.getFPS());
              }
            }));

    return scene;
  }
コード例 #2
0
  @Override
  protected void onPositionChanged() {
    super.onPositionChanged();

    final float x = this.getX();
    final float y = this.getY();
    if (x < 0 || x > GameActivity.WORLD_WIDTH || y < 0 || y > GameActivity.WORLD_HEIGHT) {
      explosionSoundEvent.set(Sounds.explosion1, x, y);
      EventBus.dispatch(explosionSoundEvent);
      explosionEvent.set(x, y);
      EventBus.dispatch(explosionEvent);

      ObjectHandler.recycleItem(this);
    }
  }