Back to project page proteus-sidescroller.
The source code is released under:
GNU General Public License
If you think the Android project proteus-sidescroller 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.bartholomew.proteus; /* w ww . jav a 2s.c om*/ import aurelienribon.tweenengine.Timeline; import aurelienribon.tweenengine.Tween; import aurelienribon.tweenengine.TweenManager; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.bartholomew.proteus.tween.ActorAccessor; public class MainMenu implements Screen { private Stage m_stage; private TextureAtlas m_atlas; private Skin m_skin; private Table m_table; private TweenManager m_tweenManager; @Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); //DEBUG //Table.drawDebug(m_stage); m_stage.act(delta); m_stage.draw(); m_tweenManager.update(delta); } @Override public void resize(int width, int height) { m_stage.setViewport(width, height, true); m_table.invalidateHierarchy(); m_table.setSize(width, height); } @Override public void show() { m_stage = new Stage(); Gdx.input.setInputProcessor(m_stage); // Allows the buttons to be pressed automatically m_atlas = new TextureAtlas("ui/button.pack"); m_skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), m_atlas); m_table = new Table(m_skin); m_table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); // Creating heading Label heading = new Label(Proteus.TITLE, m_skin); heading.setFontScale(3); // Multiply the font size by 3 // Make both buttons TextButton buttonExit = new TextButton("Exit", m_skin); buttonExit.pad(20); buttonExit.addListener(new ClickListener(){ public void clicked(InputEvent event, float x, float y) { Gdx.app.exit(); // Set up Exit button functionality } }); TextButton buttonPlay = new TextButton("Play", m_skin); buttonPlay.pad(20); buttonPlay.addListener(new ClickListener(){ public void clicked(InputEvent event, float x, float y){ ((Game) Gdx.app.getApplicationListener()).setScreen(new GameWorld()); } }); // Adding Actors to m_table m_table.add(heading); m_table.getCell(heading).spaceBottom(100); m_table.row(); // Put a new row now, so put the heading above the code that's below here m_table.add(buttonPlay); m_table.getCell(buttonPlay).spaceBottom(10); m_table.row(); m_table.add(buttonExit); //DEBUG DONE Remove later. Adds red lines around boxes and such //m_table.debug(); m_stage.addActor(m_table); // Create animations m_tweenManager = new TweenManager(); Tween.registerAccessor(Actor.class, new ActorAccessor()); // Heading color animation Timeline.createSequence().beginSequence() // Fade heading into different colors forever .push(Tween.to(heading, ActorAccessor.RGB, 0.5f).target(0, 0, 1)) .push(Tween.to(heading, ActorAccessor.RGB, 0.5f).target(0.5f, 1, 0)) .push(Tween.to(heading, ActorAccessor.RGB, 0.5f).target(1, 0, 0.2f)) .push(Tween.to(heading, ActorAccessor.RGB, 0.5f).target(1, 1, 0)) .push(Tween.to(heading, ActorAccessor.RGB, 0.5f).target(0, 0.1f, 0.4f)) .push(Tween.to(heading, ActorAccessor.RGB, 0.5f).target(1, 1, 1)) .end().repeat(Tween.INFINITY, 0).start(m_tweenManager); // Heading and buttons fade-in Timeline.createSequence().beginSequence() .push(Tween.set(buttonPlay, ActorAccessor.ALPHA).target(0)) .push(Tween.set(buttonExit, ActorAccessor.ALPHA).target(0)) .push(Tween.from(heading, ActorAccessor.ALPHA, 0.25f).target(0)) .push(Tween.to(buttonPlay, ActorAccessor.ALPHA, 0.25f).target(1)) .push(Tween.to(buttonExit, ActorAccessor.ALPHA, 0.25f).target(1)) .end().start(m_tweenManager); // Table fade-in Tween.from(m_table, ActorAccessor.ALPHA, 0.5f).target().target(0).start(m_tweenManager); Tween.from(m_table, ActorAccessor.Y, 0.5f).target(Gdx.graphics.getHeight() / 8).start(m_tweenManager); } @Override public void hide() { dispose(); } @Override public void pause() { } @Override public void resume() { } @Override public void dispose() { m_stage.dispose(); m_atlas.dispose(); m_skin.dispose(); } }