Pay for Hesitation: 利用sin()來達到motion smooth
Pay for Hesitation
Ideas are Worthless Unless Acted Upon
Pages
Home
Authors
2008年3月25日 星期二
利用sin()來達到motion smooth
http://imlab.cs.nccu.edu.tw/~pie/bounceBall.swf
注意在Bobbing class中的onEnterFrame(),
利用sin是-1~1之間的平滑曲線性質,來smooth球上下彈跳的motion
package anim {
import flash.display.Sprite;
public class Ball extends Sprite {
private var radius:Number;
private var color:uint;
public function Ball(radius:Number=40, color:uint=0xff0000) {
this.radius = radius;
this.color = color;
init();
}
public function init():void {
graphics.beginFill(color);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
}
}
}
package anim
{
import flash.display.Sprite;
import flash.events.Event;
public class Bobbing extends Sprite {
private var ball:Ball;
private var angle:Number = 0;
private var centerY:Number = 200;
private var range:Number = 50;
private var speed:Number = .1;
public function Bobbing(x:int) {
init(x);
}
private function init(x:int):void {
ball = new Ball();
addChild(ball);
ball.x = x / 2;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
ball.y = centerY + Math.sin(angle) * range;
angle += speed;
}
}
}
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言