forked from: Wonderfl Book vol.02 Loop
forked from Wonderfl Book vol.01 (diff: 30)
ActionScript3 source code
/**
* Copyright genny ( http://wonderfl.net/user/genny )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/t6AM
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.GlowFilter;
[SWF(backgroundColor="0x000000", frameRate="30")]
public class LikeTimeLine2 extends Sprite
{
// Property
private var _ball:Sprite;
private var _timeGage:Sprite;
private var _startX:int = 0;
private var _startY:int = stage.stageHeight/2;
private var _endX:int = stage.stageWidth;
private var _frameCount:int = 0;
private var _frameCountLimit:int = 150;
private var _animationFrames:Array;
// Constructer
function LikeTimeLine2()
{
init();
}
// initialize
private function init() :void
{
// フレーム数分の座標値を算出
_animationFrames = generateAnimationFrames();
// ボールを生成
_ball = new Sprite();
_ball.graphics.beginFill( 0x66CC33 );
_ball.graphics.drawCircle( 0, 0, 5 );
_ball.graphics.endFill();
addChild( _ball );
_ball.x = _startX;
_ball.y = _startY;
_ball.filters = [ new GlowFilter( 0x66CC33, 1, 20, 20, 2, 2) ];
// タイムゲージの生成
_timeGage = new Sprite();
_timeGage.graphics.beginFill( 0x333333 );
_timeGage.graphics.drawRect( 0, 0, stage.stageWidth, 5 );
_timeGage.graphics.endFill();
addChild( _timeGage );
_timeGage.x = 0;
_timeGage.y = stage.stageHeight - 5;
_timeGage.width = 0;
// レンダリング開始
start();
}
/**
* Handler
*/
private function render( event:Event ) :void
{
if( _frameCount <= _frameCountLimit )
{
_ball.x = _animationFrames[ _frameCount ];
}
else
{
//stop();
_ball.x = 0;
_frameCount = 0;
}
// タイムゲージの伸縮
_timeGage.width = ( _frameCount / _frameCountLimit ) * stage.stageWidth;
_frameCount ++;
trace(_frameCount);
}
/**
* Listener
*/
private function start() :void
{
addEventListener( Event.ENTER_FRAME, render );
}
private function stop() :void
{
removeEventListener( Event.ENTER_FRAME, render );
}
/**
* 移動座標の算出を行う
*/
private function generateAnimationFrames() :Array
{
var arr:Array = new Array();
var tmpX:Number = _startX;
var len:int = _frameCountLimit;
var easeRatio:Number = 0.2;
for( var i:int = 0; i < len; i ++ )
{
tmpX += ( _endX - tmpX ) * easeRatio;
arr.push( tmpX )
}
return arr;
}
}
}