Back to project page candy-drop.
The source code is released under:
Copyright (c) 2014, Gregory Martin All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...
If you think the Android project candy-drop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.gregfmartin.facetapper.screens; // w w w . j ava 2 s . com import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.gregfmartin.facetapper.GameCore; import com.gregfmartin.facetapper.entities.Screen; import com.gregfmartin.facetapper.entities.SplashImage; import com.gregfmartin.facetapper.utils.Gl20Utils; /** * Exactly as it sounds, this is the Splash Screen that shows the studio logo. * * @author Gregory Martin */ public class SplashScreen extends Screen { // Used for debugging to DDMS static final private String TAG = SplashScreen.class.getSimpleName(); static final private String CTAG = SplashScreen.class.getCanonicalName(); // The company splash image private SplashImage mSplashImage; // Variables for automatic camera translation private int mCamTranslateTicker = 0; private int mCamTranslateTickLimit = 1; private float mCamTranslateInc = 4.0F; private boolean mIsCamDirty = false; // Store the default location of the camera private float cx, cy, cz = 0.0F; // The current state of the animation private SplashScreenAnimationState mAnimState = SplashScreenAnimationState.TRANSLATE; public SplashScreen(GameCore coreRef) { super(coreRef); } @Override public void castingCall() { super.castingCall(); // Get the default location of the camera cx = mStage.getCamera().position.x; cy = mStage.getCamera().position.y; cz = mStage.getCamera().position.z; mSplashImage = new SplashImage(); } @Override public void rehearsal() { super.rehearsal(); mStage.addActor(mSplashImage); mSplashImage.setPosition(0.0F, 0.0F); } @Override public void logic(float delta) { super.logic(delta); /* UPDATE Conditionally queue the translation to the camera if the width of the viewport doesn't exceed that of the splash image. The calculated comparator would be that of the camera's current position plus the width of the viewport (since the dimensions of the viewport wouldn't change). UPDATE The calculation that was being used was modified slightly. It would appear that the Stage uses an Orthogonal Camera whose origin is fixed in the center. Dividing the Viewport width in half for this calculation moves the width boundary to the center of the camera relative to its origin. */ float calculatedCamArea = (mStage.getCamera().position.x + (mStage.getCamera().viewportWidth / 2)); /* Used to help determine the calculated metrics of the camera during the iteration Log.d("SplashScreen mStage Camera Position", String.format("X: %s, Y: %s, Z: %s", curCamPos.x, curCamPos.y, curCamPos.z)); Log.d("SplashScreen mStage Camera Viewport Width", String.valueOf(curCamViewportWidth)); Log.i("SplashScreen", String.format("Camera Position X: %s", String.valueOf(mStage.getCamera().position.x))); Log.i("SplashScreen", String.format("Calculcated Camera Boundary: %s", String.valueOf(calculatedCamArea))); Log.i("SplashScreen", String.format("Splash Image Width (getImageWidth): %s", String.valueOf(mSplashImage.getImageWidth()))); */ if(mAnimState == SplashScreenAnimationState.TRANSLATE) { if(calculatedCamArea < (mSplashImage.getWidth())) { // Increment the ticker until it reaches the tick limit if(++mCamTranslateTicker >= mCamTranslateTickLimit) { // Reset the ticker mCamTranslateTicker = 0; // Queue the translation to the camera mStage.getCamera().translate(mCamTranslateInc, 0.0F, 0.0F); // Mark camera viewport as dirty mIsCamDirty = true; } } else { /* * I was going to put a delay governer here but after see it in action, I feel like I like it going * directly to the next phase of the animation. */ mAnimState = SplashScreenAnimationState.FADE_TO_WHITE; } } else if(mAnimState == SplashScreenAnimationState.FADE_TO_WHITE) { if(mStage.getRoot().getActions().size == 0) { // mStage.addAction(Actions.fadeOut(0.75F, Interpolation.sineOut)); mStage.addAction(Actions.sequence(Actions.fadeOut(0.75F, Interpolation.sineOut), Actions.run(new Runnable() { @Override public void run() { mAnimState = SplashScreenAnimationState.ZOOM_TO_FIT; mStage.getRoot().clearActions(); } }))); } } else if(mAnimState == SplashScreenAnimationState.ZOOM_TO_FIT) { /* * The position of the camera is going to need reset here. The image will also need rescaled so that it * fits entirely in the Viewport with no clipping. We also need to fade in. * * The first part of this test will simply fade in. */ if(mStage.getRoot().getActions().size == 0) { // Reposition the camera back to it's original position mStage.getCamera().position.set(cx, cy, cz); // Rescale the image so that it fits in teh viewport mSplashImage.setWidth(mStage.getCamera().viewportWidth); mSplashImage.setHeight(mStage.getCamera().viewportHeight); mStage.addAction(Actions.sequence(Actions.fadeIn(0.75F, Interpolation.sineIn), Actions.delay(1.75F), Actions.run(new Runnable() { @Override public void run() { mAnimState = SplashScreenAnimationState.FADE_TO_BLACK; mStage.getRoot().clearActions(); } }))); } } else if(mAnimState == SplashScreenAnimationState.FADE_TO_BLACK) { if(mStage.getRoot().getActions().size == 0) { mStage.addAction(Actions.sequence(Actions.fadeOut(0.75F, Interpolation.sineOut), Actions.delay(1.0F), Actions.run(new Runnable() { @Override public void run() { // Transition to the next screen mGameCoreRef.setScreen(new AssociationScreen(mGameCoreRef)); } }))); } } // Apply all changes to the camera if(mIsCamDirty) { mIsCamDirty = false; mStage.getCamera().update(); } } @Override public void draw(float delta) { if(mAnimState == SplashScreenAnimationState.FADE_TO_BLACK) { Gl20Utils.glClearColour(Color.BLACK); } else { Gl20Utils.glClearColour(Color.WHITE); } mStage.draw(); } @Override public void dispose() { super.dispose(); mSplashImage = null; } private enum SplashScreenAnimationState { TRANSLATE, FADE_TO_WHITE, ZOOM_TO_FIT, FADE_TO_BLACK, END } }