org.andengine.engine.handler.timer.ITimerCallback Java Examples

The following examples show how to use org.andengine.engine.handler.timer.ITimerCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LevelChoiceScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
@Override
public void disposeScene() {

    camera.setChaseEntity(null);
    camera.setCenter(camera.getWidth() / 2, camera.getHeight() / 2);
    rightArrow.setVisible(false);
    leftArrow.setVisible(false);
    camera.setHUD(null);

    final LevelChoiceScene levelChoiceScene = this;
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    arrowHud.detachChildren();
                    levelChoiceScene.detachChildren();
                }
            }));
}
 
Example #2
Source File: JustPlayScoreScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
private void addAnimation(final int[] currentScore) {

        float stepRange = 0.5f / (justPlayResult.getScore() - justPlayResult.getLastScore());
        engine.registerUpdateHandler(new TimerHandler(stepRange, true, new ITimerCallback() {

                    @Override
                    public void onTimePassed(TimerHandler pTimerHandler) {

                        if (!leaveScene) {
                            if (currentScore[0] >= justPlayResult.getScore()) {
                                score.setText(String.valueOf(justPlayResult.getScore()));
                                engine.unregisterUpdateHandler(pTimerHandler);
                            } else {
                                currentScore[0]++;
                                score.setText(String.valueOf(currentScore[0]));
                            }
                        } else {
                            engine.unregisterUpdateHandler(pTimerHandler);
                        }
                    }
                }));
        registerEntityModifier(new MoveYModifier(0.15f, -camera.getHeight(), 0, EaseQuadInOut.getInstance()));
    }
 
Example #3
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 6 votes vote down vote up
@Override
public void loadGameSceneFromLevelChoiceScene(final Level level) {

    choiceScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    gameScene = new LevelModeGameScene(level);
                    setScene(gameScene);
                    choiceScene = null;
                }
            }));
}
 
Example #4
Source File: GameScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
@Override
public void updateGameScene() {

    if (gameService.solvedPuzzle()) {
        setOnSceneTouchListener(null);
        gameService.detatch(this);
        baseScene.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                    @Override
                    public void onTimePassed(final TimerHandler pTimerHandler) {

                        baseScene.unregisterUpdateHandler(pTimerHandler);
                        onSolvedGame();
                    }
                }));
    }

    scoreText.setText(String.valueOf(gameService.getLevel().getMovesCount()));

    updateTiles(gameService.solvedPuzzle());
}
 
Example #5
Source File: JustPlayLostScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
private void addAnimation(final int[] currentScore) {

        engine.registerUpdateHandler(new TimerHandler(0.01f, true, new ITimerCallback() {

                    @Override
                    public void onTimePassed(TimerHandler pTimerHandler) {

                        if (!leaveScene) {
                            if (currentScore[0] >= justPlayResult.getScore()) {
                                score.setText(String.valueOf(justPlayResult.getScore()));
                                engine.unregisterUpdateHandler(pTimerHandler);
                            } else {
                                currentScore[0]++;
                                score.setText(String.valueOf(currentScore[0]));
                            }
                        } else {
                            engine.unregisterUpdateHandler(pTimerHandler);
                        }
                    }
                }));
        registerEntityModifier(new MoveYModifier(0.15f, -camera.getHeight(), 0, EaseQuadInOut.getInstance()));
    }
 
Example #6
Source File: JustPlayGameScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
@Override
public void updateJustPlayScene() {

    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(TimerHandler pTimerHandler) {

                    leftTime.setText(String.valueOf(timeBasedGameService.getRemainingTime()));

                    if (timeBasedGameService.getRemainingTime() <= 5) {
                        backgroundFlash();
                    }
                }
            }));

    if (timeBasedGameService.getRemainingTime() == 0 && !gameService.solvedPuzzle()) {
        onLostGame();
    }
}
 
Example #7
Source File: LevelModeGameScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
@Override
public void onSolvedGame() {

    restartButton.setVisible(false);

    Level level = gameService.getLevel();
    final LevelResult levelResult = levelService.calculateLevelResult(level);
    levelService.persistLevelResult(levelResult);

    int nextLevelId = level.getId() + 1;
    levelService.unlockLevel(nextLevelId);
    this.leaveScene = true;
    engine.registerUpdateHandler(new TimerHandler(1.5f, new ITimerCallback() {

                @Override
                public void onTimePassed(TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    storyService.loadScoreScreen(levelResult);
                }
            }));
}
 
Example #8
Source File: JustPlayGameScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
@Override
public void onSolvedGame() {

    timeBasedGameService.stop();
    restartButton.setVisible(false);

    if (!leaveScene) {
        restartButton.setEnabled(false);
        leaveScene = true;
        engine.registerUpdateHandler(new TimerHandler(1f, new ITimerCallback() {

                    @Override
                    public void onTimePassed(TimerHandler pTimerHandler) {

                        engine.unregisterUpdateHandler(pTimerHandler);
                        storyService.loadJustPlayScoreSceneFromJustPlayScene(
                            new JustPlayLevelResult(timeBasedGameService.getRemainingTime(),
                                gameService.getLevel().getMovesCount(),
                                gameService.getLevel().getMinimumMovesToSolve()));
                    }
                }));
    }
}
 
Example #9
Source File: JustPlayGameScene.java    From sopa with Apache License 2.0 6 votes vote down vote up
@Override
public void onBackKeyPressed() {

    if (!leaveScene) {
        leaveScene = true;
        engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                    @Override
                    public void onTimePassed(TimerHandler pTimerHandler) {

                        engine.unregisterUpdateHandler(pTimerHandler);
                        storyService.loadMenuSceneFromJustPlayGameScene();
                    }
                }));
    }
}
 
Example #10
Source File: JustPlaySceneServiceImpl.java    From sopa with Apache License 2.0 6 votes vote down vote up
@Override
public void loadJustPlaySceneFromJustPlayScene(final TimeBasedGameService timeBasedGameService,
    final JustPlayLevel justPlayLevel) {

    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    justPlayGameScene.disposeScene();
                    justPlayGameScene = new JustPlayGameScene(timeBasedGameService, justPlayLevel);
                    setScene(justPlayGameScene);
                }
            }));
}
 
Example #11
Source File: JustPlaySceneServiceImpl.java    From sopa with Apache License 2.0 6 votes vote down vote up
@Override
public void start() {

    this.justPlayService = new JustPlayServiceImpl();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    ResourcesManager.getInstance().loadGameSceneResources();
                    ResourcesManager.getInstance().loadJustPlayScoreResources();
                    justPlayGameScene = new JustPlayGameScene(justPlayService.getNextLevel());
                    setScene(justPlayGameScene);
                }
            }));
}
 
Example #12
Source File: TutorialScene.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {

    if (pSceneTouchEvent.isActionDown()) {
        if (alreadySwitched == 0) {
            firstScreenA.setVisible(false);
            firstScreenB.setVisible(false);
            secondScreenA.setVisible(true);
            secondScreenB.setVisible(true);
        } else if (alreadySwitched == 1) {
            secondScreenA.setVisible(false);
            secondScreenB.setVisible(false);
            letsGo.setVisible(true);
            engine.registerUpdateHandler(new TimerHandler(1.5f, new ITimerCallback() {

                        @Override
                        public void onTimePassed(TimerHandler pTimerHandler) {

                            engine.unregisterUpdateHandler(pTimerHandler);

                            if (!leaveScene) {
                                storyService.loadFirstLevelFromTutorial();
                            }
                        }
                    }));
        }

        alreadySwitched++;
    }

    return false;
}
 
Example #13
Source File: GameActivity.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {

    mEngine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    mEngine.unregisterUpdateHandler(pTimerHandler);
                    ResourcesManager.getInstance().storyService.createMenuScene();
                }
            }));
    pOnPopulateSceneCallback.onPopulateSceneFinished();
}
 
Example #14
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadScoreScreen(final LevelResult level) {

    gameScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    scoreScene = new ScoreScreen(level);
                    setScene(scoreScene);
                }
            }));
}
 
Example #15
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadLevelModeCompleteSceneFromScoreScene() {

    scoreScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    levelCompleteScene = new LevelModeCompleteScene();
                    setScene(levelCompleteScene);
                }
            }));
}
 
Example #16
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadLevelChoiceFromLevelModeCompleteScene() {

    levelCompleteScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    choiceScene = new LevelChoiceScene();
                    setScene(choiceScene);
                }
            }));
}
 
Example #17
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadLevelChoiceSceneFromScoreScene() {

    scoreScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    choiceScene = new LevelChoiceScene();
                    setScene(choiceScene);
                }
            }));
}
 
Example #18
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadGameSceneFromScoreScene(final Level level) {

    scoreScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    gameScene = new LevelModeGameScene(level);
                    setScene(gameScene);
                }
            }));
}
 
Example #19
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadGameSceneFromGameScene(final Level level) {

    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    gameScene = new LevelModeGameScene(level);
                    setScene(gameScene);
                }
            }));
}
 
Example #20
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadTutorialSceneFromLevelChoiceScene() {

    choiceScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    tutorialScene = new TutorialScene();
                    setScene(tutorialScene);
                }
            }));
}
 
Example #21
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadFirstLevelFromTutorial() {

    tutorialScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    gameScene = new LevelModeGameScene(ResourcesManager.getInstance().levelService.getLevelById(1));
                    setScene(gameScene);
                }
            }));
}
 
Example #22
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadLevelChoiceFromTutorial() {

    tutorialScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    choiceScene = new LevelChoiceScene();
                    setScene(choiceScene);
                }
            }));
}
 
Example #23
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void loadLevelChoiceSceneFromGameScene() {

    gameScene.disposeScene();
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    choiceScene = new LevelChoiceScene();
                    setScene(choiceScene);
                }
            }));
}
 
Example #24
Source File: LevelModeSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {

    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    loadResources(pTimerHandler);
                }
            }));
}
 
Example #25
Source File: MenuSceneServiceImpl.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {

    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    ResourcesManager.getInstance().loadMenuSceneResources();
                    menuScene = new MainMenuScene();
                    setScene(menuScene);
                }
            }));
}
 
Example #26
Source File: MainMenuScene.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void disposeScene() {

    final MainMenuScene mainMenuScene = this;

    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    mainMenuScene.detachChildren();
                }
            }));
}
 
Example #27
Source File: BaseOnScreenControl.java    From tilt-game-android with MIT License 5 votes vote down vote up
public BaseOnScreenControl(final float pX, final float pY, final Camera pCamera, final ITextureRegion pControlBaseTextureRegion, final ITextureRegion pControlKnobTextureRegion, final float pTimeBetweenUpdates, final VertexBufferObjectManager pVertexBufferObjectManager, final IOnScreenControlListener pOnScreenControlListener) {
	this.setCamera(pCamera);

	this.mOnScreenControlListener = pOnScreenControlListener;
	/* Create the control base. */
	this.mControlBase = new Sprite(pX, pY, pControlBaseTextureRegion, pVertexBufferObjectManager) {
		@Override
		public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
			return BaseOnScreenControl.this.onHandleControlBaseTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
		}
	};

	/* Create the control knob. */
	this.mControlKnob = new Sprite(0, 0, pControlKnobTextureRegion, pVertexBufferObjectManager);
	this.onHandleControlKnobReleased();

	/* Register listeners and add objects to this HUD. */
	this.setOnSceneTouchListener(this);
	this.registerTouchArea(this.mControlBase);
	this.registerUpdateHandler(new TimerHandler(pTimeBetweenUpdates, true, new ITimerCallback() {
		@Override
		public void onTimePassed(final TimerHandler pTimerHandler) {
			BaseOnScreenControl.this.mOnScreenControlListener.onControlChange(BaseOnScreenControl.this, BaseOnScreenControl.this.mControlValueX, BaseOnScreenControl.this.mControlValueY);
		}
	}));

	this.attachChild(this.mControlBase);
	this.mControlBase.attachChild(this.mControlKnob);

	this.setTouchAreaBindingOnActionDownEnabled(true);
}
 
Example #28
Source File: SettingsScene.java    From sopa with Apache License 2.0 5 votes vote down vote up
@Override
public void disposeScene() {

    final SettingsScene settingsScene = this;
    engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() {

                @Override
                public void onTimePassed(final TimerHandler pTimerHandler) {

                    engine.unregisterUpdateHandler(pTimerHandler);
                    settingsScene.detachChildren();
                }
            }));
}
 
Example #29
Source File: ContinuousHoldDetector.java    From tilt-game-android with MIT License 5 votes vote down vote up
public ContinuousHoldDetector(final long pTriggerHoldMinimumMilliseconds, final float pTriggerHoldMaximumDistance, final float pTimeBetweenUpdates, final IHoldDetectorListener pHoldDetectorListener) {
	super(pTriggerHoldMinimumMilliseconds, pTriggerHoldMaximumDistance, pHoldDetectorListener);

	this.mTimerHandler = new TimerHandler(pTimeBetweenUpdates, true, new ITimerCallback() {
		@Override
		public void onTimePassed(final TimerHandler pTimerHandler) {
			ContinuousHoldDetector.this.fireListener();
		}
	});
}
 
Example #30
Source File: BaseOnScreenControl.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public BaseOnScreenControl(final float pX, final float pY, final Camera pCamera, final ITextureRegion pControlBaseTextureRegion, final ITextureRegion pControlKnobTextureRegion, final float pTimeBetweenUpdates, final VertexBufferObjectManager pVertexBufferObjectManager, final IOnScreenControlListener pOnScreenControlListener) {
	this.setCamera(pCamera);

	this.mOnScreenControlListener = pOnScreenControlListener;
	/* Create the control base. */
	this.mControlBase = new Sprite(pX, pY, pControlBaseTextureRegion, pVertexBufferObjectManager) {
		@Override
		public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
			return BaseOnScreenControl.this.onHandleControlBaseTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY);
		}
	};

	/* Create the control knob. */
	this.mControlKnob = new Sprite(0, 0, pControlKnobTextureRegion, pVertexBufferObjectManager);
	this.onHandleControlKnobReleased();

	/* Register listeners and add objects to this HUD. */
	this.setOnSceneTouchListener(this);
	this.registerTouchArea(this.mControlBase);
	this.registerUpdateHandler(new TimerHandler(pTimeBetweenUpdates, true, new ITimerCallback() {
		@Override
		public void onTimePassed(final TimerHandler pTimerHandler) {
			BaseOnScreenControl.this.mOnScreenControlListener.onControlChange(BaseOnScreenControl.this, BaseOnScreenControl.this.mControlValueX, BaseOnScreenControl.this.mControlValueY);
		}
	}));

	this.attachChild(this.mControlBase);
	this.attachChild(this.mControlKnob);

	this.setTouchAreaBindingOnActionDownEnabled(true);
}