Jump to content

Collide problem?


traiq11alone
 Share

Recommended Posts

Hi guys, somebody can please tell me how collide, push sprite go, tileSprite too. Read examples, find some solutions but i dont know whats wrong with my code:

 

function preload(){
    game.load.image('block1', 'block1.png');
    game.load.image('block2', 'block2.png');
}
function create() {
    game.physics.startSystem(Phaser.Physics.ARCADE);
    game.stage.backgroundColor = '#ECF0DD';
    block1 = game.add.sprite(500, 300, 'block1');
    game.physics.arcade.enable(block1);
    block1.body.allowCollision = true;
    block2 = game.add.sprite(700, 300, 'block2');
    game.physics.arcade.enable(block2);
    block2.body.allowCollision = true;
}

function update() {
        game.physics.arcade.collide(block1, block2);
        if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
            block1.body.x += 5;
        } else if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
            block1.body.x -= 5;
        } else if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
            block1.body.y -= 5;
        } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
            block1.body.y += 5;
        }
}

var game = new Phaser.Game(900, 500, Phaser.CANVAS, 'game', {preload:preload, create:create,update:update});

 

3YCk9qe.png

 

Its just go through, dont collide at all. Can you please tell me how to collide left, right side too?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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