Hello, I need to take control of how my base game class updates:
package
{
import flash.display.Sprite;
import flash.events.KeyboardEvent;
public class Test extends Sprite
{
private var sprite:Sprite;
public function Test()
{
sprite = new Sprite();
sprite.graphics.beginFill(0xFF0000, 1);
sprite.graphics.drawRect(0, 0, 20, 20);
sprite.graphics.endFill();
addChild(sprite);
this.stage.addEventListener(KeyboardEvent.KEY_UP,
moveSprite);
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,
moveSprite);
}
private function moveSprite(keyEvent:KeyboardEvent):void
{
switch (keyEvent.keyCode)
{
case 37:
sprite.x--
break;
case 38:
sprite.y--;
break;
case 39:
sprite.x++
break;
case 40:
sprite.y++;
break;
default:
break;
}
}
}
}
Here after every key press/release AS3 takes care of automatically drawing a sprite onto screen, but I need to do this manualy. Haw to get my hands on updating mechanism here? I need something like this - all time repeating game loop that is set to be updated/redrawn every time at its end. Are there any ideas how could I achieve this?
Thanks everyone for help.