我有一个MovieClip
的菜单tweens
一直在运行,当用户点击开始游戏时,当我们添加menu.visible = true;
时,这会阻止菜单运行背景还是只是让它不可见,它会继续在后台运行并降低性能?
答案 0 :(得分:1)
内存中MovieClip
的所有实例(即存在对它们的引用或尚未由GC
收集)正在播放并消耗一些处理器时间来触发EnterFrame
事件或执行框架脚本。但是设置visible=false
或将其从stage
中删除以防止其呈现仍然很重要,这可能导致消耗更多资源。
小额奖金,我使用这种实用程序方法停止所有动画,然后将其从display list
移除,希望它有所帮助:
/**
* Stops all animations in the MovieClip and all its chilrend recursivly
*
* @param target
* @param self stop animation in target or not
* @param isGoToAndStopFirstFrame move all clips to the first frame
*
*/
public static function stopAll(target:DisplayObject, self:Boolean = true, isGoToAndStopFirstFrame:Boolean = false):void
{
if (!target)
return;
var t:int = getTimer();
var targetMovieClip:MovieClip = (target as MovieClip);
if (self && targetMovieClip)
{
if(isGoToAndStopFirstFrame)
{
targetMovieClip.gotoAndStop(1);
}else
{
targetMovieClip.stop();
}
}
//stops all children in DisplayObjectContainer
var targetContainer:DisplayObjectContainer = (target as DisplayObjectContainer);
if(targetContainer)
{
for (var i:int=0; i<targetContainer.numChildren; i++)
{
var child:DisplayObject = targetContainer.getChildAt(i);
if (child)
{
stopAll(child, true, isGoToAndStopFirstFrame);
}
}
}
// stops all states in SimpleButton
var targetSimpleButton:SimpleButton = (target as SimpleButton);
if(targetSimpleButton)
{
stopAll(targetSimpleButton.overState, true, isGoToAndStopFirstFrame);
stopAll(targetSimpleButton.upState, true, isGoToAndStopFirstFrame);
stopAll(targetSimpleButton.downState, true, isGoToAndStopFirstFrame);
stopAll(targetSimpleButton.hitTestState, true, isGoToAndStopFirstFrame);
}
return;
}