遠ざかるボール
forked from base (diff: 52)
ActionScript3 source code
/**
* Copyright _wonder ( http://wonderfl.net/user/_wonder )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6AQc
*/
// forked from _wonder's base
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class Perspective extends Sprite {
private var ball:Ball;
private var xpos:Number = 0;
private var ypos:Number = 0;
private var zpos:Number = 0;
private var fl:Number = 250;
private var vpX:Number = stage.stageWidth / 2;
private var vpY:Number = stage.stageHeight / 2;
public function Perspective() {
ball = new Ball();
addChild( ball );
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
private function onEnterFrame(e:Event):void {
xpos = mouseX - vpX;
ypos = mouseY - vpY;
var scale:Number = fl / ( fl + zpos );
ball.scaleX = ball.scaleY = scale;
ball.x = vpX + xpos * scale;
ball.y = vpX + ypos * scale;
}
private function onKeyDown(e:KeyboardEvent):void {
if( e.keyCode == Keyboard.UP ){
zpos += 5;
} else if ( e.keyCode == Keyboard.DOWN ){
zpos -= 5;
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite {
public var radius:Number;
public var color:uint;
public var vx:Number = 0;
public var vy:Number = 0;
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();
}
}