OttoRobba Posted January 9, 2015 Share Posted January 9, 2015 EDIT: Solved! Apparently it is a limitation with calling setScene in the init function of a scene. Working around this with a timer that calls a function that changes scene I was playing around with scene management and I noticed something weird: only the 'Main' scene automatically updates objects that use game.scene.addObject I'm probably doing something wrong but here is my code:game.module('game.main').require('game.assets', 'game.loader', 'game.entities.player').body(function() { game.createScene('Main', { backgroundColor: 0x000000, init: function() { game.system.setScene('Play'); } }); game.createScene('Play', { init: function() { this.player = new game.Player(game.system.width / 2, game.system.height / 2); this.player2 = new game.Player(game.system.width / 8, game.system.height / 2); } });});//player.jsgame.module('game.entities.player').body(function() { game.createClass('Player', { init: function(x, y) { this.sprite = new game.Sprite('player.png'); this.sprite.addTo(game.scene.stage); this.sprite.position.set(x, y); this.sprite.anchor.set(0.5, 0.5); game.scene.addObject(this); }, update: function() { this.sprite.position.x += 1; } }); });When I transfer the code in the 'Play' scene back to main, the sprites move normally. Where did I bork it up? EDIT: Solved! Apparently it is a limitation with calling setScene in the init function of a scene. Working around this with a timer that calls a function that changes scene Quote Link to comment Share on other sites More sharing options...
enpu Posted January 9, 2015 Share Posted January 9, 2015 Yeah you should not change scene right in scene's init function. Why would you wanna do that? Quote Link to comment Share on other sites More sharing options...
OttoRobba Posted January 9, 2015 Author Share Posted January 9, 2015 Yeah you should not change scene right in scene's init function. Why would you wanna do that? It was for a template so that the scene chain would already be in place. Good thing to be aware of this though Quote Link to comment Share on other sites More sharing options...
enpu Posted January 9, 2015 Share Posted January 9, 2015 You can change the start scene from config file:system: { startScene: 'MyScene'} OttoRobba 1 Quote Link to comment Share on other sites More sharing options...
OttoRobba Posted January 9, 2015 Author Share Posted January 9, 2015 Hmm that is nice to know, thanks Enpu Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.