Interface: utils

MC.utils

The utils (utilities) object provides internal engine methods.
Developers may find them useful.
Source:

Methods

(static) checkBB(bb1, bb2) → {Boolean}


Checks if 2 passed Sprite Bounding Boxes intersect (indicating a possible hit) OR whether a point is inside a Bounding Box
Used internally by the MC Engine
Parameters:
Name Type Description
bb1 Object First MC.Sprite.boundingBox
bb2 Object | MC.Point Second MC.Sprite.boundingBox OR an MC.Point
Source:
Returns:
True if the two boxes (or single box and point) intersect
Type
Boolean

(static) circInCircle(Centre1, Radius1, Centre2, Radius2) → {Boolean}


Checks if 2 circles intersect
Parameters:
Name Type Description
Centre1 MC.Point centre of the first circle
Radius1 Number radius of the first circle
Centre2 MC.Point centre of the second circle
Radius2 Number radius of the second circle
Source:
Returns:
true if the circle intersect, else false
Type
Boolean

(static) cloneWithAssign(thing) → {Object}


copies the object using the native JS Object.assign() method
Parameters:
Name Type Description
thing Object What is to be copied
Source:
Returns:
a new copt of the object CAUTION: only sure to work with enumerable items. May(will) not work 100% for nested elements within the object
Type
Object

(static) colorOrString(color) → {string}


Checks if a "color" is a string (i.e. HTML5 color name) or a {Color} object
Returns either the HTML5 string or the {Color} as a "rgb(r,g,b)" string
Parameters:
Name Type Description
color string | MC.Color
Source:
Returns:
Type
string

(static) fixAngle(angle) → {Number}


Accepts an angle (in degrees) and returns it's value in the range of 0-360
Parameters:
Name Type Description
angle Number Angle to be fixed
Source:
Throws:
Returns original parameter if it is non-numeric
Returns:
Same angle within range 0-360
Type
Number

(static) getPolyArray(sides, radius, angle) → {Array.<MC.Point>}

Creates an array of points representing a regular polygon's vertices about a central point
Used internally by various MC.draw methods (esp. MC.draw.poly())
Parameters:
Name Type Description
sides Number # of sides to the polygon
radius Number Distance from Poly centre to each vertex
angle Number Angle (in degrees) of first vertex. 0 = right of centre, 90 = below centre etc.
Source:
Returns:
Array of MC.Point objects
Type
Array.<MC.Point>

(static) getRectArray(width, height, angle) → {Array.<MC.Point>}

Creates an array of points representing a rectangles vertices around a central point
Used internally by various MC methods
Parameters:
Name Type Description
width Number Rectangle width
height Number Rectangle height
angle Number Angle (in degrees) of the rectangle rotation about centre. 0 = axis aligned, positive = clockwise
Source:
Returns:
Array of MC.Point objects
Type
Array.<MC.Point>

(static) getStarArray(sides, outerRadius, innerRadius, angle) → {Array.<MC.Point>}

Creates an array of points representing a regular star's vertices about a central point
Used internally by various MC.draw methods (esp. MC.draw.star())
Parameters:
Name Type Description
sides Number # of points to the star
outerRadius Number Distance from star centre to each point
innerRadius Number Distance from centre to inner points
angle Number Angle (in degrees) of first point. 0 = right of centre, 90 = below centre etc.
Source:
Returns:
Array of MC.Point objects
Type
Array.<MC.Point>

(static) hasXY(item) → {Boolean}


Checks if the entered items has x: and y: properties
Used as confirmation and to assist Method Polymorphism
Parameters:
Name Type Description
item anything
Source:
Returns:
True if both item.x and item.y exist; else False
Type
Boolean

(static) isNumeric(n) → {Boolean}


Checks if an item is a number
Parameters:
Name Type Description
n anything
Source:
Returns:
True if n is a number; else False
Type
Boolean

(static) mix(color1, color2, ratio) → {MC.Color}


Mixes two MC Color objects and returns a NEW Color object
N.B. alpha (Color.a) is also mixed
Parameters:
Name Type Description
color1 MC.Color First Color
color2 MC.Color Second Color
ratio Number Ratio of how much travel required from first color to second (as a decimal 0-1)
Source:
Returns:
a NEW color object
Type
MC.Color

(static) pointInCirc(Point, Centre, Radius) → {Boolean}


Checks if a point coordinate is within a circle defined by centre (point) and radius
Parameters:
Name Type Description
Point MC.Point to be tested
Centre MC.Point of circle to be tested against
Radius Number of circle
Source:
Returns:
true if the point is within (or on the perimeter of) the circle, else false
Type
Boolean

(static) pointInRect(Point, Corners) → {Boolean}


Checks if a point coordinate is within a rectangle defined by an array of points
Parameters:
Name Type Description
Point MC.Point to be tested
Corners Array.<MC.Point> of the Rectangle
winding direction does not matter but points should be ordered as if going around the perimeter of the rectangle
Source:
Throws:
Console warning if Corners Array does not have 4 members.
Returns:
true if the point is within (or on the perimeter of) the rectangle, else false
Type
Boolean

(static) pointInShape(Point, Array) → {Boolean}


Checks if a point coordinate lies within the shape defined by a second array of points
This only produces reliable results with CONVEX shapes.
Parameters:
Name Type Description
Point MC.Point to be tested
Array Array.<MC.Point> of points defining a shape to be tested against
winding direction does not matter but points should be ordered as if going around the perimeter of the shape
Source:
Returns:
true if the point is within (or on the perimeter of) the shape, else false
Type
Boolean

(static) pointInTri(Point, Array) → {Boolean}


Checks if a point coordinate is within the bounds defined by an Array of 3 further points
Used internally by the MC engine.
Parameters:
Name Type Description
Point MC.Point to be tested
Array Array.<MC.Point> defining bounds of the triangle
Source:
Returns:
true if the point lies within the triangle, else false
Type
Boolean

(static) randomColor() → {MC.Color}


Creates a random opaque Color Object.
Source:
Returns:
a new
Type
MC.Color

(static) shapeInCircle(Shape, Centre, Radius) → {Boolean}


Checks is any of the vertices of a shape (defined by an array of MC.Point's) are within or touching a circle
Parameters:
Name Type Description
Shape Array.<MC.Point> points array to be tested
Centre MC.Point of the circle to be tested against
Radius Number of the circle
Source:
Returns:
True if any of the points intersect the circle, else false
Type
Boolean

(static) shapeInShape(First, Second) → {Boolean}


Checks if any of an Array of point coordinates lies within the shape defined by a second array of points (and vice versa)
This only produces reliable results with shapes when each line between the vertices and centre is internal
Parameters:
Name Type Description
First Array.<MC.Point> array of points defining a shape to be tested
Second Array.<MC.Point> array of points defining another shape to be tested
winding direction does not matter but points should be ordered as if going around the perimeter of the shapes
Source:
Returns:
true if any of the points is within (or on the perimeter of) the other shape, else false
Type
Boolean

(static) shuffle(o) → {Array}


Shuffles an array
Parameters:
Name Type Description
o Array Array to be scrambled
Source:
Returns:
The same array, just in a different order
Type
Array

(static) validHT(object1, object2opt) → {Boolean}


Checks if an object is valid candidate for a hitTest, Specifically:
1. is a MC.Sprite
2. has collider === true
3. is dead === false
Used Internally an a TARGET by the MC Engine, recommended that the Developer call it on any Object prior to attempting to make it do a hitTest() call.
Parameters:
Name Type Attributes Description
object1 Object (ideally MC.Sprite) to be tested
object2 Object <optional>
Optional second Object to test
Source:
Throws:
Console warning if invalid
Returns:
True if all parameter Objects are valid hitTest candidate(s)
Type
Boolean