Skip to main content
Known Participant
August 21, 2013
Answered

XoniX Game wall coloring problem

  • August 21, 2013
  • 1 reply
  • 2255 views

Hello,

I'm working at the XoniX game at the moment

the idea of the game is simple multiple enemies are moving in the room , you have to build the walls to make their room smaller

the actual problem is that I want to fill the color when the wall is built

I have made this so far

https://appswithssl.com/xonix/

here you can move the player with w,a,s,d and if you go from one wall to another the shape is drawn

This topic has been closed for replies.
Correct answer kglad

but there is still left something I must find a shortest way, which is a little bit difficult to figure out.

if i choose the wrong polygon I will fill allready filled one too


you don't need to find the shortest way.  you just need to find one interior point of the quad and then use the bitmapdata's floodfill method.  actually, you don't even need to find which sprites constitute the quad.  you can create a bitmap of them all and use floodfill and the point(s) that are interior.

1 reply

kglad
Community Expert
Community Expert
August 21, 2013

in general, what you want to do is difficult. 

first, you have to determine whether you have a closed polygon.  then you have to determine which points are inside and which points are outside the polygon.

Known Participant
August 21, 2013

thank you for the answer,

i have already an algorithm about a closed polygon, the problem is deteoning points, which are inside the polygon and another which are the edges of a polygon.

Known Participant
August 24, 2013

you don't need to do that.  you just need to determine which sprites/lines constitute part of your polygon.  you can then use the bitmapdata class to draw a new bitmap of that filled polygon.  you can then add that filled polygon to your display (under your lines).

determining those sprites should be straight-forward (at least using brute force).  in general this could be wildly unwieldly and inpractical, but in a flash app with a very limited number of lines this should not be unworkable.

when you have a positive hittest, you have the start and end sprites/lines.  the start sprite has a positive hittest with, at least, one other sprite (that's not the end sprite).  save those (potential 2nd leg of the polygon) sprites.  each of those has a positive hittest with, at least, 1 other sprite that's not the start sprite.  save those (potential 3rd leg of the polygon) sprites. etc until one of the potential legs has a positive hittest with the end sprite.


thank you sooo much, that should solve my problem