Jump to content

Overlap doesn't always works ?


robomatix
 Share

Recommended Posts

Hello,

 

For a game I'm building, I generates squares but I don't want them to overlap...

I wrote this code, but i doesnt always works...

,    generateSquares: function () {        var x, y, squareScale, square;        x = this.game.rnd.integerInRange(50, this.game.world.width - 50);        y = this.game.rnd.integerInRange(50, this.game.world.height - 50);        squareScale = this.game.rnd.integerInRange( 1, 4 );        square = new Square(this.game, x, y);        square.scale.setTo(squareScale);        this.game.physics.enable([square], Phaser.Physics.ARCADE);        if (!this.game.physics.arcade.overlap(square, this.simon)) {            this.simon.add(square);            console.log('NO overlap');            this.squaresCount++;        } else {            console.log('OOOOOverlap');            square.tint=0xff0000;            square.destroyThis();        }        console.log(this.squaresCount);        if(this.squaresCount === 18){// We want 18 squares            this.squaresGenerator.timer.stop();        }    }

Here is an example : http://le-carre-noir.net/repetita-test/. Clip anywhere to launche the generation of squares... ( You can see some stuff on the javascript console ) 

Here is the repository : https://github.com/robomatix/repetita

 

Any help ?

 

Thank you

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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