Jump to content

Group Distance Check

Recommended Posts

Hei Phaser-Folks,


finally I had to register and now I really would like starting asking questions ;)


I've been playing around with Phaser for like a month and came to a point today where I could need some help.


Here is the problem:

I have a checker board and two different groups of figures (let's say black and white).

Now I want to check if any of those figures is surrounded by four other figures of the other group, like one black is surrounded by one white (left, right, up and down).

Since I have them in a group I cannot do a simple distance check like if white.x - black.x < x1 do...

I thought it is possible to use collision handlers using the "touching" property, but that does not work either. I can only check if they collide but not how many of those collide with one of the other group.


So I don't know how to go on now and would appreciate any hint.


Thanks in advance



Link to post
Share on other sites

Hi Richard,


I thought of the idea of having the whole game stored in an array and do the whole math on that array just showing the graphics as a visual representation... but I'm not sure if this is such a good idea. I would have to loop every update-cycle through the whole array and check if there is something near to my figures.


I've figured out another way: I am looping through all living black figures, calling another loop in each black figure on each living white figure. Then I can check if it is within a specific circle that has its center in the center of the black figure. Thus I can check for 4-neighboring or by expanding the circle for 8-neighboring white figures. Another advantage of this method is that I could also translate the current idea from the raster approach to a non-raster approach and it would still work.


Thank you.



Link to post
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.

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.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...