I'm probably overlooking something, but i can't get my sprite animations to loop in the script below. I got 2 animations, walking and standing. And i'm trying to switch between the two when i press a button. the switching works, but if i hold down the button, the walking animation doesn't loop. I used certain code snippets from the Telemachus example and the animator.js is from the sprite and animations tutorial.
// create player sprites and put them in a group
var playerSheet = new animator.SpriteSheet('images/player.gif', {width: 32, height: 44});
var playerAnimation = new animator.AnimationSheet(playerSheet, {'idle': [0], 'walk': [1,12]}, 25);
var playercharacter = new PlayerCharacter([50, 400], playerAnimation);
playercharacter.moveDelta = [0, 0];
playercharacter.moveSpeed = 10;
playerAnimation.start('idle');
var keysDown = {};
function handleEvent(event) {
if (event.type === gamejs.event.KEY_DOWN) {
keysDown[event.key] = true;
} else if (event.type === gamejs.event.KEY_UP) {
keysDown[event.key] = false;
};
// left, right
if (keysDown[gamejs.event.K_a]) {
playercharacter.moveDelta[0] = -playercharacter.moveSpeed;
playerAnimation.start('walk');
} else if (keysDown[gamejs.event.K_d]) {
playercharacter.moveDelta[0] = +playercharacter.moveSpeed;
playerAnimation.start('walk');
} else {
playercharacter.moveDelta[0] = 0;
playerAnimation.start('idle');
}
// up / down
if (keysDown[gamejs.event.K_w]) {
playercharacter.moveDelta[1] = -playercharacter.moveSpeed
playerAnimation.start('walk');
} else if (keysDown[gamejs.event.K_s]) {
playercharacter.moveDelta[1] = +playercharacter.moveSpeed;
playerAnimation.start('walk');
} else {
playercharacter.moveDelta[1] = 0;
}
};