samedi 24 décembre 2016

EnterFrame listener that rotates sprite KILLS my framerate?

Well, I'm not quite a newbie, and not nearly an expert, but I find this very strange. I have a class that creates an array of images and rotates through them in an ENTER_FRAME listener function, a la animated gif.
Fine.
I added another ENTER_FRAME listener that rotates the object in increments of .5 degrees until it reaches 23.5 degrees, which it does, but my frameRate slows to a crawl.
Bad!
At one time I put a getTimer() device into the first listener to measure how fast it is being called, and I saw about 20ms without the rotation listener, and 200-250ms when the rotation listener was active.
Also of note, when the rotation listener reaches 23.5 degrees, and turns itself off, the calling of the frameAdvance listener stays the same (terribly slow).

Functions in my class:

    private function drawThis():void {
        removeEventListener(Event.ENTER_FRAME, wait4images);            
        for (var i:int = 0; i < shapeLoader.ShapeArr.length; i++) {
            addChild(shapeLoader.ShapeArr[i]);
        }

        //stage.addEventListener(Event.ENTER_FRAME, rotateme);
             //like this, it works quickly!

        stage.addEventListener(Event.ENTER_FRAME, rotateme);
             //like this, it is very slow!

        graphics.lineStyle(2,0xff0000)
        graphics.moveTo(0, -this.width / 2);
        graphics.lineTo(0, this.width / 2);
        addEventListener(Event.ENTER_FRAME, frameAdvance,false,0,true);
    }

    private function rotateme(e:Event):void{
        this.rotation += .5;
        if (this.rotation == 23.5) {
            stage.removeEventListener(Event.ENTER_FRAME, rotateme);
        }
    }

    private function frameAdvance(e:Event):void {
        frameNo += 1;   
        addChild(shapeLoader.ShapeArr[frameNo]);
        if (frameNo == 23) {
            frameNo = 0;
        }
    }

Any ideas/explainations/solutions for this problem out there?

Aucun commentaire:

Enregistrer un commentaire