问题描述
正如标题状态,我想知道什么是最好的方式在舞台上处理多个影片剪辑在同一时间,每个都有自己的onEnterFrame功能。比方说,我们有50个敌人在屏幕上一次,不断播放着一个行走动画。该的onEnterFrame功能将包括得到一个方向,移动X / Y值,检查播放器和自身之间的距离,检查是否处于可攻击距离等你可以想象很多滞后的occures的。
As the title states, I'm wondering what the best way to handle several movieclips on the stage at one time, each with their own onEnterFrame functions. Lets say we have 50 enemies on the screen at once, constantly playing a walking animation. The onEnterFrame function would consist of getting a direction, moving X/Y values, checking the distance between the player and itself, checking if it is in an attackable distance, etc. As you can imagine a lot of lag occures.
这是一个类型的游戏,这个问题通常是解决将是僵尸游戏在那里你会在屏幕上多个僵尸一次的。
An type of a game where this problem is usually overcome would be in zombie games where you would have multiple zombies on the screen at one time.
处理多个影片剪辑像这样的时候会是什么,以减少延迟的最佳方法是什么?
What would be the best way to reduce lag when handling multiple movieclips like this?
推荐答案
每个的onEnterFrame听众创造了新的事件对象,所以更的onEnterFrame的听众,你有更多的对象被创建每一帧。而在AS2创建对象是pretty的慢。
Each onEnterFrame listener creates new event objects, so the more onEnterFrame listeners you have the more objects gets created each frame. And in AS2 object creation is pretty slow.
所以,有优化要考虑的是刚刚注册的一个的onEnterFrame通过所有的敌人等事件,然后从主的onEnterFrame循环,并呼吁每个实例的更新功能。
So, one optimization to consider is to just register one onEnterFrame event and then from that "main" onEnterFrame loop through all enemies etc. and call an update function on each instance.
这也从一个code结构上看是个好主意,因为你现在只有一条code运行的每一帧。它可以更容易地看到什么是真正运行的每一帧。而暂停游戏,你可以简单地停止主的onEnterFrame和整场比赛将停止。
It is also a good idea from a code structure point of view since you now only have one piece of code running each frame. It makes it easier to see what is actually running each frame. And to pause the game you could simply stop the main onEnterFrame and the whole game would stop.
这篇关于AS2最好的方法时,与几个影片剪辑与onEnterFrames处理减少滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!