Skip to content

Instantly share code, notes, and snippets.

@BlckKnght
Created June 10, 2012 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BlckKnght/2907638 to your computer and use it in GitHub Desktop.
Save BlckKnght/2907638 to your computer and use it in GitHub Desktop.
My version of Mobias's TitleWorld class
package
{
import flash.display.Graphics;
import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.Graphic;
import net.flashpunk.graphics.Image;
import net.flashpunk.graphics.Text;
import net.flashpunk.Tween;
import net.flashpunk.tweens.misc.VarTween;
import net.flashpunk.utils.Ease;
import net.flashpunk.utils.Input;
import net.flashpunk.World;
import net.flashpunk.utils.Key;
/**
* ...
* @author Mobias
*/
public class TitleWorld extends World
{
protected var topTitle:Entity;
protected var bottomTitle:Entity;
protected var hasPlayedTitle:Boolean;
protected var infoText:Text;
protected var text:Entity;
protected var pressedAlready:Boolean;
public function TitleWorld()
{
hasPlayedTitle = false;
pressedAlready = false;
super();
}
override public function begin():void
{
topTitle = addGraphic(Image.createRect(800, 300, 0xaa4444));
topTitle.y = -FP.screen.height;
bottomTitle = addGraphic(Image.createRect(800, 300, 0x44aa44));
bottomTitle.y = FP.screen.height * 1.5;
var topTween:VarTween = new VarTween(onBounceIn);
topTween.tween(topTitle, "y", 0, 1.5, Ease.bounceOut);
addTween(topTween);
var bottomtween:VarTween = new VarTween();
bottomtween.tween(bottomTitle, "y", FP.screen.height/2, 1.5, Ease.bounceOut);
addTween(bottomtween);
}
public function onBounceIn():void
{
infoText = new Text("click to play");
infoText.size = 8;
infoText.x = FP.screen.width / 2 - infoText.width / 2;
infoText.y = FP.screen.height - 20;
trace(infoText.x, infoText.y);
infoText.alpha = 0;
infoText.color = 0;
text = addGraphic(infoText);
var textTween:VarTween = new VarTween(onTextFadeIn);
textTween.tween(infoText, "alpha", 1, 1, Ease.quartOut);
addTween(textTween, true);
}
public function onTextFadeIn():void
{
hasPlayedTitle = true;
}
override public function update():void
{
if (Input.mousePressed && hasPlayedTitle && !pressedAlready)
{
pressedAlready = true;
onPressPlay();
}
if (Input.pressed(Key.A))
{
trace(infoText.x, infoText.y, infoText.alpha);
}
}
public function onPressPlay():void
{
var textTween:VarTween = new VarTween(onTextFadeOut);
textTween.tween(infoText, "alpha", 0, 1, Ease.quartIn);
addTween(textTween, true);
}
public function onTextFadeOut():void
{
var topTween:VarTween = new VarTween(onTitleDisappear);
topTween.tween(topTitle, "y", -FP.screen.height, 1.5);
addTween(topTween);
var bottomtween:VarTween = new VarTween();
bottomtween.tween(bottomTitle, "y", FP.screen.height * 1.5, 1.5);
addTween(bottomtween);
}
public function onTitleDisappear():void
{
FP.world = new Game();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment