API Docs for: 6.0.1
Show:

window.scrawl_Collisions Class

window.scrawl

scrawlCollisions extension adaptions to the scrawl-canvas library object

New default attributes

  • Position.delta - default: {x:0,y:0,z:0};
  • Cell.fieldLabel - default: '';
  • Entity.fieldChannel - default: 'anycolor';
  • Entity.fieldTest - default: 0;
  • Entity.collisionVectors - default: [];
  • Entity.collisionPoints - default: [];

Methods

Cell.buildField

() chainable

Builds a collision map image from entitys, for use in entity field collision detection functions

Returns:

This

Cell.checkFieldAt

(
  • items
)
private

Cell field collision detection function

Argument should be in the form of:

  • {channel:String, test:Number, coordinates:Array of Vectors, x:Number, y:Number}

Where:

  • channel (optional) can be 'red', 'green', 'blue', 'alpha', or 'anycolor' (default)
  • test (optional) can be a value between 0 and 254 (default: 0)
  • coordinates (optional) is an array of Vector coordinates, in pixels, relative to the Cell's <canvas> element's top left corner
  • x (optional) is the horizontal coordinate, in pixels, relative to the Cell's top left corner
  • y (optional) is the vertical coordinate, in pixels, relative to the Cell's top left corner

Either include a single coordinate (x, y), or an array of coordinate Vectors

Test will return:

  • false if it encounters a coordinate outside the bounds of its image map
  • true if all coordinates exceed the test level (thus a entity testing in the red channel will report true if it is entirely within a red part of the collision map
  • the first coordinate that falls below, or equals, the test level

Parameters:

  • items Object

    Argument containing details of how and where to check the cell's collision map image

Returns:

Vector of first the first coordinates to 'pass' the test

Cell.checkFieldAtActions (not a function)

() private

checkFieldAt helper object

Cell.collisionsCellInit

() private

Cell constructor hook function - modified by collisions module

Entity.addEntityToCellFences

(
  • [items]
)
chainable

Add this entity to a (range of) Cell object fence groups

Parameters:

  • [items] Array optional

    Array of CELLNAME Strings; alternatively, a single CELLNAME String can be supplied

Returns:

This

Entity.addEntityToCellFields

(
  • [items]
)
chainable

Add this entity to a (range of) Cell object field groups

Parameters:

  • [items] Array optional

    Array of CELLNAME Strings; alternatively, a single CELLNAME String can be supplied

Returns:

This

Entity.buildCollisionVectors

(
  • [items]
)
private chainable

Collision detection helper function

Parses the collisionPoints array to generate coordinate Vectors representing the entity's collision points

Parameters:

  • [items] Array optional

    Array of collision point data

Returns:

This

Entity.checkField

(
  • [cell]
)

Check this entity's collision Vectors against a Cell object's collision field image to see if any of them are colliding with the Cell's field entitys

Parameters:

  • [cell] String optional

    CELLNAME String of the Cell to be checked against

Returns:

First Vector coordinate to 'pass' the Cell.checkFieldAt() function's test; true if none pass; false if the test parameters are out of bounds

Entity.collisionsEntityConstructor

() private

Entity constructor hook function - modified by collisions module

Entity.collisionsEntityRegisterInLibrary

() private

Entity.registerInLibrary hook function - modified by collisions module

Entity.collisionsEntitySet

() private

Entity.set hook function - modified by collisions module

Entity.collisionsEntitySetDelta

() private

Entity.setDelta hook function - modified by collisions module

Entity.getCollisionPoints

()

Calculate the current positions of this entity's collision Vectors, taking into account the entity's current position, roll and scale

Returns:

Array of coordinate Vectors

Entity.parseCollisionPoints

(
  • [items]
)
private chainable

Collision detection helper function

Parses user input for the collisionPoint attribute

Parameters:

  • [items] Array optional

    Array of collision point data

Returns:

This

Entity.removeEntityFromCellFences

(
  • [items]
)
chainable

Remove this entity from a (range of) Cell object fence groups

Parameters:

  • [items] Array optional

    Array of CELLNAME Strings; alternatively, a single CELLNAME String can be supplied

Returns:

This

Entity.removeEntityFromCellFields

(
  • [items]
)
chainable

Remove this entity from a (range of) Cell object field groups

Parameters:

  • [items] Array optional

    Array of CELLNAME Strings; alternatively, a single CELLNAME String can be supplied

Returns:

This

Entity.resetCollisionPoints

() chainable

Recalculate the entity's current collision point positions

This will be triggered automatically when changing the following attributes via set ort setDelta:

  • for set() - start, startX, startY, handle, handleX, handleY, scale, roll, collisionPoints, width, height, radius, pasteWidth, pasteHeight
  • for setDelta() - start, startX, startY, handle, handleX, handleY, scale, roll, width, height, radius, pasteWidth, pasteHeight

Returns:

this

Group.getBetweenGroupEntityHits

(
  • g
)

Check all entitys in this Group against all entitys in the argument Group, to see if they are in collision

Parameters:

  • g String

    GROUPNAME of Group to be checked against this group; alternatively, the Group object itself can be supplied as the argument

Returns:

Array of [ENTITYNAME, ENTITYNAME] Arrays, one for each pair of entitys currently in collision

Group.getEntitysCollidingWith

(
  • entity
)

Check all entitys in the Group to see if they are colliding with the supplied entity object. An Array of all entity objects colliding with the reference entity will be returned

Parameters:

  • entity String

    SPRITENAME String of the reference entity; alternatively the entity Object itself can be passed as the argument

Returns:

Array of visible entity Objects currently colliding with the reference entity

Group.getFieldEntityHits

(
  • [cell]
)

Check all entitys in this Group against a <canvas> element's collision field image

If no argument is supplied, the Group's default Cell's <canvas> element will be used for the check

An Array of Arrays is returned, with each constituent array consisting of the the SPRITENAME of the entity that has reported a positive hit, alongside a coordinate Vector of where the collision is occuring

Parameters:

  • [cell] String optional

    CELLNAME of Cell whose <canvas> element is to be used for the check

Returns:

Array of [ENTITYNAME, Vector] Arrays

Group.getInGroupEntityHits

()

Check all entitys in the Group against each other to see if they are in collision

Returns:

Array of [ENTITYNAME, ENTITYNAME] Arrays, one for each pair of entitys currently in collision

Group.resetCollisionPoints

() chainable

Recalculate the current collision point positions for all entitys in the group

Returns:

this

Pad.buildFields

() chainable

Orders all Cell objects associated with this Pad to (re)create their field collision image maps

Returns:

This

scrawl.buildFields

(
  • [items]
)

A general function which asks Cell objects to generate field collision tables

Parameters:

  • [items] Array optional

    Array of CELLNAME Strings - can also be a String

Returns:

Always true

Properties

scrawl.workcols

Object private

Collision vectors, for use in collision detection calculations

Note: at some point in the future, this object needs to be moved into the scrawl.work object, for consistency