Jirka1111

game.rnd.pick sometimes generate wrong number

Recommended Posts

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.

 

post-9946-0-67773000-1414344370_thumb.pn

 

post-9946-0-45991800-1414344372_thumb.pn

 

post-9946-0-63388400-1414344374_thumb.pn

 

post-9946-0-42007400-1414344376_thumb.pn

    

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.