要大大降低FPS

时间:2014-04-17 21:37:49

标签: actionscript-3

http://www.fastswf.com/USUAp00

当我将基于perlin噪声贴图的程序生成的地图缩放到更大的尺寸时,我可以在地图上放置一个角色并实际导航它(在地图周围移动地图而不是地图上的玩家),它会导致主要的fps下降。 使用提供的链接测试自己,比例或地图宽度/高度越高,行走时滞后越多。我知道这是分配移动的数据块

有没有更好的方法来移动我的玩家? 将生成的对象添加到对象池有帮助吗?我认为不会

是否可以在生成后将地图拆分为细分,并根据x,y?

加载某些细分

World class://处理产生地图 http://pastebin.com/CfMDBWeR

级别类://处理移动地图

public class Level extends MovieClip
{
    var world:World;
    protected var goin:Vector.<int> = new Vector.<int>();
    protected var moveSpeed:int;
    protected var MAP_SCALE:int;


    public function Level()
    {
        MAP_SCALE = GlobalCode.MAP_SCALE;
        trace("level")
        for(var i:int = 0; i < 4; i++){
            goin[i]=0;
        }
        world = new World(this);
        addEventListener(Event.ENTER_FRAME, update);
        addEventListener(Event.ADDED_TO_STAGE, init);
        addEventListener(Event.REMOVED_FROM_STAGE, cleanUp);
        moveSpeed = 10;
        // constructor code
    }
    protected function init(e:Event)
    {
        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
        stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
    }
    protected function cleanUp(e:Event)
    {
        stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
        stage.removeEventListener(KeyboardEvent.KEY_UP, keyReleased);
    }
    protected function keyPressed(k:KeyboardEvent)
    {
        if (k.keyCode == Keyboard.W)
        {
            goin[0] = 1;
        }
        if (k.keyCode == Keyboard.S)
        {
            goin[1] = 1;
        }
        if (k.keyCode == Keyboard.A)
        {
            goin[2] = 1;
        }
        if (k.keyCode == Keyboard.D)
        {
            goin[3] = 1;
        }
    }
    protected function MovePlayer(){
        if (goin[0] == 1)
        {
            world.worldTiles.y +=  moveSpeed;
        }
        if (goin[1] == 1)
        {
            world.worldTiles.y -=  moveSpeed;
        }
        if (goin[2] == 1)
        {
            world.worldTiles.x +=  moveSpeed;
        }
        if (goin[3] == 1)
        {
            world.worldTiles.x -=  moveSpeed;
        }
    }

    protected function keyReleased(k:KeyboardEvent)
    {
        if (k.keyCode == Keyboard.W)
        {
            goin[0] = 0;
        }
        if (k.keyCode == Keyboard.S)
        {
            goin[1] = 0;
        }
        if (k.keyCode == Keyboard.A)
        {
            goin[2] = 0;
        }
        if (k.keyCode == Keyboard.D)
        {
            goin[3] = 0;
        }
    }
    public function update(e:Event)
    {
        world.worldTiles.scaleX = MAP_SCALE;
        world.worldTiles.scaleY = MAP_SCALE;
        MovePlayer();
    }
}

Stage Class:实际连接到舞台的类,处理帧切换

public class Stage extends MovieClip {
    private var targetFrame:String;

    public function Stage() {
        targetFrame = "Menu";
        // constructor code
    }
    private function gotoLabel(desiredLabel:String)
    {
        for (var i=0; i<currentLabels.length; i++)
        {
            if (currentLabels[i].name == desiredLabel)
            {
                gotoAndPlay(desiredLabel);
                return;
            }
        }
        trace("Requested frame missing!");
    }
    public function generateMap(m:MouseEvent){
        GlobalCode.TILE_SIZE = int(tileSizeText.text);
        GlobalCode.MAP_HEIGHT = int(mapHeightText.text);
        GlobalCode.MAP_WIDTH = int(mapWidthText.text);
        GlobalCode.MAP_SCALE = int(mapScaleText.text);
        gotoLabel("Game");
    }
    private function doneLoading(m:MouseEvent)
    {
        //set targetFrame
        gotoLabel("Menu");
    }
  }

0 个答案:

没有答案