As3位于顶部基于Y而没有滞后?

时间:2015-01-08 18:31:02

标签: performance actionscript-3 position

我正在使用自己制作的标签系统创建一个位置脚本,以按照y位置的顺序定位所有对象。这个脚本使我的游戏滞后,所以我想问一下是否有更好的方法。 PS:每帧使用此代码。

private function positionGameObjectToLayer():void 
    {
        var objectOnScreen : Array = [];
        var parentObj : Sprite;
        var l : int;
        l = gameObjects.length;
        for (var i : int = 0; i < l; i++) {
           /*checks if the object has the position tag*/
            if (gameObjects[i].checkTag(Tags.POSITION_ON_Y_TAG)) {  
                objectOnScreen.push(gameObjects[i]); //if it does it goes into this array   
            }
        }
        objectOnScreen.sortOn("y", Array.NUMERIC); /* sorts the array on y position*/
        l = objectOnScreen.length;
        for (i = 0; i < l; i++) {
            /*this sets the layer of the object in order of the array*/
            parentObj = objectOnScreen[i].parent;
            parentObj.setChildIndex(objectOnScreen[i],parentObj.numChildren - 1); 
        }
        l = gameObjects.length;
        for (i = 0; i < l; i++) {
           //if it has the always on top tag
            if (gameObjects[i].checkTag(Tags.POSITION_ON_TOP_TAG)) {
                /*then this code will grab that object and place it over the other layers*/
                parentObj = gameObjects[i].parent;
                parentObj.setChildIndex(gameObjects[i], parentObj.numChildren - 1); 
            }
        }
    }

0 个答案:

没有答案