Adding existing game object and playing animation


#1

how to play animation on added tile sprite game object

dude = this.add.tileSprite(100, 450, 100,100, 'dude');
player=this.physics.add.existing(dude, false);
player.body.setBounce(0.3);
player.body.setCollideWorldBounds(true);

Animation

this.anims.create({
    key: 'left',
    frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 3 }),
    frameRate: 10,
    repeat: -1
});

and playing it with the anims.play return dude.anims or player.anims is undefined

player.anims.play('left', true);

or

player.body.anims.play('left', true);

or

dude.anims.play('left', true);

the animation will play if I add the sprite by

player = this.physics.add.sprite(x,y,sprite)

#2

Show us all the code please.


#3
player = this.add.tileSprite(100, 450, 100, 100, 'dude');
this.physics.add.existing(dude, false);
player.anims.play('left', true);

#4

edited


#5

didn’t work, the function player.anims not found


#6

player = this.physics.add.sprite(100, 450, ‘dude’);
player.displayWidth=100;
player.displayHeight=100;

it seems tilesprite didn’t implement anims function so I tried to use sprite and display property and now everything work well.

thanks guys.