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.

kglad
Community Expert
Community Expert
August 22, 2013

this is just a simple thing,

at first I am checking if the player isn't on a wall and if true I start tracking it's movement,

each time it changes the direction  I store the position of a point where the direction was changed in an array , untill the player intersects or hits the wall

i detect a hit/intersection and begin to draw the lines using the points I stored and than I store all the new walls in a wall array and it works pretty well

only problem I have is filling the shapes with a color

the whole game so far is here

https://appswithssl.com/xonix/xonix.zip

p.s. sorry for the controls it is with arrow keys and not with wasd


are you creating a new sprite each time you change direction and use that sprite's graphics property to draw the line and then use those sprites in your hittest?  if so, you determine which sprites constitiute your polygon, use the bitmapdata draw method to create a bitmap of your polygon and then fill that bitmap.