Jump to content

"trigger" Collision in Phaser


Ido
 Share

Recommended Posts

Hi,
I'm new to Phaser, so this may be very simple...
Is there a way to define 2 objects that when they collide they don't bounce of eachother but go straight through?
e.g. in a top-down game when the character steps into a "hole".
I'd like to have my callback invoked but the character and hole sprites have to overlap...
Thanks!

Link to comment
Share on other sites

Sorry, I don't understand what you are asking about.

Overlap and collide work basically the same way, if you check the phaser you will find that they invoke the same functions, they differ in one parameter which is false for collide and true for overlap which results in a slightly different result but that's all.

When you use collide in update it is called every update unless you put some condition above it so I don't see what exactly you have a problem with.

If you need one object to overlap with the other one then just call overlap and do your stuff.

If you are using collide then you probably have something like this: physics.collide(obj1, obj2, //some other stuff) in your update function so if you need overlap instead of collision (which triggers only when they collide and then basically nothing) use: physics,overlap(obj1, obj2, //some other stuff). When you check for collisions you usually do it every update call too unless you have some other code that decides if you need to check the collision - but that is basically part of collision functionality in general too.

If you have any other conditions you can put them above that but you don't provide any more details about that so I can't help you with it.

 

PS: What do you mean by "call method just once and it will check this all the time"? How can you call something once and then do it al lthe time? The only thing I can come up with is a function with infinite loop which will kill the game.

Link to comment
Share on other sites

I saw in this example:
http://phaser.io/examples/v2/p2-physics/collision-groups

That they set the collision parameters in the create method, and then I guess that Phaser checks collisions by itself all the time.

As far as I understand, I should call the "Overlap" method every time I want to check if there is an overlap. I'd like it to work "automatically'...

Link to comment
Share on other sites

Hi again,

first of all I'd advise you to start with more details for example that you are using P2 physics ;-).

In your example they just set collisoin groups but the collision itself is undoubtly called all the time as well, it's the engine that takes care of it. You can imagine it the way that they turn collision ON for the groups and the call in update method is not written explicitly but is hidden in the engine somewhere - thus implicitly it's still in there.

Link to comment
Share on other sites

I know, I was hoping that there was some method for findingoverlaps that the engine calls instead of me...
Because if there isn't, I'll need to use this method MYSELF on all the pairs of sprites that I have in order to detect all the overlaps and this just sucks. :) 

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...