Jump to content

"Phaser.Arcade" Collision


Zackorz
 Share

Recommended Posts

Im sorry for opening a new thread, but my old is kind of messy and i really, really need some help fast. I need to finish a prototype for presenting a project but cant figure out how i get my collision detection to work.

Here is an example how i programmed my code.

Create:

cloud1 = this.add.sprite(this.world.centerX, this.world.centerY/1.5, "cloud");
wolke2 = this.add.sprite(this.world.centerX, this.world.centerY/1.5, "cloud");

this.physics.startSystem(Phaser.Physics.ARCADE);
this.physics.enable(cloud1, Phaser.Physics.ARCADE);
this.physics.enable(cloud2, Phaser.Physics.ARCADE);

 

Update:

console.log(this.physics.arcade.collide(cloud1, cloud2));

 

I also get "false" as a result of my collision. What is missing? I love phaser, but the never had half of the trouble with collision detection in any other framework..

Link to comment
Share on other sites

Just a heads-up, when you're adding the sprites, you're adding 'cloud1' and 'wolke2', but you're checking collisions on cloud1 and cloud2. I'm not sure if that's just you translating the code for this post, but if that's how it is in your actual code then that'll be your problem.

Link to comment
Share on other sites

8 hours ago, shohan4556 said:

If  in the game world the two object is not colliding then its shows false if collide then its true.

check the in the game world the two objects is colliding then its will result true.

Didnt i checked for that?  I placed the sprites on the same position, and checked for a collision. But i always get "false" (and they should collide all the time when they at the same position).

 

i also tried :

this.physics.arcade.collide(cloud6, cloud5, collisionHandler, null, this);

function collisionHandler()

{
console.log("collision detected");
}

But its always "false" and the collisionHandler never fires.

Do i have to write it in another notation?

 

1 hour ago, SignalSin said:

Just a heads-up, when you're adding the sprites, you're adding 'cloud1' and 'wolke2', but you're checking collisions on cloud1 and cloud2. I'm not sure if that's just you translating the code for this post, but if that's how it is in your actual code then that'll be your problem.

Thanks for informing me about that, but its correct in game, I just translated it for this forum and forgot to translate everything.

Link to comment
Share on other sites

I tried it with "overlap" instead of "collision" now and it works. I dont get it why "collision" doesnt..

what is the difference between this two and why is only "overlap" working?:

this.physics.arcade.collide(bird, cloud, collisionHandler, null, this); // not working
this.physics.arcade.overlap(bird, cloud, collisionHandler, null, this); // working



function collisionHandler (obj1, obj2)
{
 console.log("collision detected");
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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