Back to Top

Vexr master

A Vector and Behavior Library

Convert()

Small library of converters needed for the various Vexr operations

Returns

Void

value(radians)

Parameters

Name Type Description
radians

{number}

Returns

number

value(v)

Resets the supplied Vector to 0.

Parameters

Name Type Description
v

{Vector3}

Returns

Void

value(v)

Copy this vector

Parameters

Name Type Description
v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

Screen()

Screen is a bunch of helper functions to give you control over where you want things to go on the screen using Vectors

When setting the anchor you do it as an expression of the ratio of where you want to show up on the screen. For example 0.5, 0.5 would give you the center of the screen

Set an anchor point by calling setAnchor("PinnedLeftCenter", 0, 0.5);

If you want to know the absolute position of an anchor on the screen, pass the key for your anchor to Screen.getAnchor("PinnedLeftCenter");

Returns

Void

value(e)

The function called on resize that buffers the event to resize

Parameters

Name Type Description
e

{event}

Returns

Void

get()

Returns the screen dimensions as a vector x = width, y = height

Returns

Vector3

key()

Behaviors are applied to Actors by passing actors, target actors, and parameters into them.

Returns

Void

value()

init is a static method that is used to initialize the object pool

Returns

Void

Actor()

The Actor class is used by Behaviors to apply behaviors to.

Returns

Void

Actor(className, location)

Parameters

Name Type Description
className

{string}

location

{Vector3)

Returns

Void

createClass(vector)

addForce() will add the vector you pass in to the acceleration

Parameters

Name Type Description
vector

{Vector3}

Returns

Void

DOMActor()

DOMActor is an extension of the Actor class specifically for working with DOM elements.

Returns

Void

DOMActor(className, location)

Parameters

Name Type Description
className

{string} the CSS class you want to use for this DOMActor

location

{Vector3} The starting location for this Actor

Returns

Void

createClass(parentElement)

addToParentElement() will add DOMActor.element to the parentElement

Parameters

Name Type Description
parentElement

{HTMLElement}

Returns

Void

new Convert()

Small library of converters needed for the various Vexr operations

Returns

Void

Convert.RadiansToDegrees(radians)

Parameters

Name Type Description
radians

{number}

Returns

number

Convert.DegreesToRadians(degrees)

Parameters

Name Type Description
degrees

{number}

Returns

number

Convert.MapRange(value, bottomA, topA, bottomB, topB)

MapRange takes a set of values and maps another set of values to that range.

Parameters

Name Type Description
value

{number}

bottomA

{number}

topA

{number}

bottomB

{number}

topB

{number}

Returns

number

Convert.reset(v)

Resets the supplied Vector to 0.

Parameters

Name Type Description
v

{Vector3}

Returns

Void

Convert.angleBetween(a, b)

angleBetween() gets the angle between two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

Returns

number

Convert.lerp(a, b, t, v)

Linear interpolation between two vector locations

Parameters

Name Type Description
a

{Vector3} Starting point

b

{Vector3} Ending point

t

{number} The ratio between the two points 0: Start. 1: End.

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

Convert.normalize(vector, v)

Normalize a Vector

Parameters

Name Type Description
vector

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

Convert.magnitude(vector)

Get the Magnitude of a vector

Parameters

Name Type Description
vector

{Vector3}

Returns

number

Convert.add(a, b, v)

Add two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

Convert.multiply(a, b, v)

Subtract two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

Convert.divide(a, b, v)

Multiply two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

Convert.dot(a, b)

Gets the dot product of two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

Returns

number

Convert.cross(a, b, v)

Get the cross product of two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

Convert.dist(a, b)

Get the distance between two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

Returns

number

Convert.constructor(x, y, z, w)

Creates a new Vector

Parameters

Name Type Description
x

{number}

y

{number}

z

{number}

w

{number}

Returns

Void

Convert.get(v)

Copy this vector

Parameters

Name Type Description
v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

Convert.set(x, y, z, w)

Sets the vector to the values passed in

Parameters

Name Type Description
x

{number}

y

{number}

z

{number}

w

{number}

Returns

Void

Convert.multiply(scalar)

Multiplies this vector by a scalar

Parameters

Name Type Description
scalar

{number}

Returns

Void

Convert.add(v)

Adds the vector passed in to this vector

Parameters

Name Type Description
v

{Vector3}

Returns

Void

Convert.subtract(v)

Subtracts the vector passed in from this vector

Parameters

Name Type Description
v

{Vector3}

Returns

Void

Convert.divide(scalar)

Divides this vector by the scalar

Parameters

Name Type Description
scalar

{Vector3}

Returns

Void

Convert.negate()

Inverts this vector

Returns

Void

Convert.clamp(limit)

Clamps the vector components to the limit value

Parameters

Name Type Description
limit

{number}

Returns

Void

Convert.limit(limit)

limits the vector magnitude to the limit value

Parameters

Name Type Description
limit

{number} the maximum magnitude

Returns

Void

Convert.rotate(degrees, pivotVector, stabilize)

Rotate this vector

Parameters

Name Type Description
degrees

{number} degrees to rotate the vector by

pivotVector

{Vector3} [pivotVector= new Vector3()] The point that you want to rotate around (default 0,0)

stabilize

{boolean} [stabilize = false] stabilize the rotation of the vector by maintaining it's magnitude

Returns

Void

Convert.magnitude()

The magnitude of this vector

Returns

number

Convert.normalize()

Normalize this vector

Returns

Void

new Screen()

Screen is a bunch of helper functions to give you control over where you want things to go on the screen using Vectors

When setting the anchor you do it as an expression of the ratio of where you want to show up on the screen. For example 0.5, 0.5 would give you the center of the screen

Set an anchor point by calling setAnchor("PinnedLeftCenter", 0, 0.5);

If you want to know the absolute position of an anchor on the screen, pass the key for your anchor to Screen.getAnchor("PinnedLeftCenter");

Returns

Void

resize(e)

The function called on resize that buffers the event to resize

Parameters

Name Type Description
e

{event}

Returns

Void

recalculate()

Loops through all the anchors and properties and updates their real coordinates

Returns

Void

getAnchor(name)

Returns a vector for your anchor point at it's real position on screen

Parameters

Name Type Description
name

{string}

Returns

Void

setAnchor(name, ratioX, ratioY)

Sets an anchor point at the provided ratio

Parameters

Name Type Description
name

{string}

ratioX

{number}

ratioY

{number}

Returns

Void

removeAnchor(name)

Deletes an anchor

Parameters

Name Type Description
name

Returns

Void

init()

Initializes the static class (ES6 no static property workaround)

Returns

Void

key()

Behaviors are applied to Actors by passing actors, target actors, and parameters into them.

Returns

Void

init()

init is a static method that is used to initialize the object pool

Returns

Void

seek(actor, targetPosition, scaleForce)

seek() finds the distance between the actor and the targetLcation and applys a force to move the actor toward that target.

Parameters

Name Type Description
actor

{Actor}

targetPosition

{Vector3}

scaleForce

{?number}

Returns

Void

arrive(actor, target, power, scaleForce)

arrive() works similarly to seek, but with the magnitude of the seek mapped to a power that is inversely proportionate to the magnitude of the distance between the actor and the target.

Parameters

Name Type Description
actor

{Actor}

target

{Vector3}

power

{?number}

scaleForce

{?number}

Returns

Void

avoidAll(actor, obstacles, avoidRadius, scaleForce)

avoidAll() takes an array of obstacle actors and for each obstacle, the Actor will have the average escape vector of all the obstacles near it applied to it.

Parameters

Name Type Description
actor

{Actor}

obstacles

{Array.}

avoidRadius

{?number}

scaleForce

{?number}

Returns

Void

avoid(actor, target, avoidRadius)

Uses a single obstacle in the avoidAll function

Parameters

Name Type Description
actor
target
avoidRadius

Returns

Void

constrain(actor, minWidth, minHeight, maxWidth, maxHeight, margin)

constrain() will lock your actor to the provided area. Velocity will be inverted with no friction when an Actor hits the wall.

Parameters

Name Type Description
actor

{Actor}

minWidth

{number} Left

minHeight

{number} Uo

maxWidth

{number} Right

maxHeight

{number} Bottom

margin

{number} the amount of offset you want for these values. The margins work by subtracting from minimums and adding to maximums.

Returns

Void

wrap(actor, minWidth, minHeight, maxWidth, maxHeight, margin)

wrap() will teleport your object to the opposite side of the screen where it left

Parameters

Name Type Description
actor

{Actor}

minWidth

{number} Left

minHeight

{number} Uo

maxWidth

{number} Right

maxHeight

{number} Bottom

margin

{number} the amount of offset you want for these values. The margins work by subtracting from minimums and adding to maximums.

Returns

Void

disableOutside(actor, minWidth, minHeight, maxWidth, maxHeight, margin)

disableOutside will set your Actor.active parameter to "false" when it leaves the defined area

Parameters

Name Type Description
actor

{Actor}

minWidth

{number} Left

minHeight

{number} Uo

maxWidth

{number} Right

maxHeight

{number} Bottom

margin

{number} the amount of offset you want for these values. The margins work by subtracting from minimums and adding to maximums.

Returns

Void

destroyOutside(actor, minWidth, minHeight, maxWidth, maxHeight, margin)

destroyOutside will set Actor.dead to true if it leaves the defined area;

Parameters

Name Type Description
actor

{Actor}

minWidth

{number} Left

minHeight

{number} Uo

maxWidth

{number} Right

maxHeight

{number} Bottom

margin

{number} the amount of offset you want for these values. The margins work by subtracting from minimums and adding to maximums.

Returns

Void

new Actor()

The Actor class is used by Behaviors to apply behaviors to.

Returns

Void

Actor.constructor(className, location)

Parameters

Name Type Description
className

{string}

location

{Vector3)

Returns

Void

Actor.addForce(vector)

addForce() will add the vector you pass in to the acceleration

Parameters

Name Type Description
vector

{Vector3}

Returns

Void

Actor.update()

update() will check to see if this actor is active, then call move(), then add the acceleration to the velocity, the velocity to the location, then reset the acceleration.

Returns

Void

Actor.move()

move() is unused in the base class and is designed to be overridden. Anything in the move function will be applied before acceleration is added to velocity. See DOMActor for an example.

Returns

Void

Actor.render()

render() checks if the actor is visible then calls the draw() function. See DOMActor for an example.

Returns

Void

Actor.draw()

draw() is empty in this class but can be extended to render itself in any rendering environment of your choice. See DOMActor for an example.

Returns

Void

Actor.destroy()

destroy() sets the Actor.dead state to true. This is used by the GameLoop class to clean up / remove dead objects.

Returns

Void

new DOMActor()

DOMActor is an extension of the Actor class specifically for working with DOM elements.

Returns

Void

DOMActor.constructor(className, location)

Parameters

Name Type Description
className

{string} the CSS class you want to use for this DOMActor

location

{Vector3} The starting location for this Actor

Returns

Void

DOMActor.addToParentElement(parentElement)

addToParentElement() will add DOMActor.element to the parentElement

Parameters

Name Type Description
parentElement

{HTMLElement}

Returns

Void

DOMActor.draw()

draw() sets this DOMActor.element.style.transform to translateX(${this.location.x}px) translateY(${this.location.y}px) rotate(${this.angle}deg)

Returns

Void

DOMActor.destroy()

destroy() sets this DOMActor to dead, removes it from the DOM, and nulls its reference to the parentElement

Returns

Void

Convert()

Small library of converters needed for the various Vexr operations

Returns

Void

value(radians)

Parameters

Name Type Description
radians

{number}

Returns

number

value(v)

Resets the supplied Vector to 0.

Parameters

Name Type Description
v

{Vector3}

Returns

Void

value(v)

Copy this vector

Parameters

Name Type Description
v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

Screen()

Screen is a bunch of helper functions to give you control over where you want things to go on the screen using Vectors

When setting the anchor you do it as an expression of the ratio of where you want to show up on the screen. For example 0.5, 0.5 would give you the center of the screen

Set an anchor point by calling setAnchor("PinnedLeftCenter", 0, 0.5);

If you want to know the absolute position of an anchor on the screen, pass the key for your anchor to Screen.getAnchor("PinnedLeftCenter");

Returns

Void

value(e)

The function called on resize that buffers the event to resize

Parameters

Name Type Description
e

{event}

Returns

Void

get()

Returns the screen dimensions as a vector x = width, y = height

Returns

Vector3

key()

Behaviors are applied to Actors by passing actors, target actors, and parameters into them.

Returns

Void

value()

init is a static method that is used to initialize the object pool

Returns

Void

Actor()

The Actor class is used by Behaviors to apply behaviors to.

Returns

Void

Actor(className, location)

Parameters

Name Type Description
className

{string}

location

{Vector3)

Returns

Void

createClass(vector)

addForce() will add the vector you pass in to the acceleration

Parameters

Name Type Description
vector

{Vector3}

Returns

Void

DOMActor()

DOMActor is an extension of the Actor class specifically for working with DOM elements.

Returns

Void

DOMActor(className, location)

Parameters

Name Type Description
className

{string} the CSS class you want to use for this DOMActor

location

{Vector3} The starting location for this Actor

Returns

Void

createClass(parentElement)

addToParentElement() will add DOMActor.element to the parentElement

Parameters

Name Type Description
parentElement

{HTMLElement}

Returns

Void

constructor(className, location)

Parameters

Name Type Description
className

{string}

location

{Vector3)

Returns

Void

addForce(vector)

addForce() will add the vector you pass in to the acceleration

Parameters

Name Type Description
vector

{Vector3}

Returns

Void

update()

update() will check to see if this actor is active, then call move(), then add the acceleration to the velocity, the velocity to the location, then reset the acceleration.

Returns

Void

move()

move() is unused in the base class and is designed to be overridden. Anything in the move function will be applied before acceleration is added to velocity. See DOMActor for an example.

Returns

Void

render()

render() checks if the actor is visible then calls the draw() function. See DOMActor for an example.

Returns

Void

draw()

draw() is empty in this class but can be extended to render itself in any rendering environment of your choice. See DOMActor for an example.

Returns

Void

destroy()

destroy() sets the Actor.dead state to true. This is used by the GameLoop class to clean up / remove dead objects.

Returns

Void

init()

init is a static method that is used to initialize the object pool

Returns

Void

seek(actor, targetPosition, scaleForce)

seek() finds the distance between the actor and the targetLcation and applys a force to move the actor toward that target.

Parameters

Name Type Description
actor

{Actor}

targetPosition

{Vector3}

scaleForce

{?number}

Returns

Void

arrive(actor, target, power, scaleForce)

arrive() works similarly to seek, but with the magnitude of the seek mapped to a power that is inversely proportionate to the magnitude of the distance between the actor and the target.

Parameters

Name Type Description
actor

{Actor}

target

{Vector3}

power

{?number}

scaleForce

{?number}

Returns

Void

avoidAll(actor, obstacles, avoidRadius, scaleForce)

avoidAll() takes an array of obstacle actors and for each obstacle, the Actor will have the average escape vector of all the obstacles near it applied to it.

Parameters

Name Type Description
actor

{Actor}

obstacles

{Array.}

avoidRadius

{?number}

scaleForce

{?number}

Returns

Void

avoid(actor, target, avoidRadius)

Uses a single obstacle in the avoidAll function

Parameters

Name Type Description
actor
target
avoidRadius

Returns

Void

constrain(actor, minWidth, minHeight, maxWidth, maxHeight, margin)

constrain() will lock your actor to the provided area. Velocity will be inverted with no friction when an Actor hits the wall.

Parameters

Name Type Description
actor

{Actor}

minWidth

{number} Left

minHeight

{number} Uo

maxWidth

{number} Right

maxHeight

{number} Bottom

margin

{number} the amount of offset you want for these values. The margins work by subtracting from minimums and adding to maximums.

Returns

Void

wrap(actor, minWidth, minHeight, maxWidth, maxHeight, margin)

wrap() will teleport your object to the opposite side of the screen where it left

Parameters

Name Type Description
actor

{Actor}

minWidth

{number} Left

minHeight

{number} Uo

maxWidth

{number} Right

maxHeight

{number} Bottom

margin

{number} the amount of offset you want for these values. The margins work by subtracting from minimums and adding to maximums.

Returns

Void

disableOutside(actor, minWidth, minHeight, maxWidth, maxHeight, margin)

disableOutside will set your Actor.active parameter to "false" when it leaves the defined area

Parameters

Name Type Description
actor

{Actor}

minWidth

{number} Left

minHeight

{number} Uo

maxWidth

{number} Right

maxHeight

{number} Bottom

margin

{number} the amount of offset you want for these values. The margins work by subtracting from minimums and adding to maximums.

Returns

Void

destroyOutside(actor, minWidth, minHeight, maxWidth, maxHeight, margin)

destroyOutside will set Actor.dead to true if it leaves the defined area;

Parameters

Name Type Description
actor

{Actor}

minWidth

{number} Left

minHeight

{number} Uo

maxWidth

{number} Right

maxHeight

{number} Bottom

margin

{number} the amount of offset you want for these values. The margins work by subtracting from minimums and adding to maximums.

Returns

Void

new Convert()

Small library of converters needed for the various Vexr operations

Returns

Void

Convert.RadiansToDegrees(radians)

Parameters

Name Type Description
radians

{number}

Returns

number

Convert.DegreesToRadians(degrees)

Parameters

Name Type Description
degrees

{number}

Returns

number

Convert.MapRange(value, bottomA, topA, bottomB, topB)

MapRange takes a set of values and maps another set of values to that range.

Parameters

Name Type Description
value

{number}

bottomA

{number}

topA

{number}

bottomB

{number}

topB

{number}

Returns

number

new DOMActor()

DOMActor is an extension of the Actor class specifically for working with DOM elements.

Returns

Void

DOMActor.constructor(className, location)

Parameters

Name Type Description
className

{string} the CSS class you want to use for this DOMActor

location

{Vector3} The starting location for this Actor

Returns

Void

DOMActor.addToParentElement(parentElement)

addToParentElement() will add DOMActor.element to the parentElement

Parameters

Name Type Description
parentElement

{HTMLElement}

Returns

Void

DOMActor.draw()

draw() sets this DOMActor.element.style.transform to translateX(${this.location.x}px) translateY(${this.location.y}px) rotate(${this.angle}deg)

Returns

Void

DOMActor.destroy()

destroy() sets this DOMActor to dead, removes it from the DOM, and nulls its reference to the parentElement

Returns

Void

new Screen()

Screen is a bunch of helper functions to give you control over where you want things to go on the screen using Vectors

When setting the anchor you do it as an expression of the ratio of where you want to show up on the screen. For example 0.5, 0.5 would give you the center of the screen

Set an anchor point by calling setAnchor("PinnedLeftCenter", 0, 0.5);

If you want to know the absolute position of an anchor on the screen, pass the key for your anchor to Screen.getAnchor("PinnedLeftCenter");

Returns

Void

resize(e)

The function called on resize that buffers the event to resize

Parameters

Name Type Description
e

{event}

Returns

Void

recalculate()

Loops through all the anchors and properties and updates their real coordinates

Returns

Void

getAnchor(name)

Returns a vector for your anchor point at it's real position on screen

Parameters

Name Type Description
name

{string}

Returns

Void

setAnchor(name, ratioX, ratioY)

Sets an anchor point at the provided ratio

Parameters

Name Type Description
name

{string}

ratioX

{number}

ratioY

{number}

Returns

Void

removeAnchor(name)

Deletes an anchor

Parameters

Name Type Description
name

Returns

Void

init()

Initializes the static class (ES6 no static property workaround)

Returns

Void

reset(v)

Resets the supplied Vector to 0.

Parameters

Name Type Description
v

{Vector3}

Returns

Void

angleBetween(a, b)

angleBetween() gets the angle between two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

Returns

number

lerp(a, b, t, v)

Linear interpolation between two vector locations

Parameters

Name Type Description
a

{Vector3} Starting point

b

{Vector3} Ending point

t

{number} The ratio between the two points 0: Start. 1: End.

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

normalize(vector, v)

Normalize a Vector

Parameters

Name Type Description
vector

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

magnitude(vector)

Get the Magnitude of a vector

Parameters

Name Type Description
vector

{Vector3}

Returns

number

add(a, b, v)

Add two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

multiply(a, b, v)

Subtract two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

divide(a, b, v)

Multiply two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

dot(a, b)

Gets the dot product of two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

Returns

number

cross(a, b, v)

Get the cross product of two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

dist(a, b)

Get the distance between two vectors

Parameters

Name Type Description
a

{Vector3}

b

{Vector3}

Returns

number

constructor(x, y, z, w)

Creates a new Vector

Parameters

Name Type Description
x

{number}

y

{number}

z

{number}

w

{number}

Returns

Void

get(v)

Copy this vector

Parameters

Name Type Description
v

{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector

Returns

Vector3

set(x, y, z, w)

Sets the vector to the values passed in

Parameters

Name Type Description
x

{number}

y

{number}

z

{number}

w

{number}

Returns

Void

multiply(scalar)

Multiplies this vector by a scalar

Parameters

Name Type Description
scalar

{number}

Returns

Void

add(v)

Adds the vector passed in to this vector

Parameters

Name Type Description
v

{Vector3}

Returns

Void

subtract(v)

Subtracts the vector passed in from this vector

Parameters

Name Type Description
v

{Vector3}

Returns

Void

divide(scalar)

Divides this vector by the scalar

Parameters

Name Type Description
scalar

{Vector3}

Returns

Void

negate()

Inverts this vector

Returns

Void

clamp(limit)

Clamps the vector components to the limit value

Parameters

Name Type Description
limit

{number}

Returns

Void

limit(limit)

limits the vector magnitude to the limit value

Parameters

Name Type Description
limit

{number} the maximum magnitude

Returns

Void

rotate(degrees, pivotVector, stabilize)

Rotate this vector

Parameters

Name Type Description
degrees

{number} degrees to rotate the vector by

pivotVector

{Vector3} [pivotVector= new Vector3()] The point that you want to rotate around (default 0,0)

stabilize

{boolean} [stabilize = false] stabilize the rotation of the vector by maintaining it's magnitude

Returns

Void

magnitude()

The magnitude of this vector

Returns

number

normalize()

Normalize this vector

Returns

Void