Android Open Source - candy-drop Association Screen






From Project

Back to project page candy-drop.

License

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.

Java Source Code

package com.gregfmartin.facetapper.screens;
//ww  w.j  a  v  a  2 s. c om
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.gregfmartin.facetapper.GameCore;
import com.gregfmartin.facetapper.entities.Screen;
import com.gregfmartin.facetapper.utils.Gl20Utils;

/**
 * A filler screen that serves absolutely no purpose whatsoever. It's here just to waste space. :)
 *
 * @author Gregory Martin
 */
public class AssociationScreen extends Screen {
    static final private String TAG = AssociationScreen.class.getSimpleName();
    static final private String CTAG = AssociationScreen.class.getCanonicalName();

    // Elements for the layout of the screen
    private Table mRootTable; // Root node for all Scene2D UI components
    private Label mAssociationTitleLabel; // Contains "In Association With"
    private Label mAssociationNameLabel; // "Oily Cow"
    private Label.LabelStyle mLabelStyle; // The style used for all of the Label components on this screen
    private Image mOilyCow; // The image of the Oily Cow
    private Sound mCowMoo; // A nice moo that will play when the image is shown
    private FreeTypeFontGenerator mFreeTypeFontGenerator; // Used to generate BitmapFonts

    // The current state of the animation
    AssociationScreenAnimationState mAnimState;

    public AssociationScreen(GameCore gameCore) {
        super(gameCore);
    }

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

        mAnimState = AssociationScreenAnimationState.FADE_IN_FROM_BLACK;
        mFreeTypeFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/sawasdee/sawasdee.ttf"));
        mLabelStyle = new Label.LabelStyle(mFreeTypeFontGenerator.generateFont(32), Color.WHITE);
        mCowMoo = Gdx.audio.newSound(Gdx.files.internal("se/cow-whine2.ogg"));
        mRootTable = new Table();
        mAssociationTitleLabel = new Label("In Association With", mLabelStyle);
        mAssociationNameLabel = new Label("Oily Cow", mLabelStyle);
        mOilyCow = new Image(new Texture(Gdx.files.internal("images/ui/splash/oilycow.png")));
    }

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

        // Pack the components into the UI table
        mRootTable.setFillParent(true); // Make the UI table consume the entire span of the parent
        // mRootTable.debug(); // Enable the drawing of all of table and cell lines

        mRootTable.add(mAssociationTitleLabel).padBottom(10.0F);
        mRootTable.row();
        mRootTable.add(mOilyCow);
        mRootTable.row();
        mRootTable.add(mAssociationNameLabel).padTop(10.0F);

        mStage.addActor(mRootTable);
        mStage.addAction(Actions.fadeOut(0.1F));
    }

    @Override public void logic(float delta) {
        super.logic(delta);

        // Check the current state of the animation
        if (mAnimState == AssociationScreenAnimationState.FADE_IN_FROM_BLACK) {
            // Prep the action
            if (mStage.getRoot().getActions().size == 0) {
                mStage.addAction(Actions.sequence(Actions.fadeIn(0.75F, Interpolation.sineIn), Actions.run(new Runnable() {
                    @Override public void run() {
                        // Clear the actions from the stage
                        mStage.getRoot().clearActions();

                        // Move to the next stage in the animation
                        mAnimState = AssociationScreenAnimationState.DELAY;
                    }
                })));
            }
        } else if (mAnimState == AssociationScreenAnimationState.DELAY) {
            // Prep the action
            if (mStage.getRoot().getActions().size == 0) {
                mStage.addAction(Actions.sequence(Actions.delay(0.5F), Actions.run(new Runnable() {
                    @Override public void run() {
                        mCowMoo.play();
                        mStage.getRoot().clearActions();
                        mAnimState = AssociationScreenAnimationState.FADE_OUT_TO_BLACK;
                    }
                })));
            }
        } else if (mAnimState == AssociationScreenAnimationState.FADE_OUT_TO_BLACK) {
            if (mStage.getRoot().getActions().size == 0) {
                mStage.addAction(Actions.sequence(Actions.delay(1.75F), Actions.fadeOut(0.75F, Interpolation.sineOut), Actions.run(new Runnable() {
                    @Override public void run() {
                        mGameCoreRef.setScreen(new TitleScreen(mGameCoreRef));
                    }
                })));
            }
        }
    }

    @Override public void draw(float delta) {
        Gl20Utils.glClearColour(Color.BLACK);
        // Table.drawDebug(mStage); // Make the table draw to the screen
        mStage.draw();
    }

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

        mCowMoo.dispose();
        mFreeTypeFontGenerator.dispose();
    }

    private enum AssociationScreenAnimationState {
        FADE_IN_FROM_BLACK,
        DELAY,
        FADE_OUT_TO_BLACK
    }
}




Java Source Code List

com.gregfmartin.facetapper.GameCore.java
com.gregfmartin.facetapper.Main.java
com.gregfmartin.facetapper.entities.CandyBase.java
com.gregfmartin.facetapper.entities.CandyDrop.java
com.gregfmartin.facetapper.entities.Pulse.java
com.gregfmartin.facetapper.entities.Screen.java
com.gregfmartin.facetapper.entities.SplashImage.java
com.gregfmartin.facetapper.entities.Sucker.java
com.gregfmartin.facetapper.screens.ArenaScreen.java
com.gregfmartin.facetapper.screens.AssociationScreen.java
com.gregfmartin.facetapper.screens.SplashScreen.java
com.gregfmartin.facetapper.screens.TitleScreen.java
com.gregfmartin.facetapper.utils.Colour.java
com.gregfmartin.facetapper.utils.CoreUtil.java
com.gregfmartin.facetapper.utils.DevSettings.java
com.gregfmartin.facetapper.utils.Gl20Utils.java
com.gregfmartin.facetapper.utils.MathEngine.java
com.gregfmartin.facetapper.utils.StagePrep.java