ゲージの描き方と動作のさせ方
wonderfl 010309の「フレームごとに対応するマウス座標の保存」で、画面下部に表示されているゲージの書き方を詳しく見てみる。
ゲージの表示に関するもの以外の部分をコードから削除してみる。ゲージの高さを変える方法を理解するのに苦労したが、なんとか読解できた。以下、ゲージを動作させる必要最小限のコード。
// forked from Murai's #3 MouseRecord forked from: #2 Loop forked from: #1 LikeATimeLine WonderflBook Interactive2 // forked from Murai's #2 Loop forked from: #1 LikeATimeLine WonderflBook Interactive2 // forked from Murai's #1 LikeATimeLine WonderflBook Interactive2 package { import flash.display.Sprite; import flash.events.Event; [SWF(width="465",height="465",backgroundColor="0xFFFFFF",frameRate="30")] public class WonderflBook extends Sprite { private var _timeGage:Sprite; private var _frameCount:uint=0; private var _frameCountLimit:uint=150; public function WonderflBook(){ init(); } public function init():void{ _timeGage=new Sprite(); _timeGage.graphics.beginFill(0x55FF22,1); _timeGage.graphics.drawRect(0,0,stage.stageWidth,40); _timeGage.graphics.endFill(); //_timeGage.x=-1; _timeGage.y=stage.stageHeight-100; addChild(_timeGage); start(); } private function render(e:Event):void{ if(_frameCount >= _frameCountLimit){ _frameCount=0; } _timeGage.width=(_frameCount/_frameCountLimit)*stage.stageHeight; //_timeGage.height = 400; _frameCount++; } public function start():void{addEventListener(Event.ENTER_FRAME,render);}; } }
_timeGage.y=stage.stageHeight-100;で、ゲージのy座標を指定している。ゲージ自体は、drawRectで描かれている。その長方形の高さは、_timeGage.graphics.drawRect(0,0,stage.stageWidth,40);で決める(この場合40)。