# addForce(vector)
addForce() will add the vector you pass in to the acceleration
Parameters
Name | Types | Description |
---|---|---|
vector |
|
{Vector3} |
# destroy()
destroy() sets the Actor.dead state to true. This is used by the GameLoop class to clean up / remove dead objects.
# 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.
# 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.
# render()
render() checks if the actor is visible then calls the draw() function. See DOMActor for an example.
# sName(className, location)
Parameters
Name | Types | Description |
---|---|---|
className |
|
{string} |
location |
|
{Vector3) |
# 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.
# 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 | Types | Description |
---|---|---|
actor |
|
{Actor} |
target |
|
{Vector3} |
power |
|
{?number} |
scaleForce |
|
{?number} |
# avoid(actor, target, avoidRadius)
Uses a single obstacle in the avoidAll function
Parameters
Name | Types | Description |
---|---|---|
actor |
|
|
target |
|
|
avoidRadius |
|
# 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 | Types | Description |
---|---|---|
actor |
|
{Actor} |
obstacles |
|
{Array. |
avoidRadius |
|
{?number} |
scaleForce |
|
{?number} |
# destroyOutside(actor, minWidth, minHeight, maxWidth, maxHeight, margin)
destroyOutside will set Actor.dead to true if it leaves the defined area;
Parameters
Name | Types | 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. |
# disableOutside(actor, minWidth, minHeight, maxWidth, maxHeight, margin)
disableOutside will set your Actor.active parameter to "false" when it leaves the defined area
Parameters
Name | Types | 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. |
# Screen.width(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 | Types | 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. |
# Screen.width(actor, minWidth, minHeight, maxWidth, maxHeight, margin)
wrap() will teleport your object to the opposite side of the screen where it left
Parameters
Name | Types | 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. |
# 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 | Types | Description |
---|---|---|
actor |
|
{Actor} |
targetPosition |
|
{Vector3} |
scaleForce |
|
{?number} |
# MapRange(value, bottomA, topA, bottomB, topB)
MapRange takes a set of values and maps another set of values to that range.
Parameters
Name | Types | Description |
---|---|---|
value |
|
{number} |
bottomA |
|
{number} |
topA |
|
{number} |
bottomB |
|
{number} |
topB |
|
{number} |
# addToParentElement(parentElement)
addToParentElement() will add DOMActor.element to the parentElement
Parameters
Name | Types | Description |
---|---|---|
parentElement |
|
{HTMLElement} |
# destroy()
destroy() sets this DOMActor to dead, removes it from the DOM, and nulls its reference to the parentElement
# DOMActor()
DOMActor is an extension of the Actor class specifically for working with DOM elements.
# draw()
draw() sets this DOMActor.element.style.transform to translateX(${this.location.x}px) translateY(${this.location.y}px) rotate(${this.angle}deg)
# sName(className, location)
Parameters
Name | Types | Description |
---|---|---|
className |
|
{string} the CSS class you want to use for this DOMActor |
location |
|
{Vector3} The starting location for this Actor |
# anchorPositions(value)
Sets all the anchor positions
Parameters
Name | Types | Description |
---|---|---|
value |
|
{Array} |
# center(value)
sets a vector at the center of the screen
Parameters
Name | Types | Description |
---|---|---|
value |
|
{Vector3} |
# dimensions(value)
Sets the screen dimensions as a vector x = width, y = height
Parameters
Name | Types | Description |
---|---|---|
value |
|
{Vector3} |
# getAnchor(name)
Returns a vector for your anchor point at it's real position on screen
Parameters
Name | Types | Description |
---|---|---|
name |
|
{string} |
# orientation(value)
sets the screen dimensions as an orientation value.
Parameters
Name | Types | Description |
---|---|---|
value |
|
{string} |
# resize(e)
The function called on resize that buffers the event to resize
Parameters
Name | Types | Description |
---|---|---|
e |
|
{event} |
# resizeDelay(value)
The debounce value for the resize
Parameters
Name | Types | Description |
---|---|---|
value |
|
{number} |
# 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");
# setAnchor(name, ratioX, ratioY)
Sets an anchor point at the provided ratio
Parameters
Name | Types | Description |
---|---|---|
name |
|
{string} |
ratioX |
|
{number} |
ratioY |
|
{number} |
# add(a, b, v)
Add two vectors
Parameters
Name | Types | Description |
---|---|---|
a |
|
{Vector3} |
b |
|
{Vector3} |
v |
|
{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector |
# angleBetween(a, b)
angleBetween() gets the angle between two vectors
Parameters
Name | Types | Description |
---|---|---|
a |
|
{Vector3} |
b |
|
{Vector3} |
# clamp(limit)
Clamps the vector components to the limit value
Parameters
Name | Types | Description |
---|---|---|
limit |
|
{number} |
# constructor(x, y, z, w)
Creates a new Vector
Parameters
Name | Types | Description |
---|---|---|
x |
|
{number} |
y |
|
{number} |
z |
|
{number} |
w |
|
{number} |
# cross(a, b, v)
Get the cross product of two vectors
Parameters
Name | Types | Description |
---|---|---|
a |
|
{Vector3} |
b |
|
{Vector3} |
v |
|
{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector |
# dist(a, b)
Get the distance between two vectors
Parameters
Name | Types | Description |
---|---|---|
a |
|
{Vector3} |
b |
|
{Vector3} |
# divide(a, b, v)
Multiply two vectors
Parameters
Name | Types | Description |
---|---|---|
a |
|
{Vector3} |
b |
|
{Vector3} |
v |
|
{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector |
# divide(scalar)
Divides this vector by the scalar
Parameters
Name | Types | Description |
---|---|---|
scalar |
|
{Vector3} |
# dot(a, b)
Gets the dot product of two vectors
Parameters
Name | Types | Description |
---|---|---|
a |
|
{Vector3} |
b |
|
{Vector3} |
# get(v)
Copy this vector
Parameters
Name | Types | Description |
---|---|---|
v |
|
{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector |
# lerp(a, b, t, v)
Linear interpolation between two vector locations
Parameters
Name | Types | 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 |
# limit(limit)
limits the vector magnitude to the limit value
Parameters
Name | Types | Description |
---|---|---|
limit |
|
{number} the maximum magnitude |
# magnitude(vector)
Get the Magnitude of a vector
Parameters
Name | Types | Description |
---|---|---|
vector |
|
{Vector3} |
# multiply(a, b, v)
Subtract two vectors
Parameters
Name | Types | Description |
---|---|---|
a |
|
{Vector3} |
b |
|
{Vector3} |
v |
|
{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector |
# multiply(scalar)
Multiplies this vector by a scalar
Parameters
Name | Types | Description |
---|---|---|
scalar |
|
{number} |
# normalize(vector, v)
Normalize a Vector
Parameters
Name | Types | Description |
---|---|---|
vector |
|
{Vector3} |
v |
|
{Vector3} [v= new Vector()] an optional reference instead of allocating a new vector |
# set(x, y, z, w)
Sets the vector to the values passed in
Parameters
Name | Types | Description |
---|---|---|
x |
|
{number} |
y |
|
{number} |
z |
|
{number} |
w |
|
{number} |
# subtract(v)
Subtracts the vector passed in from this vector
Parameters
Name | Types | Description |
---|---|---|
v |
|
{Vector3} |
# Vector3.zero(degrees, pivotVector, stabilize)
Rotate this vector
Parameters
Name | Types | 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 |