Load json file and change frames

I load and add my json file like,

this.load.atlas(‘sprite’, sprite.png, sprite.json);

sprite=this.add.sprite(400,300,‘sprite’)

Now what i need i have 14 to 15 frames in json.how can i call particular frame using phaser3

You could try handling it something like this:
https://labs.phaser.io/edit.html?src=src\animation\from%20json.js

1 Like

Thanks sturb,
can i use setFrame concept for json.is that possible?

Yup, you should be able to. Just have to make sure you load the animations into the image/sprite like in that example. Then call setFrame(…) with the index or key of the frame you want to change to.

1 Like

I use like sprite.setFrame(3).but it doesn’t make any changes.it still in frame one.

Try passing in the name of the frame instead of the index. So the key it uses in the atlas.

1 Like

Thanks sturb,can you give me any example using name?

Sure. In that link I posted, you can replace the four this.add.sprite(..) lines with this.add.sprite(400, 100, 'gems').setFrame("prism_0001");.

1 Like

it works,thanks sturb

1 Like