PushButton Engine不会主动执行主循环从而控制你的游戏,你必须要亲自启动它
Engine Startup
如果你使用PushButton Engine MXML tags,在程序启动时尽可能早地处理,层相关的tags在应用程序事件结束后处理,资源 相关的tags在被flex加载时立刻被处理 - usually in the first few frames.
为了管理这些tag,ResourceManager, LevelManager, and other managers也许被初始化和创建
如果你手动启动游戏,直接调用管理者,不使用标签。
ProcessManager管理着主循环和回调函数,并允许你设置回调对象的相关优先级
Frame Callbacks框架回调在IAnimatedObject接口中发生,简单执行IAnimatedObject interface,调用ProcessManager.instance.addAnimatedObject(this),如:
// Example of a component that receives per-frame callbacks.
public class DemoAnimatedComponent extends EntityComponent implements IAnimatedObject
{
public function onFrame(elapsed:Number):void
{
trace("Frame happened, and " + elapsed + "ms passed since last time.");
}
protected override function onAdd():void
{
ProcessManager.instance.addAnimatedObject(this);
}
protected override function onRemove():void
{
ProcessManager.instance.removeAnimatedObject(this);
}
}
PBLabs.Engine.Components.AnimatedComponent帮你自动注册和注销活跃对象,并可以设置优先级
Ticks
Ticks确保在固定间隔发生,ProcessManager负责产生Ticks,相当一个计时器,在onTick回调时,执行自己的代码。
// Example of a component which receives tick callbacks.
public class DemoTickedComponent extends EntityComponent implements ITickedObject
{
public function onTick(tickRate:Number):void
{
trace("A tick happened!");
}
protected override function onAdd():void
{
ProcessManager.instance.addTickedObject(this);
}
protected override function onRemove():void
{
ProcessManager.instance.removeTickedObject(this);
}
}
TickedComponent基类简单创建一个产生ticks的组件
ProcessManager,在第个frame(框架)的开始处(the ENTER_FRAME事件),做以下工作:
ProcessManager产生:IAnimatedObject回调、tick回调ITickedObject onTick、待定事件
Process IAnimatedObject callbacks.
Process any pending ticks by calling ITickedObject onTick zero or more times.
Process any pending events.