Search code examples
actionscript-32dgame-enginestarling-framework

Having trouble with 2D texture movement


I'm having trouble with smooth character movement for a 2d game I'm making. It looks like the character is double when moving. Kinda like this (its just one pixel though):

 ( ()
/ /{}\  ==>
|  ||

The game runs on a solid 60 FPS and my monitor is not the problem (I have tested this on several monitors).

I'm using starling at the moment, but I've had this since I first stared making games (using openGL). I was hoping someone could tell me what I'm missing. Here is my code:

private var _x:Number = 20, _y:Number;

public function update(delta:Number):void
{
    if(gravity){
        _y += delta * 120;
    }

    if(_y + skin.image.height > game.stage.stageHeight){
        _y = game.stage.stageHeight - skin.image.height;
        gravity = false;
    }

    if(right && left){
        skin.playAnimation("none");
    }else if(left){
        _x -= delta * speed;
        skin.playAnimation("left");
    }else if(right){
        _x += delta * speed;
        skin.playAnimation("right");
    }

    //update skin
    skin.update(delta, Math.round(_x), Math.round(_y));
}

skin update method:

    public function update(delta:Number, x:int, y:int):void
    {
        image.x = x;
        image.y = y;
        if(currentAnimation){//this is texture switching (I tried without, still happens)
            currentAnimation.update(delta);
        }else{
            image.texture = textures[4];
        }
    }

Here is the game.


Solution

  • Based on my own experimentation, as well as all the data in the comments, I think the ghosting is dependent on the frame rate and the computer itself.

    First, and most importantly, when I tried the game in the link, it had the described ghosting at the full frame rate of 60. However, when I tried to film a screencast for further analysis, that occupied some CPU, dropping the frame rate down to around 35 or 40. At that point, the ghosting stopped.

    Second, because different people are reporting different experiences with the described ghosting, I'd also think that it has a little to do with the individual computers themselves, probably rooted in their available memory and CPU, though that's just a theory, as I don't have any benchmarks to go off of.

    Third, I think part of it is also rooted in neuroscience, as different people perceive animation differently.

    People always talk about wanting a higher frame rate, but honestly, to fix this, I would recommend LOWERING the frame rate. Flash Professional CS6 has a default frame rate of 24 FPS, and I have never experienced a ghosting problem to my memory. It is worth mentioning that Flash animators usually work in 24 FPS.

    Then again, appearance-wise, it really isn't a major deal. It is one of those graphics flaws that people tend to ignore, similar to the motion blur you get on 24 FPS films, until they changed it to 48.