2012年1月12日 星期四

flashpunk LinearMotion usage

幾個地方要注意
// auto remove when it has finished
var myTween = new LinearMotion(null, Tween.ONESHOT);

// auto stop and run myComplete when is has finished
var myTween = new LinearMotion(myComplete);

myTween.setMotion(to_x, 340, to_x, 300, 0.5, Ease.quadOut);

// don't start immediately
addTween(myTween, false);

you can check myTween.active in update().
完整範例如下:

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();
}
}
}
}
view raw gistfile1.as hosted with ❤ by GitHub

沒有留言:

張貼留言