WayDeterminer

WayDeterminer

A Class for pixel level collision detection.


Constructor

new WayDeterminer(transparencyColoropt, canvasObject, arrayOfCanvasObjectsopt)

Parameters:
Name Type Attributes Default Description
transparencyColor Number <optional>
0

The pixel color value denoting clear, default is 0.

canvasObject CanvasObject

the CanvasObject to use during wayIsClear calls.

arrayOfCanvasObjects Array <optional>

optional array of CanvasObjects to use during multipleWaysClear and multipleWaysClearAndRegister

Members

(static) bitmapData :CanvasObject

The CanvasObject to use during wayIsClear calls. Whatever CanvasObject is set during construction overrules this value, but this value is not a reference to what was set during construction.

Type:

(static) transColor :Number

The pixel color value denoting clear pixels, default is 0.

Type:
  • Number

_bmdRef

Set during construction to the CanvasObject you pass.

_lastBitmapHit

Set during multipleWaysClearAndRegister

constructor

multipleBitmapDatas

Set during construction.

Methods

multipleWaysClear(x, y, bitmapDatas) → {Boolean}

Returns true if the pixel color value in each CanvasObject in the bitmapDatas Array matchs WayDeterminer.transColor or 0.

Parameters:
Name Type Description
x Number

The x location to check

y Number

The y location to check

bitmapDatas Array

Array of CanvasObjects to check, if not set the multipleBitmapDatas property will be used.

Returns:
Type
Boolean

multipleWaysClearAndRegister(x, y, bitmapDatas) → {Boolean}

Checks the x y position on each CanvasObject in the bitmapDatas Array. Returns true if the pixel color value in each CanvasObject matches WayDeterminer.transColor at the given x y location. If the way is not clear this method sets _lastBitmapHit to the CanvasObject that was not clear at the location.

Parameters:
Name Type Description
x Number

The x location to check

y Number

The y location to check

bitmapDatas Array

Array of CanvasObjects, if not set the multipleBitmapDatas property will be used.

Returns:
Type
Boolean

wayIsClear(x, y) → {Boolean}

Returns true if the pixel color value in _bmdRef or WayDeterminer.bitmapData at the x y location given matches WayDeterminer.transColor or 0.

Parameters:
Name Type Description
x Number

The x location to check

y Number

The y location to check

Returns:
Type
Boolean