Jump to content

Phaser.Physics.Arcade.overlap() working but collide() not?


koko
 Share

Recommended Posts

Hi, this is my first post and probably a newbie mistake,

I'm trying to get collisions working between two objects. What I have is overlap() works but collide() doesn't. All being equal when I substitute overlap for collide in code below the collision is no longer detected. Any thoughts on why it may be so? 

First I setup the engine: 

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

Then set up the objects:

this.platform = this.game.add.sprite(471, 535, null);
game.physics.enable(this.platform, Phaser.Physics.ARCADE);
this.platform.body.immovable = true;
this.platform.body.setSize(200,10, 0,0);

and this:

this.cube = game.add.sprite(x, y - 30, 'characters', 'cube1');
this.cube.anchor.setTo(0.5, 0.5);
game.physics.enable(this.cube, Phaser.Physics.ARCADE);  

And in the update() collide/overlap them like that:

game.physics.arcade.overlap(this.platform, this.cube, function (platform, cube) {
    this.unloadCube();
	game.paused = true;
}, null, this);

This is just part of the code. For what it's worth, cube is in a group and is moved with it's parent. The platform is on the root level. 

 

Link to comment
Share on other sites

One is moving the other is static. But the moving one is attached to a group and I move the group by x and y. Now from the other thread I learned  that I need to move the bodies with velocity in order for collisions to make any sense, so moving a group makes no sense probably and I need to use a sprite with children? 

Link to comment
Share on other sites

Well, I'm quite new to phaser so I don't know all the options yet and group was the first ting I found. As I wrote elsewhere, I have a character carrying an object and I need to check if the object is put on a surface. For now I use overlap for that but for what I know it doesn't support directions so I have to manually check if it's ON and not UNDER or BESIDE the table surface. So basically my question is what's a best way to satisfy these assumptions?

  • The collided object is carried around with a sprite which shouldn't collide 
  • The object should collide with another (immovable) object
  • I want to know the direction of the collision (ie. the side of immovable object that was hit)
Link to comment
Share on other sites

In Arcade physics, the bodies have a property called "touching". "body.touching.down" means the body collided on the bottom. Would that work? There's another property, "blocked", for when the body collides with the world boundaries or a tile.

You might end up having two separate sprites whose positions you keep in sync manually, instead of making one of them a child? Or, you could make them both children but then check each of them directly instead of the parent?

Link to comment
Share on other sites

There are slight rotations involved so I'd rather put them in one container. Yeah, I'd check each directly as I do now, I only wonder if they inherit parent's velocity which is needed for collisions? I'll test that, thanks anyway!

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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