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.