Jump to content

Non-Main scenes don't update objects


OttoRobba
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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