JavaScript Sprite

I’ve been working on a small browser-game with a friend of mine, I posted about it here: http://forums.graal.in/forums/showthread.php?7553-Ivy-js-(Random-Project)
As you may have noticed in the video, the player moves “awkwardly”, he skips a frame instead of going through all 4 (see sprite sheet attached below).
I’ve tried messing with the following code, but nothing really works, my friend gave it a shot too but he couldn’t fix it either.
I’d be fine if you hinted to where the problem was, I don’t need anyone to rewrite the entire code, unless it’s necessary.
Thanks again.

        var player = new Sprite(32, 49);
        player.x = 6 * 16 - 8;
        player.y = 10 * 16;
        var image = new Surface(96, 194);
        image.draw(game.assets['chara0.gif'], 0, 0, 96, 194, 0, 0, 96, 194);
        player.image = image;

        player.isMoving = false;
        player.direction = 0;
        player.walk = 1;
        player.addEventListener('enterframe', function() {
            this.frame = this.direction * 3 + this.walk;
            if (this.isMoving) {
                this.moveBy(this.vx, this.vy);
 
                if (!(game.frame % 3)) {
                    this.walk++;
                    this.walk %= 3;
                }
                if ((this.vx && (this.x-8) % 16 == 0) || (this.vy && this.y % 16 == 0)) {
                    this.isMoving = false;
                    this.walk = 1;
                }
            } else {
                this.vx = this.vy = 0;
                if (game.input.left) {
                    this.direction = 1;
                    this.vx = -4;
                } else if (game.input.right) {
                    this.direction = 2;
                    this.vx = 4;
                } else if (game.input.up) {
                    this.direction = 3;
                    this.vy = -4;
                } else if (game.input.down) {
                    this.direction = 0;
                    this.vy = 4;
                }

[ATTACH=CONFIG]3682[/ATTACH]

Edit: I’m not sure if the code fragment I provided is enough to fix the problem, if anyone needs me to host the files online I’ll gladly do so.

There’s only three images for each direction and not four. So I’m not sure what you mean.

I’m assuming he wants it to do something like

Frame1 Frame2 Frame3 Frame2 -> repeat,

but it’s doing something like

Frame1 Frame2 Frame3 -> repeat

idk what language he’s using so I can’t help much past that.

Javascript, it’s in the thread title.

The lazy way would be to add the second sprite-frame again. I don’t actually see the code that determines which part of the image is going to be used in this snippet, so it’s going to be hard to help out.

I meant that I don’t know Javascript. >.<

Oh, lol. I misread. Sorry about that. :smiley: