When I do a animation with sprite from extended class, my animation wont working properly (don’t playing).
There’s is the class:
class Character extends Phaser.GameObjects.Sprite {
constructor (self, data, texture) {
super(
self,
self.positionToRealWorld(data.position.x),
self.positionToRealWorld(data.position.y)
);
this.data = {
sprite: data.sprite,
position: {
x: data.position.x || 1,
y: data.position.y || 1,
facing: data.position.facing || 0
},
stepFlag: 0
};
this.setTexture(texture);
//this.setFrame(self.database.characters[data.sprite].name + "_down_idle0");
this.setPosition(
self.positionToRealWorld(data.position.x),
self.positionToRealWorld(data.position.y)
);
this.setOrigin(
self.database.characters[data.sprite].origin.x,
self.database.characters[data.sprite].origin.y
);
// adiciona animação de idle
for (let i = 0, l = self.database.overworld.directions.length; i < l; i++) {
// criar animação idle para todos os lados
self.anims.create({
key: "idle_" + self.database.overworld.directions[i],
frames: [
{key: texture, frame: self.database.characters[data.sprite].name + "_" + self.database.overworld.directions[i] + "_idle0"},
{key: texture, frame: self.database.characters[data.sprite].name + "_" + self.database.overworld.directions[i] + "_idle1"}
],
frameRate: 2,
repeat: -1
});
console.log(
"frames",
{key: texture, frame: self.database.characters[data.sprite].name + "_" + self.database.overworld.directions[i] + "_idle0"},
{key: texture, frame: self.database.characters[data.sprite].name + "_" + self.database.overworld.directions[i] + "_idle1"}
);
// adiciona animação a sprite do player
console.log("key", "idle_" + self.database.overworld.directions[i]);
this.anims.load("load", "idle_" + self.database.overworld.directions[i]);
console.log("load", "idle_" + self.database.overworld.directions[i]);
};
// inicia animação idle
this.anims.play("idle_" + self.database.overworld.directions[data.position.facing]);
console.log("anims.play", "idle_" + self.database.overworld.directions[data.position.facing]);
self.containers.main.add(this);
}
onStartMove(callback) {
}
onEndMove(callback) {
}
onCantMove(callback) {
}
addInteraction (fn) {
this.setInteractive().on("pointerdown", fn);
}
preUpdate () {}
};
class Player extends Character {
constructor (self, data, texture) {
super(self, data, texture);
this.data.stop = data.stop || false;
this.data.walkInProgress = false;
}
preUpdate () {}
};
There’s the sprite insertion:
https://pastebin.com/U3wkjSvK
There’s the debug output:
When I do it whithout extend sprite class it works fine.