Jump to content

Collision detection on dynamic generated objects.


Terumi
 Share

Recommended Posts

Hello all, 

 

I'm trying to make a "game" in which you drag sticks from a pool and you position them on the screen.

(I'm basicaly creating a cuisenaire program).

 

The sticks have to be restrained in the underneath tilemap and also cannot overlap with each other.

 

Every stick has a 
sprite.input.enableDrag();
sprite.input.enableSnap(30, 30, true, true);

 

So it can be draggable.

 

Also, I whenever the user drags a stick from the pool, I clone a stick there so he can drag another one later on.

 

How can I instruct phaser to watch for collisions between all sticks?

If I put them on a group, I loose the input.enableDrag on every stick.

If I don't have them on a group, how can I reference them to watch for collisions with each other?

 

Thank you

Link to comment
Share on other sites

Easy solution I can think of is to put sticks in an array and then loop over the array for collision check in the update() function. Be careful to remove killed or unused objects from array (as Phaser won't handle it).

 

It's a shame not to use groups though : are you sure the inputs won't work if you do so?

 

Performance-wise it shouldn't change anything, I'm pretty sure in the end Phaser.groups are iterated over for collision checks.

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