Skip to content

Instantly share code, notes, and snippets.

@wwwins
Created January 12, 2012 04:42
Show Gist options
  • Save wwwins/1598832 to your computer and use it in GitHub Desktop.
Save wwwins/1598832 to your computer and use it in GitHub Desktop.
package
{
import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.graphics.BitmapFont;
import net.flashpunk.graphics.BitmapText;
import net.flashpunk.graphics.Text;
import net.flashpunk.Tween;
import net.flashpunk.tweens.motion.LinearMotion;
import net.flashpunk.utils.Ease;
public class MotionScore extends Entity
{
protected var text_score:Text;
private var myTween:LinearMotion;
private var to_x:Number;
private var currText:String;
public function MotionScore()
{
currText = "";
to_x = FP.halfWidth - 50;
x = to_x;
y = 340;
text_score = new Text("", 0, 0, { color:0xFF0000, size:26, align:"center" }, 25);
graphic = text_score;
// auto remove when it has finished.
//myTween = new LinearMotion(null, Tween.ONESHOT);
myTween = new LinearMotion(myComplete);
myTween.setMotion(to_x, 340, to_x, 300, 0.5, Ease.quadOut);
addTween(myTween, false);
}
public function playTween():void
{
myTween.start();
text_score.visible = true;
}
private function myComplete():void
{
myTween.active = false;
text_score.visible = false;
x = to_x;
y = 340;
}
override public function update():void {
if (myTween.active) {
// setting x,y position
x = myTween.x;
y = myTween.y;
text_score.text = currText;
return;
}
if (Main.showscore.length > 0) {
currText = "+" + Main.showscore.shift();
playTween();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment