Checks to see whether a given point falls within the defined polygon area.
Define a polygonal area. It's just an array of coordinates, like:
array[0] = 10; // vertex 1 x
array[1] = 20; // vertex 1 y
array[3] = 50; // vertex 2 x
array[4] = 30; // vertex 2 y
...
etc
you can use script poly_create
for it, like:
poly = poly_create(10,20,50,30,80,70);
or use GMS2 syntax:
poly = [10,20,50,30,80,70];
or use poly_create_from_path(path)
When using this function, it's will work out whether the given point falls within it's bounds or not. If the point falls within the defined polygon the function will return true otherwise the function will return false.
It's uses ray casting algorithm.
Functions:
I use Tiled map editor to create polygons (see screenshot)
End User Licence Agreement (EULA).
Some refactoring made: JSDoc style comments; Removed some functions, like array_create_from_string (because GMS already has no limits for argument count); Functions was renamed (sorry if this breaks your old code). New names: poly_draw()
, poly_shift()
, poly_create()
, poly_create_from_path()
.
Some refactoring made: Removed some functions, like array_create_from_string (because GMS already has no limits for argument count); Functions was renamed (sorry if this breaks your old code). New names: poly_draw()
, poly_shift()
, poly_create()
, poly_create_from_path()
.