Jump to content

2D collision leads to overlap


caramucho
 Share

Recommended Posts

Hi,

I'm new to phaser and I have a problem with collision in a simple 2D game

I have sprite falling one on the over.

But after the 7th boxe dropped, fallen boxes overlap one over one.

It's certainly a physics issue regarding weight and gravity (and a limit with dealing compression of sprites in a limited area).

But I don't want this as it's a 2D game. (no over Z-axe is supposed to exist)

Do you know how to avoid this ?

Thanks by advance

Here's my code.

Best regards

var game = new Phaser.Game(1280, 720, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });

function preload() {

    game.load.image('ground', 'assets/platform.png');
    game.load.image('cube0', 'assets/cube0.png');
    game.load.image('sky', 'assets/sky_6400.png');

}

var platforms;

var cubes;

function create() {

    game.physics.startSystem(Phaser.Physics.ARCADE);
    game.add.tileSprite(0, 0, 6000, 6000, 'sky');
    game.world.setBounds(0, 0, 6000, 1440);
    game.physics.arcade.gravity.y = 90;
    
    platforms = game.add.group();
    platforms.enableBody = true;
    
    var ground = platforms.create(0, 600, 'ground');
    ground.scale.setTo(2, 2);
    ground.body.immovable = true;
    ground.body.allowGravity = false;
    
    cubes = game.add.physicsGroup(Phaser.Physics.ARCADE);
    
    for (var j = 9; j > 0; j--)
    {
        cube = cubes.create(300, j*50  , 'cube0');
    }
}

function update() {
    game.physics.arcade.collide(cubes);
    game.physics.arcade.collide(cubes, platforms);
}

    
function render() {
    game.debug.cameraInfo(game.camera, 32, 32);
}


 

  

 

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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