Phempt Posted October 21, 2014 Share Posted October 21, 2014 This is the working code:game.module('game.main').require('game.assets').body(function() {game.createScene('Main', { backgroundColor: 0x000000, init: function() { this.terrain = new game.Sprite("world/terrain.png"); this.terrain.position.set(0, game.system.height - this.terrain.height); this.terrain.interactive = true; this.stage.addChild(this.terrain); this.terrain.touchstart = this.terrain.click = function(){ game.system.setScene("Game"); } },});game.createScene('Game', { backgroundColor: 0x000000, birdsArray: [], init: function(){ /* WORLD & CONTAINERS */ this.world = new game.World(0, 9); this.world.ratio = 1; /* CONTAINER */ this.bgContainer = new game.Container(); this.bgContainer.addTo(this.stage); this.topBar = new game.Container(); this.topBar.addTo(this.stage); /* CLOUDS */ this.addParallax(0, 'world/clouds.png', -35); /* ADD BG IMAGES AND WORLD IMAGES */ this.citybg = new game.Sprite("world/backCity.png"); this.addParallax(game.system.height - this.citybg.height, 'world/backCity.png', 5); this.terrain = new game.Sprite("world/terrain.png"); this.addParallax(game.system.height - this.terrain.height, 'world/terrain.png', 25); /* TUBES SPAWN */ this.birdsGenerator(); }, birdsGenerator: function() { console.log('spawn'); this.addTimer(1000, this.birdsGenerator.bind(this)); }, addParallax: function(y, path, speed) { var parallax = new game.TilingSprite(path); parallax.position.y = y; parallax.speed.x = speed; parallax.addTo(this.bgContainer); this.addObject(parallax); } });});but if in the main scene I change the init function simply with:init: function() { game.system.setScene("Game"); },the game scene doesn't work properly, for example the function parallax is not working as expected (no movement). Quote Link to comment Share on other sites More sharing options...
ambidex Posted October 22, 2014 Share Posted October 22, 2014 Not entirely sure why you can't use the game.system.setScene() in init, but I think it's a known limitation. Though, if you'd like to start with a different scene, I'd suggest you use the startscene property (http://www.pandajs.net/docs/classes/game.System.html#attr_startScene) in your config.js. Using an entire scene to only initiate some variables / objects / etc... sounds like bad practice anyway. Quote Link to comment Share on other sites More sharing options...
Phempt Posted October 22, 2014 Author Share Posted October 22, 2014 Yesterday I lost 2 hours for this thing XD (When I start a new game typically I'll start from the game Scene using the "Main" one, but yesterday I tried a different way discovering this "bug/limitation".) 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.