espace
November 10, 2019, 4:29am
1
Hi,
I would like to play an animation with a spritesheet inside my prototype. But i can’t see the animation playing… Why ?
class Sp_matter extends Phaser.Physics.Matter.Sprite {
constructor(scene,x,y,texture,num) {
super(scene.matter.world,x,y,texture,num);
this.setTexture(texture)
this.setFrictionAir(0.0005)
this.setBounce(.1)
//spritesheet animation
this.scene.anims.create({
key: 'eye',
frames: this.scene.anims.generateFrameNames('pig'),
frameRate: 2,
repeat: -1
});
this.play('eye')
scene.add.existing(this)
}
preUpdate(time, delta) {
super.preUpdate(time, delta)
}
}
tac
November 10, 2019, 4:45am
2
You have to move your play() to inside its own separate function. Why? Probably because it hasn’t been created yet since you have anims.create() inside the same block.
espace
November 10, 2019, 8:01am
3
hi,
yeah it works but i have still a problem because i have my texture on a sub-element => this.main and in this case your solution don’t work. Do you have an issue ? i have tested a lot of things but without success…
class Sp_ extends Phaser.Physics.Matter.Sprite {
constructor(scene,x,y,texture,num) {
super(scene.matter.world,x,y,texture,num);
this.setTexture(texture)
this.setFrictionAir(0.0005)
this.setBounce(.1)
this.main = scene.add.sprite(this.x,this.y,'pig')
this.scene.anims.create({
key: 'eye',
frames: this.scene.anims.generateFrameNames('pig'),
frameRate: 2,
repeat: -1
});
scene.add.existing(this)
}
preUpdate(time, delta) {
super.preUpdate(time, delta)
this.main.setPosition(this.x,this.y)
}
anim_eye(){
this.main.play('eye')
}
}
//
pig = new Sp_(this,100,200,'texture_matter')
pig.anim_eye()
the error is :
this.main.play is not a function
tac
November 10, 2019, 8:37am
4
your code has many careless errors. you are trying to call your class incorrectly for one
pig = new Sp_(this,100,200,‘texture_matter’)
your class is called Sp_matter , not Sp_
you need to keep your anims.create() call in your constructor. only move your anims.play() to anim_eye()
espace
November 10, 2019, 8:44am
5
ok it 's updated.
but i still can’t animate this.main…