BdR Posted July 20, 2018 Share Posted July 20, 2018 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 More sharing options...
NoxBrutalis Posted July 20, 2018 Share Posted July 20, 2018 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 dabe_glavins 1 Link to comment Share on other sites More sharing options...
rich Posted July 20, 2018 Share Posted July 20, 2018 Yeah, I nearly always have a Preload Scene, that includes a loading image, progress bar, etc and it loads most the game assets and creates the animations. Once complete the game never returns to it ever again. Link to comment Share on other sites More sharing options...
Recommended Posts