Jump to content

Arcarde Physics - Collision between Group and Tilemap


Chupup Games
 Share

Recommended Posts

Hi, I need some help.

 

I want to test the collision between a group and a tilemap.

 this.physics.arcade.collide(this.fireball, this.layer, this.killFireball); 

My function killFireball never gets called...

 

 

First I activate the physics:

 this.physics.startSystem(Phaser.Physics.ARCADE);

Then I create the tilemap like this:

var map = this.add.tilemap('playfield', 32, 32);        map.addTilesetImage('tiles');        map.setCollision(0);        this.layer = map.createLayer(0);        this.layer.resizeWorld(); 

and my group:

this.fireball = this.add.group();        this.fireball.enableBody = true;        this.fireball.physicsBodyType = Phaser.Physics.ARCADE; 

I got a bit lost here. I tried to research how to do this, but in the forum and the examples i didn't find anything that could help me.

Link to comment
Share on other sites

Can you provide a link to a working demo of this problem?

 

I've had trouble in the past where I was sending a null into the collision function when I thought I was sending a sprite instance. Phaser silently returns in that case (IMO that's the right thing to do, just caught me by surprise the first time). I'm wondering if that's happening here..?

 

Another thing to try is use the un-minified version of phaser.js and set a breakpoint on the collide function to see what's happening.

Link to comment
Share on other sites

i tried with null, this but still it doesn't wanna work.  :(

 

here is my create & update function:

Fireball.Game.prototype = {    create: function () {        this.physics.startSystem(Phaser.Physics.ARCADE);        this.add.sprite(0, 0, 'background');        var map = this.add.tilemap('playfield', 32, 32);        map.addTilesetImage('tiles');                this.layer = map.createLayer(0);        this.layer.resizeWorld();        map.setCollision(0);        this.player1 = this.add.sprite(200, 375, 'player', 0);        this.player1.animations.add('jump', [0, 3]);        this.player1.animations.play('jump', 5, true);        this.fireball1 = this.add.group();        this.fireball1.enableBody = true;        this.fireball1.physicsBodyType = Phaser.Physics.ARCADE;        this.fireball2 = this.add.group();        this.fireball2.enableBody = true;        this.fireball2.physicsBodyType = Phaser.Physics.ARCADE;        this.fireball3 = this.add.group();        this.fireball3.enableBody = true;        this.fireball3.physicsBodyType = Phaser.Physics.ARCADE;        this.fireball4 = this.add.group();        this.fireball4.enableBody = true;        this.fireball4.physicsBodyType = Phaser.Physics.ARCADE;        this.time.events.loop(Phaser.Timer.SECOND * 3, this.createFireball, this);    },    update: function () {        this.physics.arcade.collide(this.fireball1, this.layer, this.killFireball, null, this);        this.physics.arcade.collide(this.fireball2, this.layer, this.killFireball, null, this);        this.physics.arcade.collide(this.fireball3, this.layer, this.killFireball, null, this);        this.physics.arcade.collide(this.fireball4, this.layer, this.killFireball, null, this);    },    createFireball: function () {        this.fireball1.create(44, 70, 'fireball', 0, true);        this.fireball1.setAll('body.velocity.y', 60);        this.fireball2.create(39, 396, 'fireball', 0, true);        this.fireball2.setAll('body.velocity.x', 60);        this.fireball3.create(268, 403, 'fireball', 0, true);        this.fireball3.setAll('body.velocity.y', -60);        this.fireball4.create(275, 77, 'fireball', 0, true);        this.fireball4.setAll('body.velocity.x', -60);    },    killFireball: function () {        console.log('bang');    },
Link to comment
Share on other sites

Ok... Let's do a bit of debug:

Fireball.Game.prototype = {    create: function () {        this.physics.startSystem(Phaser.Physics.ARCADE);        this.add.sprite(0, 0, 'background');        var map = this.add.tilemap('playfield', 32, 32);        map.addTilesetImage('tiles');        map.setCollision(0);                this.layer = map.createLayer(0);        this.layer.resizeWorld();        this.layer.debug = true;        this.player1 = this.add.sprite(200, 375, 'player', 0);        this.player1.animations.add('jump', [0, 3]);        this.player1.animations.play('jump', 5, true);        this.fireball = this.add.sprite(44, 70, 'fireball', 0, true);        this.fireball.body.velocity.y = 60;        this.game.physics.arcade.enableBody(this.fireball);                this.time.events.loop(Phaser.Timer.SECOND * 3, this.createFireball, this);    },    update: function () {        this.physics.arcade.collide(this.fireball, this.layer, this.killFireball, null, this);    },    createFireball: function () {        this.fireball = this.game.add.sprite(44, 70, 'fireball', 0);        this.fireball.body.velocity.y = 60;    },    killFireball: function () {        console.log('bang');    },

We're going to turn on debug bodies for the tile map so that you can see where collisions are, and we're going to just create one fireball every 3 seconds.

 

We're also just checking collision against that one fireball. 

 

What happens?

Link to comment
Share on other sites

i changed for this now:

this.fireball1 = this.add.sprite(44, 70, 'fireball', 0);                this.game.physics.arcade.enableBody(this.fireball1);        this.fireball1.body.velocity.y = 60;

and check collision:

this.physics.arcade.collide(this.fireball1, this.layer, this.killFireball, null, this);

still no luck..., no collision detected. i think there is something missing. sad that don't have one example with arcarde, tilemaps and groups  from rich

Link to comment
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...
 Share

  • Recently Browsing   0 members

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