Jirka1111 Posted October 26, 2014 Share Posted October 26, 2014 In update function: platformsCreate: function() { // platform basic setup this.platforms = this.add.group(); this.platforms.enableBody = true; this.platforms.createMultiple( 10, 'pixel' ); // create the base platform, with buffer on either side so that the hero doesn't fall through// this.platformsCreateOne( -16, this.world.height - 16, this.world.width + 16 ); // create a batch of platforms that start to move up the level for( var i = 0; i < 9; i++ ) { this.platformsCreateOne( this.platformsPosition(), this.world.height - 150 - 150 * i, 50 ); } }platformsPosition: platformsPosition: function(){ return Phaser.Math.getRandom([56, 127, 198, 269, 340, 411]); },Other methods:platformsCreate: function() { // platform basic setup this.platforms = this.add.group(); this.platforms.enableBody = true; this.platforms.createMultiple( 10, 'pixel' ); // create the base platform, with buffer on either side so that the hero doesn't fall through// this.platformsCreateOne( -16, this.world.height - 16, this.world.width + 16 ); // create a batch of platforms that start to move up the level for( var i = 0; i < 9; i++ ) { this.platformsCreateOne( this.rnd.integerInRange( 0, this.world.width - 50 ), this.world.height - 150 - 150 * i, 50 ); } }, platformsCreateOne: function( x, y, width ) { // this is a helper function since writing all of this out can get verbose elsewhere var platform = this.platforms.getFirstDead(); platform.reset( x, y ); platform.scale.x = width; platform.scale.y = 16; platform.body.immovable = false; return platform; }, I had to generate platforms in some predefined x coordinates. But sometimes the platform just won't shows up. Link to comment Share on other sites More sharing options...
Jirka1111 Posted October 30, 2014 Author Share Posted October 30, 2014 Nobody? Link to comment Share on other sites More sharing options...
jpdev Posted November 4, 2014 Share Posted November 4, 2014 Seems to me (in the 2.1.3. phaser version at least) that it never picks a wrong number: http://jsfiddle.net/jppresents/m4b438bf/1/ You can go as high as you like with the amount of checks or run it as often as you like, I could not get it to return a number that's not in the array of numbers to pick from. Link to comment Share on other sites More sharing options...
tsphillips Posted November 5, 2014 Share Posted November 5, 2014 Try putting a debug print (like console.log()) in platformsCreateOne() to see where all the x,y coordinates are. Then work backwards from there. Also, check your assumptions for this.world.width and this.world.height (with another debug print) to make sure everything is as you expect. And just in case...Try putting an assert, debug print, or similar after this line to make sure nothing surprising is happening:var platform = this.platforms.getFirstDead(); Tom Link to comment Share on other sites More sharing options...
Recommended Posts