  # Point in polygon

#### Dmi7ry

You must be logged in to obtain assets

### Description

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 = 10; // vertex 1 x
array = 20; // vertex 1 y
array = 50; // vertex 2 x
array = 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:

• point_in_poly(point_x, point_y, poly)
• poly_draw(poly)
• poly_shift(poly)
• poly_create(value1, value2, ...)
• poly_create_from_path(path, [counter])
• I use Tiled map editor to create polygons (see screenshot)

### Versions

#### GMS2 - Version 1.2.0. Published April 24, 2017

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()`.

#### GMS1 - Version 1.2.0. Published April 24, 2017

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()`.