Shape

A generic shape. The base for all other shapes.

Constructor

new Shape(type, xopt, yopt)

Parameters:
NameTypeAttributesDefaultDescription
typestring

The shape type

xnumber<optional>
0

The x position

ynumber<optional>
0

The y position

Members

copy

Create a copy of the shape

fillColor :String

The fill color when this shape is drawn

Type:
  • String

position :gameify.Vector2d

The position of the shape, often locked to the position of a sprite that it represents

strokeColor :String

The stroke color when this shape is drawn

Type:
  • String

(readonly) type :String

A string represeting the type of shape, eg "Circle"

Type:
  • String

Methods

(abstract) collidesWith(obj, recursionopt) → {Boolean}

Check if this shape collides with another shape

Parameters:
NameTypeAttributesDefaultDescription
objshapes.Shape

The object to check for collision

recursionBoolean<optional>
false

If this is a recursive call

Returns:
Type: 
Boolean

(abstract) contains(point) → {Boolean}

Check if a point (Vector2d) is inside this shape

Parameters:
NameTypeDescription
pointgameify.Vector2d

The point to check

Returns:
Type: 
Boolean

(abstract) draw(context)

Draw a hitbox for debugging

Parameters:
NameTypeDescription
contextCanvasRenderingContext2D

The rendering context to draw to

fromJSON(data) → {gameify.Tileset}

Creates a object from JSON data

Parameters:
NameTypeDescription
dataObject | Array

Serialized object data (from object.toJSON)

Returns:
Type: 
gameify.Tileset

rotated(angle, pointopt) → {gameify.shapes.Shape}

Create a copy of this shape, rotated around a point, in radians (counterclockwise)

Parameters:
NameTypeAttributesDefaultDescription
angleNumber

The angle to rotate by, in radians

pointgameify.Vector2d<optional>
<0, 0>

The point to rotate around

Returns:
Type: 
gameify.shapes.Shape

scaled(scale) → {gameify.shapes.Shape}

Create a copy of this shape, scaled by a factor.

Parameters:
NameTypeDescription
scaleNumber

The scale factor

Returns:
Type: 
gameify.shapes.Shape

toJSON()

Convert the object to JSON. Not available on the base Shape, only on inherited classes