Hello, I have some trouble with .flipX with an animation. The origin of the image should be changed but it doesn’t work the way I think it should work…
In preload I load some images:
this.load.image(‘walk01’, ‘assets/walk001.png’)
this.load.image(‘walk02’, ‘assets/walk002.png’)
this.load.image(‘walk03’, ‘assets/walk003.png’)
this.load.image(‘walk04’, ‘assets/walk004.png’)
…
The image ‘walk001’ has a Dino but its not centered. The dino is positioned to the left of the origin. The same with the other images.
In create I make the animation:
this.anims.create({
key: ‘walking’,
frames: [{
key: ‘walk01’
},
{
key: ‘walk02’
},
{
key: ‘walk03’
},
{
key: ‘walk04’
},
…
],
frameRate: 6,
repeat: -1,
})
Then also in create I place the dino with the animation:
dino = this.physics.add.sprite(320, 43, 'walk01')
dino.play('walking')
.setScale(0.25)
.setSize(420, 420, 0, 0)
.setOffset(0, 0)
The setSize/setOffset is there to place the colliding box at the right place (as its normally the same as the image borders, which are incorrect with this image files).
This works. The dino animates ‘walking’ and I can give it some velocity.
But when I call flipX:
dino.setVelocityX(value)
if (value < 0) {
dino.flipX = true
} else {
dino.flipX = false
}
it flips around the center of the image. The dino should flip around its own center (which is left from the image center).
My thought is to set the origin of the whole animation to the left, making a pivot point that is in de center of the dino. OR maybe I should set the origin of every single image?
Making the origin in the middle of the dino makes the x,y coordinates of the dino more useful too.
But I can’t get it working.
Not with .setOrigin, nor .setDisplayOrigin.
What (where?) is the best way to get this done?