Jump to content

Multiple scenes and animations, "Key already in use" when restarting a scene


BdR
 Share

Recommended Posts

I'm working on a Phaser3 game with mulitple scenes, a mainmenu, a instructions scene and a maingame scene for the actual game.

During the game I need an animation, so in the preload of the gamescene I do this

    preload: function ()
    {
		// create coin animation
		this.anims.create({
				key: 'cointurn',
				frames: [
					{ key: 'sprites', frame: 'coin1' },
					{ key: 'sprites', frame: 'coin2' },
					{ key: 'sprites', frame: 'coin3' },
					{ key: 'sprites', frame: 'coin4' },
					{ key: 'sprites', frame: 'coin5' },
					{ key: 'sprites', frame: 'coin6' },
					{ key: 'sprites', frame: 'coin7' },
					{ key: 'sprites', frame: 'coin8' }
				],
				frameRate: 15,
				repeat: -1 // endless
			});
    },


Ok this all works fine and the animation shows. Then, when the game is over it goes back to the menuscene to allow player to select another level, and then start the gamescene again to play another level.

However, when I restart the gamescene again I get this warning;

Quote

Invalid Animation Key, or Key already in use: cointurn

Evidently the preload of the gamescene is fired again, and everything loaded and created in that .preload() method is done again.

So my question is:
Where or when should I add the animations that only have to create once? So animations (and maybe other things?) that will be used throughout the entire session of the game.

Link to comment
Share on other sites

Ive not done it myself, but I saw Rich say that  he has a dedicated 'preload' scene, where he puts things like animations. so put all the animations into the preload scene and then run that scene at boot and when you reset other scenes the animations wont get touched. 

 

I found this, maybe it could be of help:

https://gamedevacademy.org/creating-a-preloading-screen-in-phaser-3/?a=13

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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