开发者

gotoAndPlay is "sticking" on target frame for two frames

开发者 https://www.devze.com 2023-04-11 16:59 出处:网络
This makes absolutely no sense to me. I\'m calling gotoAndPlay(1) every 8 frames: public function advance():void {

This makes absolutely no sense to me.

I'm calling gotoAndPlay(1) every 8 frames:

public function advance():void {
    walkDistance += 2;
    if(walkDistance >= 16) {
        walkDistance -= 16;
        // update tile
        gotoAndPlay(1);
    }

    trace(currentFrame);
}

This is inside my Player class. advance() is being called from my ENTER_FRAME handler.

However the result of this is the player animation is looping the frames 1,1,2,3,4,5,6,7. I checked this by adding the numbers 1 to 8 as TextFields in the animation. trace(currentFrame) concurs, I am getting frame 1 twice.

I am certain I am not calling gotoAndPlay anywhere else. I checked this by overloading it:

override public function gotoAndPlay(frame:Object, scene:String = null):void {
    super.gotoAndPlay(frame, scene);
    trace开发者_运维问答("GOTOANDPLAY " + frame);
    trace((new Error).getStackTrace());
}

The result of both sets of traces are the following:

GOTOANDPLAY 1
Error
    at com.nitrome.blank::Player/gotoAndPlay()
    at com.nitrome.blank::Player/advance()
    at com.nitrome.blank::Level/advance()
at com.nitrome.blank::Controller$/enterFrame()
1
1
2
3
4
5
6
7
GOTOANDPLAY 1
Error
    at com.nitrome.blank::Player/gotoAndPlay()
    at com.nitrome.blank::Player/advance()
    at com.nitrome.blank::Level/advance()
    at com.nitrome.blank::Controller$/enterFrame()
1
1
2...

So as you can see I'm calling gotoAndPlay(1) once, but I'm getting frame 1 twice.

What can cause this? I can't reproduce this in any simple test. It must be a clash with something else I've written but I can't see what would cause it. When exactly does currentFrame advance one in relation to the stage ENTER_FRAME event? Is it possible that something might cause this to be skipped once?


Longshot (a very long one, but i'd like to help); i can't figure anything out in the code you show. Why do you call walkDistance -= 16; and not walkDistance = 0;? Maybe you could trace walkDistance? If something with walkDistance goes wrong, it could be calling the gotoAndPlay twice.

0

精彩评论

暂无评论...
验证码 换一张
取 消