Function Actionscript 3:如何使用一个enter frame函数获取所有类?

Function Actionscript 3:如何使用一个enter frame函数获取所有类?,function,actionscript,frame,enter,Function,Actionscript,Frame,Enter,我正在AS3做一个冒险游戏,有很多课程。我听说,如果只有一个Enter Frame函数,并且所有更新函数都从该函数运行,那么对性能来说是最好的 我目前在main.as中有一个mainGameLoop,对于我所有的类来说,最好的方式是什么来包含从这个单输入帧函数运行的更新函数 下面是一个我在我的Player类中运行update函数的例子,但我一点也不喜欢这个解决方案 如果有人能帮忙,我将不胜感激,谢谢 public class Main extends MovieClip { // Ini

我正在AS3做一个冒险游戏,有很多课程。我听说,如果只有一个Enter Frame函数,并且所有更新函数都从该函数运行,那么对性能来说是最好的

我目前在main.as中有一个mainGameLoop,对于我所有的类来说,最好的方式是什么来包含从这个单输入帧函数运行的更新函数

下面是一个我在我的Player类中运行update函数的例子,但我一点也不喜欢这个解决方案

如果有人能帮忙,我将不胜感激,谢谢

public class Main extends MovieClip
{
    // Initialising variables...
    private var m_SceneHandler:SceneHandler;
    private var m_UserInput:UserInput;

    public function Main()
    {
        // Adding main update function...
        addEventListener( Event.ENTER_FRAME, mainGameLoop );

        // Creating the scene handler...
        m_SceneHandler = new SceneHandler();
        addChild( m_SceneHandler );
    }

    private function mainGameLoop( event:Event )
    {
        doUpdate();
    }

    private function doUpdate():void
    {
        // Update player...
        if (m_SceneHandler.m_aCurrentScene[0].m_Player)
        {
             m_SceneHandler.m_aCurrentScene[0].m_Player.doUpdate();
        }       

}

使用复合模式和代码创建可更新的接口

package view { public interface IUpdateable { function doUpdate():void; } } 包视图{ 可更新的公共接口{ 函数doUpdate():void; } } 在主游戏循环中,只需切换出应更新的对象:

package{ public class Main extends MovieClip implements IUpdateable { protected var updateChildren:Vector. = new Vector.(); //other logic would manage who is currently updateable and who is not public function doUpdate():void { for each (var updateable:IUpdateable) { updateable.doUpdate(); } } } } 包装{ 公共类Main扩展MovieClip实现IUpdateable{ 受保护的var updateChildren:Vector.=新向量。(); //其他逻辑将管理谁当前可更新,谁不可更新 公共函数doUpdate():void{ 对于每个(变量可更新:IUpdateable){ 可更新的.doUpdate(); } } } }
然后,如果有需要更新的子组件,它们也可以是IUpdateable,更高级别的IUpdateable可以调用该方法。

我认为这种方法没有问题。你不喜欢它的什么?一个场景并不总是在运行,因此if语句。我想我不喜欢主课和球员说话。我决定主更新函数将在m_SceneHandler中运行更新函数,然后在其内部在当前场景中运行更新,然后在其内部在播放器中运行更新。通过像这样向下钻取,它看起来更具可扩展性。