第三章 三角学应用Ⅱ [FL 基理译]
2009-05-30 12:08:41 来源:WEB开发网线性垂直运动
在 Wave1.as 文件中,加入了线性垂直运动,只是为我们制作动画增加一些灵感。以下是这个文件的代码:
package {
import flash.display.Sprite;
import flash.events.Event;
public class Wave1 extends Sprite {
private var ball:Ball;
private var angle:Number = 0;
private var centerY:Number = 200;
private var range:Number = 50;
private var xspeed:Number = 1;
private var yspeed:Number = .05;
public function Wave1() {
init();
}
private function init():void {
ball = new Ball();
addChild(ball);
ball.x = 0;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
ball.x += xspeed;
ball.y = centerY + Math.sin(angle) * range;
angle += yspeed;
}
}
}
心跳运动
使用正弦值作为一种工具,不仅仅只用于控制物理位置。在 Pulse.as 文件中,使用一个值来影响小球的缩放,实现一个心跳的效果,代码如下:
package {
import flash.display.Sprite;
import flash.events.Event;
public class Pulse extends Sprite {
private var ball:Ball;
private var angle:Number = 0;
private var centerScale:Number = 1;
private var range:Number = .5;
private var speed:Number = .1;
public function Pulse() {
init();
}
private function init():void {
ball = new Ball();
addChild(ball);
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event):void {
ball.scaleX = ball.scaleY = centerScale +
Math.sin(angle) * range;
angle += speed;
}
}
}
更多精彩
赞助商链接