Jump to content

anims and scenes


giorg
 Share

Recommended Posts

Hi,

I have 3 scenes, with different animations inside the create() of each one. When I do the launch of the second scene from the first one, all is ok, but when I try to launch 3rd scene, in console I get:

Invalid Animation Key, or Key already in use

for each of the animation of that scene, as if they were already created, then the 3rd scene is not working. Also I might need to start the same scene again, how to achieve this?

thanks

Link to comment
Share on other sites

Animations are stored global, not just for a specific Scene, hence the error with the key.

I would recommend creating the animations up front, as part of your preload process if possible, then each Scene can use them whenever they like.

If you can't do that for some reason, check to see if the animation already exists and if so, skip creating it again when you return to a Scene.

Link to comment
Share on other sites

hey rich,

thanks for your answer. I'm trying to create the animations in the preload function of my Boot scene, where I load all the assets. But when I do:

this.anims.create({
            key: 'cassa0',
            frames: this.anims.generateFrameNames('cassa_attesa', {
                start: 0,
                end: 59,
                prefix: 's4b2cassaattesa_',
                zeroPad: 4
            }),
            repeat: -1,
        });

in there (ofc before I do this.load.multiatlas('cassa_attesa', 'cassa_attesa.json'); which works), when I enter my scene I try this.add.sprite(510, 450).play('cassa0'); but I get

TypeError: Cannot read property 'frame' of undefined.

so I don't know how to access the animation...

thanks for any help

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...