diff --git a/api/2D.html b/api/2D.html index 0aa5656..0a2bad9 100644 --- a/api/2D.html +++ b/api/2D.html @@ -55,18 +55,18 @@ -

2D

Component for any entity that has a position on the stage.

-

Events

Move [ Old position { { _x:Number, _y:Number, _w:Number, _h:Number } }]
when the entity has moved
Invalidate
when the entity needs to be redrawn
Rotate [ Data { { cos:Number, sin:Number, deg:Number, rad:Number, o: {x:Number, y:Number}} }]
when the entity is rotated

Methods and Properties

Back to top

._attr

Setter method for all 2D properties including +

2D

Component for any entity that has a position on the stage.

+

Events

Move [Old position = { _x:Number, _y:Number, _w:Number, _h:Number }]
when the entity has moved
Invalidate
when the entity needs to be redrawn
Rotate [Data = { cos:Number, sin:Number, deg:Number, rad:Number, o: {x:Number, y:Number}}]
when the entity is rotated
Reorder
when the entity's z index has changed

Methods and Properties

Back to top

._attr

Setter method for all 2D properties including x, y, w, h, alpha, rotation and visible.

-
Back to top

._cascade

public void ._cascade(e)
e

An object describing the motion

+
Back to top

._cascade

public void ._cascade(e)
e

An object describing the motion

Move or rotate the entity's children according to a certain motion. This method is part of a function bound to "Move": It is used internally for ensuring that when a parent moves, the child also moves in the same way.

-
Back to top

._globalZ

When two entities overlap, the one with the larger _globalZ will be on top of the other.

-
Back to top

.alpha

Transparency of an entity. Must be a decimal value between 0.0 being fully transparent to 1.0 being fully opaque.

-
Back to top

.area

public Number .area(void)

Calculates the area of the entity

-
Back to top

.attach

public this .attach(Entity obj[, .., Entity objN])
obj

Child entity(s) to attach

+
Back to top

._globalZ

When two entities overlap, the one with the larger _globalZ will be on top of the other.

+
Back to top

.alpha

Transparency of an entity. Must be a decimal value between 0.0 being fully transparent to 1.0 being fully opaque.

+
Back to top

.area

public Number .area(void)

Calculates the area of the entity

+
Back to top

.attach

public this .attach(Entity obj[, .., Entity objN])
obj

Child entity(s) to attach

Sets one or more entities to be children, with the current entity (this) as the parent. When the parent moves or rotates, its children move or rotate by the same amount. (But not vice-versa: If you move a child, it @@ -76,56 +76,55 @@ objects (if any), and this._parent is its parent entity object (if any).

As many objects as wanted can be attached, and a hierarchy of objects is possible by attaching.

-
Back to top

.contains

public Boolean .contains(Number x, Number y, Number w, Number h)
x

X position of the rect

+
Back to top

.contains

public Boolean .contains(Number x, Number y, Number w, Number h)
x

X position of the rect

y

Y position of the rect

w

Width of the rect

h

Height of the rect

-
public Boolean .contains(Object rect)
rect

An object that must have the _x, _y, _w, _h values as properties.

+
public Boolean .contains(Object rect)
rect

An object that must have the _x, _y, _w, _h values as properties.

Determines if the rectangle is within the current entity. If the entity is rotated, its MBR is used for the test.

-
Back to top

.detach

public this .detach([Entity obj])
obj

The entity to detach. Left blank will remove all attached entities

+
Back to top

.detach

public this .detach([Entity obj])
obj

The entity to detach. Left blank will remove all attached entities

Stop an entity from following the current entity. Passing no arguments will stop every entity attached.

-
Back to top

.flip

Events

Invalidate
when the entity has flipped
public this .flip(String dir)
dir

Flip direction

+
Back to top

.flip

Events

Invalidate
when the entity has flipped
public this .flip(String dir)
dir

Flip direction

Flip entity on passed direction

-

Example

this.flip("X")
Back to top

.h

The height of the entity. When modified, will automatically be redrawn. +

Example

this.flip("X")
Back to top

.h

The height of the entity. When modified, will automatically be redrawn. Is actually a getter/setter so when using this value for calculations and not modifying it, use the ._h property.

Changing this value is not recommended as canvas has terrible resize quality and DOM will just clip the image.

-

See Also

Back to top

.intersect

public Boolean .intersect(Number x, Number y, Number w, Number h)
x

X position of the rect

+

See Also

Back to top

.intersect

public Boolean .intersect(Number x, Number y, Number w, Number h)
x

X position of the rect

y

Y position of the rect

w

Width of the rect

h

Height of the rect

-
public Boolean .intersect(Object rect)
rect

An object that must have the x, y, w, h values as properties

+
public Boolean .intersect(Object rect)
rect

An object that must have the _x, _y, _w, _h values as properties

Determines if this entity intersects a rectangle. If the entity is rotated, its MBR is used for the test.

-
Back to top

.isAt

public Boolean .isAt(Number x, Number y)
x

X position of the point

+
Back to top

.isAt

public Boolean .isAt(Number x, Number y)
x

X position of the point

y

Y position of the point

Determines whether a point is contained by the entity. Unlike other methods, an object can't be passed. The arguments require the x and y value.

The given point is tested against the first of the following that exists: a mapArea associated with "Mouse", the hitarea associated with "Collision", or the object's MBR.

-
Back to top

.mbr

public Object .mbr()

Returns the minimum bounding rectangle. If there is no rotation +

Back to top

.mbr

public Object .mbr()

Returns the minimum bounding rectangle. If there is no rotation on the entity it will return the rect.

-
Back to top

.move

public this .move(String dir, Number by)
dir

Direction to move (n,s,e,w,ne,nw,se,sw)

+
Back to top

.move

public this .move(String dir, Number by)
dir

Direction to move (n,s,e,w,ne,nw,se,sw)

by

Amount to move in the specified direction

Quick method to move the entity in a direction (n, s, e, w, ne, nw, se, sw) by an amount of pixels.

-
Back to top

.offsetBoundary

Extends the MBR of the entity by a specified amount.

-

Events

BoundaryOffset
when the MBR offset changes
public this .offsetBoundary(Number dx1, Number dy1, Number dx2, Number dy2)
dx1

Extends the MBR to the left by this amount

+
Back to top

.offsetBoundary

Extends the MBR of the entity by a specified amount.

+

Events

BoundaryOffset
when the MBR offset changes
public this .offsetBoundary(Number dx1, Number dy1, Number dx2, Number dy2)
dx1

Extends the MBR to the left by this amount

dy1

Extends the MBR upward by this amount

dx2

Extends the MBR to the right by this amount

dy2

Extends the MBR downward by this amount

-
public this .offsetBoundary(Number offset)
offset

Extend the MBR in all directions by this amount

+
public this .offsetBoundary(Number offset)
offset

Extend the MBR in all directions by this amount

You would most likely use this function to ensure that custom canvas rendering beyond the extent of the entity's normal bounds is not clipped.

-
Back to top

.origin

public this .origin(Number x, Number y)
x

Pixel value of origin offset on the X axis

+
Back to top

.origin

public this .origin(Number x, Number y)
x

Pixel value of origin offset on the X axis

y

Pixel value of origin offset on the Y axis

-
public this .origin(String offset)
offset

Combination of center, top, bottom, middle, left and right

+
public this .origin(String offset)
offset

Combination of center, top, bottom, middle, left and right

Set the origin point of an entity for it to rotate around.

Example

this.origin("top left")
 this.origin("center")
 this.origin("bottom right")
-this.origin("middle right")

See Also

Back to top

.pos

public Object .pos(void)

Returns the x, y, w, h properties as a rect object -(a rect object is just an object with the keys _x, _y, _w, _h).

-

The keys have an underscore prefix. This is due to the x, y, w, h -properties being merely setters and getters that wrap the properties with an underscore (_x, _y, _w, _h).

-
Back to top

.rotation

The rotation state of the entity, in clockwise degrees. +this.origin("middle right")

See Also

Back to top

.pos

public Object .pos([Object pos])
pos

an object to use as output

+
[Returns]

An object with this entity's _x, _y, _w, and _h values. If an object is passed in, it will be reused rather than creating a new object.

+

Note: The keys have an underscore prefix. This is due to the x, y, w, h properties being setters and getters that wrap the underlying properties with an underscore (_x, _y, _w, _h).

+
Back to top

.rotation

The rotation state of the entity, in clockwise degrees. this.rotation = 0 sets it to its original orientation; this.rotation = 10 sets it to 10 degrees clockwise from its original orientation; this.rotation = -10 sets it to 10 degrees counterclockwise from its @@ -138,34 +137,34 @@ rotation. (Numerical errors do not occur until you get to millions of degrees.)

The default is to rotate the entity around its (initial) top-left corner; use .origin() to change that.

-
Back to top

.shift

public this .shift(Number x, Number y, Number w, Number h)
x

Amount to move X

+
Back to top

.shift

public this .shift(Number x, Number y, Number w, Number h)
x

Amount to move X

y

Amount to move Y

w

Amount to widen

h

Amount to increase height

Shift or move the entity by an amount. Use negative values for an opposite direction.

-
Back to top

.unflip

Events

Invalidate
when the entity has unflipped
public this .unflip(String dir)
dir

Unflip direction

+
Back to top

.unflip

Events

Invalidate
when the entity has unflipped
public this .unflip(String dir)
dir

Unflip direction

Unflip entity on passed direction (if it's flipped)

-

Example

this.unflip("X")
Back to top

.visible

If the entity is visible or not. Accepts a true or false value. +

Example

this.unflip("X")
Back to top

.visible

If the entity is visible or not. Accepts a true or false value. Can be used for optimization by setting an entities visibility to false when not needed to be drawn.

The entity will still exist and can be collided with but just won't be drawn.

-
Back to top

.w

The width of the entity. When modified, will automatically be redrawn. +

Back to top

.w

The width of the entity. When modified, will automatically be redrawn. Is actually a getter/setter so when using this value for calculations and not modifying it, use the ._w property.

Changing this value is not recommended as canvas has terrible resize quality and DOM will just clip the image.

-

See Also

Back to top

.within

public Boolean .within(Number x, Number y, Number w, Number h)
x

X position of the rect

+

See Also

Back to top

.within

public Boolean .within(Number x, Number y, Number w, Number h)
x

X position of the rect

y

Y position of the rect

w

Width of the rect

h

Height of the rect

-
public Boolean .within(Object rect)
rect

An object that must have the _x, _y, _w, _h values as properties

+
public Boolean .within(Object rect)
rect

An object that must have the _x, _y, _w, _h values as properties

Determines if this current entity is within another rectangle.

-
Back to top

.x

The x position on the stage. When modified, will automatically be redrawn. +

Back to top

.x

The x position on the stage. When modified, will automatically be redrawn. Is actually a getter/setter so when using this value for calculations and not modifying it, use the ._x property.

-

See Also

Back to top

.y

The y position on the stage. When modified, will automatically be redrawn. +

See Also

Back to top

.y

The y position on the stage. When modified, will automatically be redrawn. Is actually a getter/setter so when using this value for calculations and not modifying it, use the ._y property.

-

See Also

Back to top

.z

The z index on the stage. When modified, will automatically be redrawn. +

See Also

Back to top

.z

The z index on the stage. When modified, will automatically be redrawn. Is actually a getter/setter so when using this value for calculations and not modifying it, use the ._z property.

A higher z value will be closer to the front of the stage. A smaller z value will be closer to the back. diff --git a/api/AngularMotion.html b/api/AngularMotion.html new file mode 100644 index 0000000..ba6bef2 --- /dev/null +++ b/api/AngularMotion.html @@ -0,0 +1,109 @@ + + + + Crafty - AngularMotion + + + + + + + + + + +

+
+ + + +
+
+ + + + +

AngularMotion

Events

Rotated [Old rotation = {Number}]
When entity has rotated due to angular velocity/acceleration a Rotated event is triggered.
NewRotationDirection [New direction = {-1 | 0 | 1}]
When entity has changed rotational direction due to rotational velocity a NewRotationDirection event is triggered. The event is triggered once, if direction is different from last frame.
MotionChange [Motion property name and old value = { key: String, oldValue: Number }]
When a motion property has changed a MotionChange event is triggered.

Component that allows rotating an entity by applying angular velocity and acceleration. +All angular motion values are expressed in degrees per second (e.g. an entity with vrotation of 10 will rotate 10 degrees each second).

+

Methods and Properties

Back to top

.arotation

A property for accessing/modifying the angular(rotational) acceleration. +The acceleration increases the velocity over time, resulting in ever increasing speed.

+

Example

var ent = Crafty.e("2D, AngularMotion");
+
+var arotation = ent.arotation; // retrieve the angular acceleration
+ent.arotation += 1; // increase the angular acceleration
+ent.arotation = 0; // reset the angular acceleration
Back to top

.drotation

A number that reflects the change in rotation (difference between the old & new rotation) that was applied in the last frame.

+

Example

var ent = Crafty.e("2D, AngularMotion");
+
+var drotation = ent.drotation; // the change of rotation in the last frame
Back to top

.resetAngularMotion

public this .resetAngularMotion()

Reset all motion (resets velocity, acceleration, motionDelta).

+
Back to top

.vrotation

A property for accessing/modifying the angular(rotational) velocity. +The velocity remains constant over time, unless the acceleration increases the velocity.

+

Example

var ent = Crafty.e("2D, AngularMotion");
+
+var vrotation = ent.vrotation; // retrieve the angular velocity
+ent.vrotation += 1; // increase the angular velocity
+ent.vrotation = 0; // reset the angular velocity
+ +
+
+
+ +
+ + diff --git a/api/AreaMap.html b/api/AreaMap.html new file mode 100644 index 0000000..e0c4595 --- /dev/null +++ b/api/AreaMap.html @@ -0,0 +1,109 @@ + + + + Crafty - AreaMap + + + + + + + + + + +
+
+ + + +
+
+ + + + +

AreaMap

Component used by Mouse and Touch. +Can be added to other entities for use with the Crafty.findClosestEntityByComponent method.

+

Methods and Properties

Back to top

.areaMap

Events

NewAreaMap [Data = {Crafty.polygon}]
when a new areaMap is assigned
public this .areaMap(Crafty.polygon polygon)
polygon

Instance of Crafty.polygon used to check if the mouse coordinates are inside this region

+
public this .areaMap(Array coordinatePairs)
coordinatePairs

Array of x, y coordinate pairs to generate a polygon

+
public this .areaMap(x1, y1,.., xN, yN)
point#

List of x, y coordinate pairs to generate a polygon

+

Assign a polygon to the entity so that pointer (mouse or touch) events will only be triggered if +the coordinates are inside the given polygon.

+

Example

Crafty.e("2D, DOM, Color, Mouse")
+    .color("red")
+    .attr({ w: 100, h: 100 })
+    .bind('MouseOver', function() {Crafty.log("over")})
+    .areaMap(0, 0, 50, 0, 50, 50, 0, 50);
+
+Crafty.e("2D, Mouse")
+    .areaMap([0, 0, 50, 0, 50, 50, 0, 50]);
+
+Crafty.e("2D, Mouse").areaMap(
+    new Crafty.polygon([0, 0, 50, 0, 50, 50, 0, 50])
+);
+ +
+
+
+ +
+ + diff --git a/api/Button.html b/api/Button.html new file mode 100644 index 0000000..037b175 --- /dev/null +++ b/api/Button.html @@ -0,0 +1,93 @@ + + + + Crafty - Button + + + + + + + + + + +
+
+ + + +
+
+ + + + +

Button

Provides the entity with touch or mouse functionality, depending on whether this is a pc +or mobile device, and also on multitouch configuration.

+
+ +
+
+
+ +
+ + diff --git a/api/Canvas.html b/api/Canvas.html index 00029d7..cfa614d 100644 --- a/api/Canvas.html +++ b/api/Canvas.html @@ -55,12 +55,12 @@ -

Canvas

Events

Draw [ Data { {type: "canvas", pos, co, ctx} }]
when the entity is ready to be drawn to the stage
NoCanvas
if the browser does not support canvas

When this component is added to an entity it will be drawn to the global canvas element. The canvas element (and hence all Canvas entities) is always rendered below any DOM entities.

-

Crafty.canvas.init() will be automatically called if it is not called already to initialize the canvas element.

+

Canvas

Events

Draw [Data = {type: "canvas", pos, co, ctx}]
when the entity is ready to be drawn to the stage
NoCanvas
if the browser does not support canvas

When this component is added to an entity it will be drawn to the global canvas element. The canvas element (and hence all Canvas entities) is always rendered below any DOM entities.

+

Crafty.canvasLayer.init() will be automatically called if it is not called already to initialize the canvas element.

Create a canvas entity like this

var myEntity = Crafty.e("2D, Canvas, Color")
      .color("green")
-     .attr({x: 13, y: 37, w: 42, h: 42});

Methods and Properties

Back to top

.draw

public this .draw([[Context ctx, ]Number x, Number y, Number w, Number h])
ctx

Canvas 2D context if drawing on another canvas is required

+ .attr({x: 13, y: 37, w: 42, h: 42});

Methods and Properties

Back to top

.draw

public this .draw([[Context ctx, ]Number x, Number y, Number w, Number h])
ctx

Canvas 2D context if drawing on another canvas is required

x

X offset for drawing a segment

y

Y offset for drawing a segment

w

Width of the segment to draw

diff --git a/api/Collision.html b/api/Collision.html index 8553d97..4a00710 100644 --- a/api/Collision.html +++ b/api/Collision.html @@ -55,22 +55,15 @@ -

Collision

Events

HitOn [ Data { { hitData } }]
Triggered when collisions occur. Will not trigger again until collisions of this type cease, or an event is requested once more (using `resetHitChecks(component)`).
HitOff [ Data { { componentName } }]
Triggered when collision with a specific component type ceases

Component to detect collision between any two convex polygons.

+

Collision

Events

HitOn [Data = { hitData }]
Triggered when collisions occur. Will not trigger again until collisions of this type cease, or an event is requested once more (using `resetHitChecks(component)`).
HitOff [componentName = {String}]
Triggered when collision with a specific component type ceases

Component to detect collision between any two convex polygons.

If collision checks are registered for multiple component and collisions with multiple types occur simultaniously, each collision will cause an individual event to fire.

-

Note: All data received from events is only valid for the duration of the event's callback. -If you wish to preserve the data, make a copy of it.

-

For a description of collision event data (hitData above), see the documentation for +

Note: All data received from events is only valid for the duration of the event's callback. If you wish to preserve the data, make a copy of it.

+

For a description of collision event data (hitData above), see the documentation for .hit().

-

Methods and Properties

Back to top

._createCollisionHandler

public void .checkHits(String component, Object collisionData)
component

The name of the component for which this handler

-

checks for collisions.

-
collisionData

Collision data object used to track collisions with

-

the specified component.

-

This is a helper method for creating collisions handlers set up by -.checkHits(...). Do not call this directly.

-

See Also

Back to top

.checkHits

public this .checkHits(String componentList)
componentList

A comma seperated list of components to check for collisions with.

-
public this .checkHits(String component1[, .., String componentN])
component#

A component to check for collisions with.

+

Methods and Properties

Back to top

.checkHits

public this .checkHits(String componentList)
componentList

A comma seperated list of components to check for collisions with.

+
public this .checkHits(String component1[, .., String componentN])
component#

A component to check for collisions with.

Performs collision checks against all entities that have at least one of the components specified when calling this method. If collisions occur, a "HitOn" event containing the collision information will be fired for the @@ -80,35 +73,34 @@ will be fired.

Calling this method more than once for the same component type will not cause redundant hit checks.

-

Note: Hit checks are performed upon entering each new frame (using -the EnterFrame event). It is entirely possible for object to move in -said frame after the checks were performed (even if the more is the -result of EnterFrame, as handlers run in no particular order). In such -a case, the hit events will not fire until the next check is performed in -the following frame.

-

Example

Crafty.e("2D, Collision")
+

If you want more fine-grained control consider using .hit() or even Crafty.map.search().

+

Note: Hit checks are performed upon entering each new frame (using the EnterFrame event). It is entirely possible for object to move in said frame after the checks were performed (even if the more is the result of EnterFrame, as handlers run in no particular order). In such a case, the hit events will not fire until the next check is performed in the following frame.

+

Example

Crafty.e("2D, Collision")
     .checkHits('Solid') // check for collisions with entities that have the Solid component in each frame
-    .bind("HitOn", function(hitData) {
-        console.log("Collision with Solid entity occurred for the first time.");
+    .bind("HitOn", function(hitData) {
+        Crafty.log("Collision with Solid entity occurred for the first time.");
     })
-    .bind("HitOff", function(comp) {
-        console.log("Collision with Solid entity ended.");
-    });

See Also

Back to top

.collision

Events

NewHitbox [ Data { Crafty.polygon }]
when a new hitbox is assigned
public this .collision([Crafty.polygon polygon])
polygon

Crafty.polygon object that will act as the hit area.

-
public this .collision(Array point1, .., Array pointN)
point#

Array of [x, y] coordinate pairs to generate a hit area polygon.

-

Constructor that takes a polygon or array of points to use as the hit area, + .bind("HitOff", function(comp) { + Crafty.log("Collision with Solid entity ended."); + });

See Also

Back to top

.collision

Events

NewHitbox [Data = {Crafty.polygon}]
when a new hitbox is assigned
public this .collision([Crafty.polygon polygon])
polygon

Optional Crafty.polygon object that will act as the hit area.

+
public this .collision([Array coordinatePairs])
coordinatePairs

Optional array of x, y coordinate pairs to generate a hit area polygon.

+
public this .collision([x1, y1,.., xN, yN])
point#

Optional list of x, y coordinate pairs to generate a hit area polygon.

+

Constructor that takes a polygon, an array of points or a list of points to use as the hit area, with points being relative to the object's position in its unrotated state.

The hit area must be a convex shape and not concave for collision detection to work properly.

If no parameter is passed, the x, y, w, h properties of the entity will be used, and the hitbox will be resized when the entity is.

If a hitbox is set that is outside of the bounds of the entity itself, there will be a small performance penalty as it is tracked separately.

+

In order for your custom hitbox to have any effect, you have to add the Collision component to all other entities this entity needs to collide with using this custom hitbox. +On the contrary the collisions will be resolved using the default hitbox. See .hit() - MBR represents default hitbox collision, SAT represents custom hitbox collision.

Example

Crafty.e("2D, Collision").collision(
-    new Crafty.polygon([50,0], [100,100], [0,100])
+    new Crafty.polygon([50, 0,  100, 100,  0, 100])
 );
 
-Crafty.e("2D, Collision").collision([50,0], [100,100], [0,100]);
Back to top

.hit

public Boolean/Array hit(String component)
component

Check collision with entities that have this component

-

applied to them.

-
[Returns]

false if there is no collision. If a collision is detected,

-

returns an Array of collision data objects (see below).

-

Tests for collisions with entities that have the specified component +Crafty.e("2D, Collision").collision([50, 0, 100, 100, 0, 100]); + +Crafty.e("2D, Collision").collision(50, 0, 100, 100, 0, 100);

Back to top

.hit

public Boolean/Array hit(String component)
component

Check collision with entities that have this component applied to them.

+
[Returns]

false if there is no collision. If a collision is detected, returns an Array of collision data objects (see below).

+

Tests for collisions with entities that have the specified component applied to them. If a collision is detected, data regarding the collision will be present in the array returned by this method. @@ -120,16 +112,19 @@ obj: [entity], type: ["MBR" or "SAT"], overlap: [number] -}]

obj: The entity with which the collision occured. -type: Collision detection method used. One of:

-
    +}]
      +
    • obj: The entity with which the collision occured.
    • +
    • type: Collision detection method used. One of:
      • MBR: Standard axis aligned rectangle intersection (.intersect in the 2D component).
      • -
      • SAT: Collision between any two convex polygons. Used when both colliding entities have the Collision component applied to them. -overlap: If SAT collision was used, this will signify the overlap percentage between the colliding entities.
      • +
      • SAT: Collision between any two convex polygons. Used when both colliding entities have the Collision component applied to them.
      • +
      +
    • +
    • overlap: If SAT collision was used, this will signify the overlap percentage between the colliding entities.
    -

    See Also

Back to top

.ignoreHits

public this .ignoreHits()
public this .ignoreHits(String componentList)
componentList

A comma seperated list of components to stop checking

-

for collisions with.

-
public this .ignoreHits(String component1[, .., String componentN])
component#

A component to stop checking for collisions with.

+

Keep in mind that both entities need to have the Collision component, if you want to check for SAT (custom hitbox) collisions between them.

+

If you want more fine-grained control consider using Crafty.map.search().

+

See Also

Back to top

.ignoreHits

public this .ignoreHits()
public this .ignoreHits(String componentList)
componentList

A comma separated list of components to stop checking for collisions with.

+
public this .ignoreHits(String component1[, .., String componentN])
component#

A component to stop checking for collisions with.

Stops checking for collisions with all, or certain, components. If called without arguments, this method will cause all collision checks on the entity to cease. To disable checks for collisions with specific @@ -140,19 +135,14 @@

Example

Crafty.e("2D, Collision")
     .checkHits('Solid')
     ...
-    .ignoreHits('Solid'); // stop checking for collisions with entities that have the Solid component
Back to top

.init

Set up collision handling.

-

By default, the collision hitbox will match the dimensions (x, y, w, h) and rotation of the object.

-

Note: If the entity this component is applied to does not have its -dimensions set the default hit area will not be set properly.

-
Back to top

.onHit

public this .onHit(String component, Function hit[, Function noHit])
component

Component to check collisions for.

-
hit

Callback method to execute upon collision with component. Will be passed the results of the collision check in the same format documented for hit().

-
noHit

Callback method executed once as soon as collision stops.

-

Creates an EnterFrame event calling .hit() each frame. When a collision is detected the callback will be invoked. -Note that the hit callback will be invoked every frame the collision is active, not just the first time the collision occurs. -If you want more fine-grained control consider using .checkHits or .hit.

-
Back to top

.resetHitChecks

public this .resetHitChecks()
public this .resetHitChecks(String componentList)
componentList

A comma seperated list of components to re-check

-

for collisions with.

-
public this .resetHitChecks(String component1[, .., String componentN])
component#

A component to re-check for collisions with.

+ .ignoreHits('Solid'); // stop checking for collisions with entities that have the Solid component
Back to top

.onHit

public this .onHit(String component, Function callbackOn[, Function callbackOff])
component

Component to check collisions for.

+
callbackOn

Callback method to execute upon collision with component. Will be passed the results of the collision check in the same format documented for hit().

+
callbackOff

Callback method executed once as soon as collision stops.

+

Creates an EnterFrame event calling .hit() each frame. When a collision is detected the callbackOn will be invoked. +Note that the callbackOn will be invoked every frame the collision is active, not just the first time the collision occurs.

+

If you want more fine-grained control consider using .checkHits(), .hit() or even Crafty.map.search().

+
Back to top

.resetHitChecks

public this .resetHitChecks()
public this .resetHitChecks(String componentList)
componentList

A comma seperated list of components to re-check for collisions with.

+
public this .resetHitChecks(String component1[, .., String componentN])
component#

A component to re-check for collisions with.

Causes collision events to be received for collisions that are already taking place (normally, an additional event would not fire before said collisions cease and happen another time). @@ -165,8 +155,8 @@

Example

// this example fires the HitOn event each frame the collision with the Solid entity is active, instead of just the first time the collision occurs.
 Crafty.e("2D, Collision")
     .checkHits('Solid')
-    .bind("HitOn", function(hitData) {
-        console.log("Collision with Solid entity was reported in this frame again!");
+    .bind("HitOn", function(hitData) {
+        Crafty.log("Collision with Solid entity was reported in this frame again!");
         this.resetHitChecks('Solid'); // fire the HitOn event in the next frame also, if the collision is still active.
     })
diff --git a/api/Color.html b/api/Color.html index 467d808..7269789 100644 --- a/api/Color.html +++ b/api/Color.html @@ -55,16 +55,16 @@ -

Color

Draw a colored rectangle.

-

Methods and Properties

Back to top

.color

Events

Invalidate
when the color changes

Will assign the color and opacity, either through a string shorthand, or through explicit rgb values.

-
public this .color(String color[, Float strength])
color

Color of the rectangle

+

Color

Draw a colored rectangle.

+

Methods and Properties

Back to top

.color

Events

Invalidate
when the color changes

Will assign the color and opacity, either through a string shorthand, or through explicit rgb values.

+
public this .color(String color[, Float strength])
color

Color of the rectangle

strength

the opacity of the rectangle

-
public this .color(r, g, b[, strength])
r

value for the red channel

+
public this .color(r, g, b[, strength])
r

value for the red channel

g

value for the green channel

b

value for the blue channel

strength

the opacity of the rectangle

-
public String .color()
[Returns]

A string representing the current color as a CSS property.

-

Example

var c = Crafty.e("2D, DOM, Color");
+
public String .color()
[Returns]

A string representing the current color as a CSS property.

+

Example

var c = Crafty.e("2D, DOM, Color");
 c.color("#FF0000");
 c.color("red");
 c.color(255, 0, 0);
diff --git a/api/Crafty Core.html b/api/Crafty Core.html
index d5bddcc..6282ee9 100644
--- a/api/Crafty Core.html	
+++ b/api/Crafty Core.html	
@@ -55,9 +55,9 @@
 
 
 
-

Crafty Core

Events

NewEntityName [ entity name { String }]
After setting new name for entity
NewComponent [ Component { String }]
when a new component is added to the entity
RemoveComponent [ Component { String }]
when a component is removed from the entity
Remove
when the entity is removed by calling .destroy()

Set of methods added to every single entity.

-

Methods and Properties

Back to top

.addComponent

public this .addComponent(String componentList)
componentList

A string of components to add separated by a comma ,

-
public this .addComponent(String Component1[, .., String ComponentN])
Component#

Component ID to add.

+

Crafty Core

Events

NewEntityName [entity name = {String}]
After setting new name for entity
NewComponent [Component = {String}]
when a new component is added to the entity
RemoveComponent [Component = {String}]
when a component is removed from the entity
Remove
when the entity is removed by calling .destroy()

A set of methods added to every single entity.

+

Methods and Properties

Back to top

.addComponent

public this .addComponent(String componentList)
componentList

A string of components to add separated by a comma ,

+
public this .addComponent(String Component1[, .., String ComponentN])
Component#

Component ID to add.

Adds a component to the selected entities or entity.

Components are used to extend the functionality of entities. This means it will copy properties and assign methods to @@ -68,19 +68,21 @@

If the component has a function named init it will be called.

If the entity already has the component, the component is skipped (nothing happens).

Example

this.addComponent("2D, Canvas");
-this.addComponent("2D", "Canvas");
Back to top

.attr

Events

Change [ Data { {key: value} }]
when properties change
public this .attr(String property, Any value[, Boolean silent[, Boolean recursive]])
property

Property of the entity to modify

+this.addComponent("2D", "Canvas");
Back to top

.attr

Events

Change [Data = {key: value}]
when properties change
public this .attr(String property, Any value[, Boolean silent[, Boolean recursive]])
property

Property of the entity to modify

value

Value to set the property to

silent

If you would like to supress events

recursive

If you would like merge recursively

Use this method to set any property of the entity.

-
public this .attr(Object map[, Boolean silent[, Boolean recursive]])
map

Object where each key is the property to modify and the value as the property value

+
public this .attr(Object map[, Boolean silent[, Boolean recursive]])
map

Object where each key is the property to modify and the value as the property value

silent

If you would like to supress events

recursive

If you would like merge recursively

Use this method to set multiple properties of the entity.

-

Setter options: -silent: If you want to prevent it from firing events. -recursive: If you pass in an object you could overwrite sibling keys, this recursively merges instead of just merging it. This is false by default, unless you are using dot notation name.first.

-
public Any .attr(String property)
property

Property of the entity to modify

+

Setter options:

+
    +
  • silent: If you want to prevent it from firing events.
  • +
  • recursive: If you pass in an object you could overwrite sibling keys, this recursively merges instead of just merging it. This is false by default, unless you are using dot notation name.first.
  • +
+
public Any .attr(String property)
property

Property of the entity to modify

[Returns]

Value - the value of the property

Use this method to get any property of the entity. You can also retrieve the property using this.property.

Example

this.attr({key: "value", prop: 5});
@@ -95,7 +97,7 @@
 
 this.attr("parent.child", "newvalue");
 this.parent; // {child: "newvalue"};
-this.attr('parent.child'); // "newvalue"
Back to top

.bind

public this .bind(String eventName, Function callback)
eventName

Name of the event to bind to

+this.attr('parent.child'); // "newvalue"
Back to top

.bind

public this .bind(String eventName, Function callback)
eventName

Name of the event to bind to

callback

Method to execute when the event is triggered

Attach the current entity (or entities) to listen for an event.

Callback will be invoked when an event with the event name passed @@ -106,56 +108,72 @@ callback should have an argument.

Events are arbitrary and provide communication between components. You can trigger or bind an event even if it doesn't exist yet.

-

Unlike DOM events, Crafty events are exectued synchronously.

+

Unlike DOM events, Crafty events are executed synchronously.

Example

this.attr("triggers", 0); //set a trigger count
-this.bind("myevent", function() {
+this.bind("myevent", function() {
     this.triggers++; //whenever myevent is triggered, increment
 });
-this.bind("EnterFrame", function() {
+this.bind("EnterFrame", function() {
     this.trigger("myevent"); //trigger myevent on every frame
-});
Back to top

.clone

public Entity .clone(void)
[Returns]

Cloned entity of the current entity

+});
Back to top

.clone

public Entity .clone(void)
[Returns]

Cloned entity of the current entity

Method will create another entity with the exact same properties, components and methods as the current entity.

-
Back to top

.destroy

public this .destroy(void)

Will remove all event listeners and delete all properties as well as removing from the stage

-
Back to top

.each

public this .each(Function method)
method

Method to call on each iteration

+
Back to top

.defineField

public this .defineField(String property, Function getCallback, Function setCallback)
property

Property name to assign getter & setter to

+
getCallback

Method to execute if the property is accessed

+
setCallback

Method to execute if the property is mutated

+

Assigns getters and setters to the property. +A getter will watch a property waiting for access and will then invoke the +given getCallback when attempting to retrieve. +A setter will watch a property waiting for mutation and will then invoke the +given setCallback when attempting to modify.

+

Example

var ent = Crafty.e("2D");
+ent.defineField("customData", function() {
+   return this._customData;
+}, function(newValue) {
+   this._customData = newValue;
+});
+
+ent.customData = "2" // set customData to 2
+Crafty.log(ent.customData) // prints 2
Back to top

.destroy

public this .destroy(void)

Will remove all event listeners and delete all properties as well as removing from the stage

+
Back to top

.each

public this .each(Function method)
method

Method to call on each iteration

Iterates over found entities, calling a function for every entity.

The function will be called for every entity and will pass the index in the iteration as an argument. The context (value of this) of the function will be the current entity in the iteration.

Example

Destroy every second 2D entity

-
Crafty("2D").each(function(i) {
+
Crafty("2D").each(function(i) {
     if(i % 2 === 0) {
         this.destroy();
     }
-});
Back to top

.get

public Array .get()
[Returns]

An array of entities corresponding to the active selector

-
public Entity .get(Number index)
[Returns]

an entity belonging to the current selection

+});
Back to top

.get

public Array .get()
[Returns]

An array of entities corresponding to the active selector

+
public Entity .get(Number index)
[Returns]

an entity belonging to the current selection

index

The index of the entity to return. If negative, counts back from the end of the array.

-

Example

Get an array containing every "2D" entity

+

Example

Get an array containing every "2D" entity

var arr = Crafty("2D").get()

Get the first entity matching the selector

// equivalent to Crafty("2D").get()[0], but doesn't create a new array
 var e = Crafty("2D").get(0)

Get the last "2D" entity matching the selector

-
var e = Crafty("2D").get(-1)
Back to top

.getId

public Number .getId(void)

Returns the ID of this entity.

-

For better performance, simply use the this[0] property.

+
var e = Crafty("2D").get(-1)
Back to top

.getId

public Number .getId(void)
[Returns]

the ID of this entity.

+

For better performance, simply use the this[0] property.

Example

Finding out the ID of an entity can be done by returning the property 0.

   var ent = Crafty.e("2D");
    ent[0]; //ID
-   ent.getId(); //also ID
Back to top

.has

public Boolean .has(String component)

Returns true or false depending on if the -entity has the given component.

-

For better performance, simply use the .__c object + ent.getId(); //also ID

Back to top

.has

public Boolean .has(String component)
component

The name of the component to check

+
[Returns]

true or false depending on if the entity has the given component.

+

For better performance, simply use the .__c object which will be true if the entity has the component or will not exist (or be false).

-
Back to top

.one

public Number one(String eventName, Function callback)
eventName

Name of the event to bind to

+
Back to top

.one

public Number one(String eventName, Function callback)
eventName

Name of the event to bind to

callback

Method to execute upon event triggered

[Returns]

ID of the current callback used to unbind

Works like Crafty.bind, but will be unbound once the event triggers.

-

See Also

Back to top

.removeComponent

public this .removeComponent(String Component[, soft])
component

Component to remove

+

See Also

Back to top

.removeComponent

public this .removeComponent(String Component[, soft])
component

Component to remove

soft

Whether to soft remove it (defaults to true)

Removes a component from an entity. A soft remove (the default) will only refrain .has() from returning true. Hard will remove all associated properties and methods.

Example

var e = Crafty.e("2D,DOM,Test");
 e.removeComponent("Test");        //Soft remove Test component
-e.removeComponent("Test", false); //Hard remove Test component
Back to top

.requires

public this .requires(String componentList)
componentList

List of components that must be added

+e.removeComponent("Test", false); //Hard remove Test component
Back to top

.requires

public this .requires(String componentList)
componentList

List of components that must be added

Makes sure the entity has the components listed. If the entity does not have the component, it will add it.

(In the current version of Crafty, this function behaves exactly the same @@ -163,28 +181,29 @@ component dependencies -- i.e. to indicate specifically that one component will only work properly if another component is present -- and used addComponent in all other situations.)

-
Back to top

.setName

public this .setName(String name)
name

A human readable name for debugging purposes.

-

Example

this.setName("Player");
Back to top

.setter

public this .setter(String property, Function callback)
property

Property to watch for modification

+
Back to top

.setName

public this .setName(String name)
name

A human readable name for debugging purposes.

+

Example

this.setName("Player");
Back to top

.setter

public this .setter(String property, Function callback)
property

Property to watch for modification

callback

Method to execute if the property is modified

Will watch a property waiting for modification and will then invoke the given callback when attempting to modify.

-
Back to top

.timeout

public this .timeout(Function callback, Number delay)
callback

Method to execute after given amount of milliseconds

+

This feature is deprecated; use .defineField() instead.

+

See Also

Back to top

.timeout

public this .timeout(Function callback, Number delay)
callback

Method to execute after given amount of milliseconds

delay

Amount of milliseconds to execute the method

The delay method will execute a function after a given amount of time in milliseconds.

Essentially a wrapper for setTimeout.

Example

Destroy itself after 100 milliseconds

-
this.timeout(function() {
+
this.timeout(function() {
 this.destroy();
-}, 100);
Back to top

.toArray

public this .toArray(void)

This method will simply return the found entities as an array of ids. To get an array of the actual entities, use get().

-

See Also

Back to top

.toggleComponent

public this .toggleComponent(String ComponentList)
ComponentList

A string of components to add or remove separated by a comma ,

-
public this .toggleComponent(String Component1[, .., String componentN])
Component#

Component ID to add or remove.

+}, 100);
Back to top

.toArray

public this .toArray(void)

This method will simply return the found entities as an array of ids. To get an array of the actual entities, use get().

+

See Also

Back to top

.toggleComponent

public this .toggleComponent(String ComponentList)
ComponentList

A string of components to add or remove separated by a comma ,

+
public this .toggleComponent(String Component1[, .., String componentN])
Component#

Component ID to add or remove.

Add or Remove Components from an entity.

Example

var e = Crafty.e("2D,DOM,Test");
 e.toggleComponent("Test,Test2"); //Remove Test, add Test2
 e.toggleComponent("Test,Test2"); //Add Test, remove Test2
var e = Crafty.e("2D,DOM,Test");
 e.toggleComponent("Test","Test2"); //Remove Test, add Test2
 e.toggleComponent("Test","Test2"); //Add Test, remove Test2
-e.toggleComponent("Test");         //Remove Test
Back to top

.trigger

public this .trigger(String eventName[, Object data])
eventName

Event to trigger

+e.toggleComponent("Test"); //Remove Test
Back to top

.trigger

public this .trigger(String eventName[, Object data])
eventName

Event to trigger

data

Arbitrary data that will be passed into every callback as an argument

Trigger an event with arbitrary data. Will invoke all callbacks with the context (value of this) of the current entity object.

@@ -192,13 +211,13 @@

The first argument is the event name to trigger and the optional second argument is the arbitrary event data. This can be absolutely anything.

Unlike DOM events, Crafty events are exectued synchronously.

-
Back to top

.unbind

public this .unbind(String eventName[, Function callback])
eventName

Name of the event to unbind

+
Back to top

.unbind

public this .unbind(String eventName[, Function callback])
eventName

Name of the event to unbind

callback

Function to unbind

Removes binding with an event from current entity.

Passing an event name will remove all events bound to that event. Passing a reference to the callback will unbind only that callback.

-
Back to top

.uniqueBind

public Number .uniqueBind(String eventName, Function callback)
eventName

Name of the event to bind to

+
Back to top

.uniqueBind

public Number .uniqueBind(String eventName, Function callback)
eventName

Name of the event to bind to

callback

Method to execute upon event triggered

[Returns]

ID of the current callback used to unbind

Works like Crafty.bind, but prevents a callback from being bound multiple times.

diff --git a/api/Crafty-HashMap.html b/api/Crafty-HashMap.html index a5c8079..1f1ca2c 100644 --- a/api/Crafty-HashMap.html +++ b/api/Crafty-HashMap.html @@ -55,15 +55,15 @@ -

Crafty.HashMap

Broad-phase collision detection engine. See background information at

+

Crafty.HashMap

Methods and Properties

Back to top

Crafty.HashMap.constructor

public void Crafty.HashMap([cellsize])
cellsize

the cell size. If omitted, cellsize is 64.

+

See Also

Methods and Properties

Back to top

Crafty.HashMap.constructor

public void Crafty.HashMap([cellsize])
cellsize

the cell size. If omitted, cellsize is 64.

Set cellsize. And create this.map.

-
Back to top

Crafty.HashMap.key

public Object Crafty.HashMap.key(Object obj)
obj

an Object that has .mbr() or _x, _y, _w and _h.

+
Back to top

Crafty.HashMap.key

public Object Crafty.HashMap.key(Object obj)
obj

an Object that has .mbr() or _x, _y, _w and _h.

Get the rectangular region (in terms of the grid, with grid size cellsize), where the object may fall in. This region is determined by the object's bounding box. The cellsize is 64 by default.

See Also

diff --git a/api/Crafty-addEvent.html b/api/Crafty-addEvent.html index ba95cd9..2ed3bf0 100644 --- a/api/Crafty-addEvent.html +++ b/api/Crafty-addEvent.html @@ -55,7 +55,7 @@ -

Crafty.addEvent

public this Crafty.addEvent(Object ctx, HTMLElement obj, String event, Function callback)
ctx

Context of the callback or the value of this

+

Crafty.addEvent

public this Crafty.addEvent(Object ctx, HTMLElement obj, String event, Function callback)
ctx

Context of the callback or the value of this

obj

Element to add the DOM event to

event

Event name to bind to

callback

Method to execute when triggered

@@ -65,11 +65,13 @@ finally the callback method.

If no element is passed, the default element will be window.document.

Callbacks are passed with event data.

-

Example

Will add a stage-wide MouseDown event listener to the player. Will log which button was pressed -& the (x,y) coordinates in viewport/world/game space.

+

Note: This is related to DOM events only, not Crafty's own event system. Of course, you can trigger Crafty events in the callback function!

+

Example

Normally you'd use Crafty's built-in mouse component, but for the sake of an example let's pretend that doesn't exist. +The following code will add a stage-wide MouseDown event listener to the player, and log both which button was pressed +and the (x,y) coordinates in viewport/world/game space.

var player = Crafty.e("2D");
-    player.onMouseDown = function(e) {
-        console.log(e.mouseButton, e.realX, e.realY);
+    player.onMouseDown = function(e) {
+        Crafty.log(e.mouseButton, e.realX, e.realY);
     };
 Crafty.addEvent(player, Crafty.stage.elem, "mousedown", player.onMouseDown);
diff --git a/api/Crafty-asset.html b/api/Crafty-asset.html index 7576559..7256f8e 100644 --- a/api/Crafty-asset.html +++ b/api/Crafty-asset.html @@ -55,10 +55,10 @@ -

Crafty.asset

Events

NewAsset [ key and value of new added asset. { Object }]
After setting new asset
public void Crafty.asset(String key, Object asset)
key

asset url.

+

Crafty.asset

Events

NewAsset [key and value of new added asset. = {Object}]
After setting new asset
public void Crafty.asset(String key, Object asset)
key

asset url.

asset

Audio or Image object.

Add new asset to assets object.

-
public void Crafty.asset(String key)
key

asset url.

+
public void Crafty.asset(String key)
key

asset url.

Get asset from assets object.

Example

Crafty.asset(key, value);
 var asset = Crafty.asset(key); //object with key and value fields
diff --git a/api/Crafty-assets.html b/api/Crafty-assets.html index 1f5b650..ffb9e41 100644 --- a/api/Crafty-assets.html +++ b/api/Crafty-assets.html @@ -55,10 +55,10 @@ -

Crafty.assets

An object containing every asset used in the current Crafty game. +

Crafty.assets

An object containing every asset used in the current Crafty game. The key is the URL and the value is the Audio or Image object.

If loading an asset, check that it is in this object first to avoid loading twice.

-

Example

var isLoaded = !!Crafty.assets["images/sprite.png"];
+

Example

var isLoaded = !!Crafty.assets["images/sprite.png"];

See Also

diff --git a/api/Crafty-assignColor.html b/api/Crafty-assignColor.html index 579aff8..5363410 100644 --- a/api/Crafty-assignColor.html +++ b/api/Crafty-assignColor.html @@ -55,11 +55,10 @@ -

Crafty.assignColor

Crafty.assignColor(color[, assignee])
color

a string represenation of the color to assign, in any valid HTML format

+

Crafty.assignColor

Crafty.assignColor(color[, assignee])
color

a string represenation of the color to assign, in any valid HTML format

assignee

an object to use instead of creating one from scratch

-
[Returns]

An object with _red, _green, and _blue properties assigned.

-
      Potentially with `_strength` representing the alpha channel.
-      If the assignee parameter is passed, that object will be assigned those values and returned.
+
[Returns]

An object with _red, _green, and _blue properties assigned. Potentially with _strength representing the alpha channel. If the assignee parameter is passed, that object will be assigned those values and returned.

+
diff --git a/api/Crafty-audio.html b/api/Crafty-audio.html index 1cec0fe..0e72cd2 100644 --- a/api/Crafty-audio.html +++ b/api/Crafty-audio.html @@ -55,16 +55,16 @@ -

Crafty.audio

Add sound files and play them. Chooses best format for browser support. +

Crafty.audio

Add sound files and play them. Chooses best format for browser support. Due to the nature of HTML5 audio, three types of audio files will be required for cross-browser capabilities. These formats are MP3, Ogg and WAV. When sound was not muted on before pause, sound will be unmuted after unpause. When sound is muted Crafty.pause() does not have any effect on sound

The maximum number of sounds that can be played simultaneously is defined by Crafty.audio.maxChannels. The default value is 7.

-

Methods and Properties

Back to top

Crafty.audio.add

public this Crafty.audio.add(String id, String url)
id

A string to refer to sounds

+

Methods and Properties

Back to top

Crafty.audio.add

public this Crafty.audio.add(String id, String url)
id

A string to refer to sounds

url

A string pointing to the sound file

-
public this Crafty.audio.add(String id, Array urls)
urls

Array of urls pointing to different format of the same sound, selecting the first that is playable

-
public this Crafty.audio.add(Object map)
map

key-value pairs where the key is the id and the value is either a url or urls

+
public this Crafty.audio.add(String id, Array urls)
urls

Array of urls pointing to different format of the same sound, selecting the first that is playable

+
public this Crafty.audio.add(Object map)
map

key-value pairs where the key is the id and the value is either a url or urls

Loads a sound to be played. Due to the nature of HTML5 audio, three types of audio files will be required for cross-browser capabilities. These formats are MP3, Ogg and WAV.

@@ -87,17 +87,17 @@ ]); //only one format -Crafty.audio.add("jump", "sounds/jump.mp3");
Back to top

Crafty.audio.create

public this Crafty.audio.create(String id, String url)
id

A string to refer to sounds

+Crafty.audio.add("jump", "sounds/jump.mp3");
Back to top

Crafty.audio.create

public this Crafty.audio.create(String id, String url)
id

A string to refer to sounds

url

A string pointing to the sound file

Creates an audio asset with the given id and resource. Crafty.audio.add is a more flexible interface that allows cross-browser compatibility.

If the sound file extension is not supported, returns false; otherwise, returns the audio asset.

-
Back to top

Crafty.audio.isPlaying

public Boolean Crafty.audio.isPlaying(string ID)
{string} id

The id of the audio object

+
Back to top

Crafty.audio.isPlaying

public Boolean Crafty.audio.isPlaying(string ID)
{string} id

The id of the audio object

[Returns]

a Boolean indicating whether the audio is playing or not

Check if audio with the given ID is playing or not (on at least one channel).

-

Example

var isPlaying = Crafty.audio.isPlaying('music');
Back to top

Crafty.audio.mute

public this Crafty.audio.mute()

Mute every Audio instance that is playing.

-

Example

Crafty.audio.mute();
Back to top

Crafty.audio.pause

public this Crafty.audio.pause(string ID)
{string} id

The id of the audio object to pause

+

Example

var isPlaying = Crafty.audio.isPlaying('music');
Back to top

Crafty.audio.mute

public this Crafty.audio.mute()

Mute every Audio instance that is playing.

+

Example

Crafty.audio.mute();
Back to top

Crafty.audio.pause

public this Crafty.audio.pause(string ID)
{string} id

The id of the audio object to pause

Pause the Audio instance specified by id param.

-

Example

Crafty.audio.pause('music');
Back to top

Crafty.audio.play

public this Crafty.audio.play(String id)
public this Crafty.audio.play(String id, Number repeatCount)
public this Crafty.audio.play(String id, Number repeatCount, Number volume)
id

A string to refer to sounds

+

Example

Crafty.audio.pause('music');
Back to top

Crafty.audio.play

public this Crafty.audio.play(String id)
public this Crafty.audio.play(String id, Number repeatCount)
public this Crafty.audio.play(String id, Number repeatCount, Number volume)
id

A string to refer to sounds

repeatCount

Repeat count for the file, where -1 stands for repeat forever.

volume

volume can be a number between 0.0 and 1.0

[Returns]

The audio element used to play the sound. Null if the call failed due to a lack of open channels.

@@ -108,22 +108,22 @@ //play and repeat forever Crafty.audio.play("backgroundMusic", -1); -Crafty.audio.play("explosion",1,0.5); //play sound once with volume of 50%
Back to top

Crafty.audio.remove

public this Crafty.audio.remove([String id])
id

A string to refer to sounds

+Crafty.audio.play("explosion",1,0.5); //play sound once with volume of 50%
Back to top

Crafty.audio.remove

public this Crafty.audio.remove([String id])
id

A string to refer to sounds

Will stop the sound and remove all references to the audio object allowing the browser to free the memory. If no id is given, all sounds will be removed.

This function uses audio path set in Crafty.path in order to remove sound from the assets object.

-

Example

Crafty.audio.remove("walk");
Back to top

Crafty.audio.setChannels

public this Crafty.audio.setChannels(Number n)
n

The maximum number of channels

-
Back to top

Crafty.audio.stop

public this Crafty.audio.stop([Number ID])

Stops any playing sound. if id is not set, stop all sounds which are playing

+

Example

Crafty.audio.remove("walk");
Back to top

Crafty.audio.setChannels

public this Crafty.audio.setChannels(Number n)
n

The maximum number of channels

+
Back to top

Crafty.audio.stop

public this Crafty.audio.stop([Number ID])

Stops any playing sound. if id is not set, stop all sounds which are playing

Example

//all sounds stopped playing now
-Crafty.audio.stop();
Back to top

Crafty.audio.supports

public this Crafty.audio.supports(String extension)
extension

A file extension to check audio support for

+Crafty.audio.stop();
Back to top

Crafty.audio.supports

public this Crafty.audio.supports(String extension)
extension

A file extension to check audio support for

Return true if the browser thinks it can play the given file type, otherwise false

-
Back to top

Crafty.audio.toggleMute

public this Crafty.audio.toggleMute()

Mute or unmute every Audio instance that is playing. Toggles between +

Back to top

Crafty.audio.toggleMute

public this Crafty.audio.toggleMute()

Mute or unmute every Audio instance that is playing. Toggles between pausing or playing depending on the state.

Example

//toggle mute and unmute depending on current state
-Crafty.audio.toggleMute();
Back to top

Crafty.audio.togglePause

public this Crafty.audio.togglePause(string ID)
{string} id

The id of the audio object to pause/

+Crafty.audio.toggleMute();
Back to top

Crafty.audio.togglePause

public this Crafty.audio.togglePause(string ID)
{string} id

The id of the audio object to pause/

Toggle the pause status of the Audio instance specified by id param.

-

Example

Crafty.audio.togglePause('music');
Back to top

Crafty.audio.unmute

public this Crafty.audio.unmute()

Unmute every Audio instance that is playing.

-

Example

Crafty.audio.unmute();
Back to top

Crafty.audio.unpause

public this Crafty.audio.unpause(string ID)
{string} id

The id of the audio object to unpause

+

Example

Crafty.audio.togglePause('music');
Back to top

Crafty.audio.unmute

public this Crafty.audio.unmute()

Unmute every Audio instance that is playing.

+

Example

Crafty.audio.unmute();
Back to top

Crafty.audio.unpause

public this Crafty.audio.unpause(string ID)
{string} id

The id of the audio object to unpause

Resume playing the Audio instance specified by id param.

Example

Crafty.audio.unpause('music');
diff --git a/api/Crafty-background.html b/api/Crafty-background.html index 025b452..d1f1e2c 100644 --- a/api/Crafty-background.html +++ b/api/Crafty-background.html @@ -55,7 +55,7 @@ -

Crafty.background

public void Crafty.background(String value)
style

Modify the background with a color or image

+

Crafty.background

public void Crafty.background(String style)
style

Modify the background with a color or image

This method is a shortcut for adding a background style to the stage element, i.e. Crafty.stage.elem.style.background = ...

diff --git a/api/Crafty-bind.html b/api/Crafty-bind.html index dfa66c1..8e8a3b2 100644 --- a/api/Crafty-bind.html +++ b/api/Crafty-bind.html @@ -55,7 +55,7 @@ -

Crafty.bind

public Number bind(String eventName, Function callback)
eventName

Name of the event to bind to

+

Crafty.bind

public Function bind(String eventName, Function callback)
eventName

Name of the event to bind to

callback

Method to execute upon event triggered

[Returns]

callback function which can be used for unbind

Binds to a global event. Method will be executed when Crafty.trigger is used diff --git a/api/Crafty-c.html b/api/Crafty-c.html index 9931811..6e2649e 100644 --- a/api/Crafty-c.html +++ b/api/Crafty-c.html @@ -55,7 +55,7 @@ -

Crafty.c

public void Crafty.c(String name, Object component)
name

Name of the component

+

Crafty.c

public void Crafty.c(String name, Object component)
name

Name of the component

component

Object with the component's properties and methods

Creates a component where the first argument is the ID and the second is the object that will be inherited by entities.

@@ -66,10 +66,12 @@
  • (See the two examples below for further explanation) Note that when a component method gets called, the this keyword will refer to the current entity the component was added to.
  • -

    A couple of methods are treated specially. They are invoked in partiular contexts, and (in those contexts) cannot be overridden by other components.

    +

    A handful of methods or properties are treated specially. They are invoked in partiular contexts, and (in those contexts) cannot be overridden by other components.

      -
    • init will be called when the component is added to an entity
    • -
    • remove will be called just before a component is removed, or before an entity is destroyed. It is passed a single boolean parameter that is true if the entity is being destroyed.
    • +
    • required: A string listing required components, which will be added to the component before init() runs.
    • +
    • init: A function to be called when the component is added to an entity
    • +
    • remove: A function which will be called just before a component is removed, or before an entity is destroyed. It is passed a single boolean parameter that is true if the entity is being destroyed.
    • +
    • events: An object whose properties represent functions bound to events equivalent to the property names. (See the example below.) The binding occurs directly after the call to init, and will be removed directly before remove is called.

    In addition to these hardcoded special methods, there are some conventions for writing components.

      @@ -79,20 +81,26 @@

    Example

    Crafty.c("Annoying", {
         _message: "HiHi",
    -    init: function() {
    -        this.bind("EnterFrame", function() { alert(this.message); });
    +    init: function() {
    +        this.bind("EnterFrame", function() { alert(this.message); });
         },
    -    annoying: function(message) { this.message = message; }
    +    annoying: function(message) { this.message = message; }
     });
     
    -Crafty.e("Annoying").annoying("I'm an orange...");

    WARNING:

    -

    in the example above the field _message is local to the entity. That is, if you create many entities with the Annoying component they can all have different values for _message. That is because it is a simple value, and simple values are copied by value. If however the field had been an object or array, the value would have been shared by all entities with the component because complex types are copied by reference in javascript. This is probably not what you want and the following example demonstrates how to work around it:

    -
    Crafty.c("MyComponent", {
    +Crafty.e("Annoying").annoying("I'm an orange...");

    To attach to the "EnterFrame" event using the events property instead:

    +
    Crafty.c("Annoying", {
    +    _message: "HiHi",
    +    events: {
    +        "EnterFrame": function(){alert(this.message);}
    +    }
    +    annoying: function(message) { this.message = message; }
    +});
    Warning

    In the examples above the field _message is local to the entity. That is, if you create many entities with the Annoying component, they can all have different values for _message. That is because it is a simple value, and simple values are copied by value. If however the field had been an object or array, the value would have been shared by all entities with the component, because complex types are copied by reference in javascript. This is probably not what you want and the following example demonstrates how to work around it.

    +
    Crafty.c("MyComponent", {
         _iAmShared: { a: 3, b: 4 },
    -    init: function() {
    +    init: function() {
             this._iAmNotShared = { a: 3, b: 4 };
         },
    -});

    See Also

    +});

    See Also

    diff --git a/api/Crafty-canvasLayer.html b/api/Crafty-canvasLayer.html new file mode 100644 index 0000000..73e7150 --- /dev/null +++ b/api/Crafty-canvasLayer.html @@ -0,0 +1,112 @@ + + + + Crafty - Crafty.canvasLayer + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.canvasLayer

    Collection of mostly private methods to draw entities on a canvas element.

    +

    Methods and Properties

    Back to top

    Crafty.canvasLayer._canvas

    Main Canvas element

    +
    Back to top

    Crafty.canvasLayer.add

    public Crafty.canvasLayer.add(ent)
    ent

    The entity to add

    +

    Add an entity to the list of Canvas objects to draw

    +
    Back to top

    Crafty.canvasLayer.context

    This will return the 2D context of the main canvas element. +The value returned from Crafty.canvasLayer._canvas.getContext('2d').

    +
    Back to top

    Crafty.canvasLayer.drawAll

    public Crafty.canvasLayer.drawAll([Object rect])
    rect

    a rectangular region {_x: x_val, _y: y_val, _w: w_val, _h: h_val}

    +
      +
    • If rect is omitted, redraw within the viewport
    • +
    • If rect is provided, redraw within the rect
    • +
    +
    Back to top

    Crafty.canvasLayer.drawDirty

    public Crafty.canvasLayer.drawDirty()
      +
    • Triggered by the "RenderScene" event
    • +
    • If the number of rects is over 60% of the total number of objects +do the naive method redrawing Crafty.canvasLayer.drawAll instead
    • +
    • Otherwise, clear the dirty regions, and redraw entities overlapping the dirty regions.
    • +
    +

    See Also

    Back to top

    Crafty.canvasLayer.init

    public void Crafty.canvasLayer.init(void)

    Events

    NoCanvas
    triggered if `Crafty.support.canvas` is false

    Creates a canvas element inside Crafty.stage.elem. Must be called +before any entities with the Canvas component can be drawn.

    +

    This method will automatically be called if no Crafty.canvasLayer.context is +found.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-circle.html b/api/Crafty-circle.html index 92c776e..103681d 100644 --- a/api/Crafty-circle.html +++ b/api/Crafty-circle.html @@ -55,19 +55,19 @@ -

    Crafty.circle

    Circle object used for hitboxes and click maps. Must pass a x, a y and a radius value.

    +

    Crafty.circle

    Circle object used for hitboxes and click maps. Must pass a x, a y and a radius value.

    Example

    var centerX = 5,
         centerY = 10,
         radius = 25;
     
     new Crafty.circle(centerX, centerY, radius);

    When creating a circle for an entity, each point should be offset or relative from the entities x and y (don't include the absolute values as it will automatically calculate this).

    -

    Methods and Properties

    Back to top

    .containsPoint

    public Boolean .containsPoint(Number x, Number y)
    x

    X position of the point

    +

    Methods and Properties

    Back to top

    .containsPoint

    public Boolean .containsPoint(Number x, Number y)
    x

    X position of the point

    y

    Y position of the point

    Method is used to determine if a given point is contained by the circle.

    Example

    var circle = new Crafty.circle(0, 0, 10);
     circle.containsPoint(0, 0); //TRUE
    -circle.containsPoint(50, 50); //FALSE
    Back to top

    .shift

    public void .shift(Number x, Number y)
    x

    Amount to shift the x axis

    +circle.containsPoint(50, 50); //FALSE
    Back to top

    .shift

    public void .shift(Number x, Number y)
    x

    Amount to shift the x axis

    y

    Amount to shift the y axis

    Shifts the circle by the specified amount.

    Example

    var circle = new Crafty.circle(0, 0, 10);
    diff --git a/api/Crafty-clone.html b/api/Crafty-clone.html
    index 0b3c1da..5abc703 100644
    --- a/api/Crafty-clone.html
    +++ b/api/Crafty-clone.html
    @@ -55,9 +55,34 @@
     
     
     
    -

    Crafty.clone

    public Object .clone(Object obj)
    obj

    an object

    +

    Crafty.clone

    public Object .clone(Object obj)
    obj

    an object

    Deep copy (a.k.a clone) of an object.

    -
    +

    Example

    // Null or Primitive types
    +Crafty.clone(null); // returns null
    +Crafty.clone(4);    // returns 4
    +
    +// Objects
    +var globalCount = 0;
    +var obj1 = {
    +  count: 0,
    +  inc: function(){
    +     this.count++;
    +     globalCount++;
    +  },
    +  log: function(){
    +    console.log(this.count + '/' + globalCount);
    +  }
    +};
    +
    +obj1.inc();
    +obj1.log(); // prints "1/1" to the log
    +
    +var obj2 = Crafty.clone(obj1);
    +obj2.log(); // prints "1/1" to the log
    +
    +obj1.inc();
    +obj1.log(); // prints "2/2" to the log
    +obj2.log(); // prints "1/2" to the log
    diff --git a/api/Crafty-defineField.html b/api/Crafty-defineField.html new file mode 100644 index 0000000..507a0f3 --- /dev/null +++ b/api/Crafty-defineField.html @@ -0,0 +1,108 @@ + + + + Crafty - Crafty.defineField + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.defineField

    public void Crafty.defineField(Object object, String property, Function getCallback, Function setCallback)
    object

    Object to define property on

    +
    property

    Property name to assign getter & setter to

    +
    getCallback

    Method to execute if the property is accessed

    +
    setCallback

    Method to execute if the property is mutated

    +

    Assigns getters and setters to the property in the given object. +A getter will watch a property waiting for access and will then invoke the +given getCallback when attempting to retrieve. +A setter will watch a property waiting for mutation and will then invoke the +given setCallback when attempting to modify.

    +

    Example

    var ent = Crafty.e("2D");
    +Crafty.defineField(ent, "customData", function() {
    +   return this._customData;
    +}, function(newValue) {
    +   this._customData = newValue;
    +});
    +
    +ent.customData = "2" // set customData to 2
    +Crafty.log(ent.customData) // prints 2
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-device.html b/api/Crafty-device.html index 8c43ca7..202c9f1 100644 --- a/api/Crafty-device.html +++ b/api/Crafty-device.html @@ -55,30 +55,31 @@ -

    Crafty.device

    Methods and Properties

    Back to top

    Crafty.device.deviceMotion

    public Crafty.device.deviceMotion(Function callback)
    callback

    Callback method executed once as soon as device motion is change

    +

    Crafty.device

    Methods relating to devices such as tablets or phones

    +

    Methods and Properties

    Back to top

    Crafty.device.deviceMotion

    public Crafty.device.deviceMotion(Function callback)
    callback

    Callback method executed once as soon as device motion is change

    Do something with normalized device motion data:

    {
    -    'acceleration' : ' Grab the acceleration including gravity from the results',
    -    'rawAcceleration' : 'Display the raw acceleration data',
    -    'facingUp' : 'Z is the acceleration in the Z axis, and if the device is facing up or down',
    -    'tiltLR' : 'Convert the value from acceleration to degrees. acceleration.x is the acceleration according to gravity, we'll assume we're on Earth and divide by 9.81 (earth gravity) to get a percentage value, and then multiply that by 90 to convert to degrees.',
    -    'tiltFB' : 'Convert the value from acceleration to degrees.'
    +    acceleration : 'Grab the acceleration including gravity from the results',
    +    rawAcceleration : 'Display the raw acceleration data',
    +    facingUp : 'Z is the acceleration in the Z axis, and if the device is facing up or down',
    +    tiltLR : 'Convert the value from acceleration to degrees. acceleration.x is the acceleration according to gravity, we'll assume we're on Earth and divide by 9.81 (earth gravity) to get a percentage value, and then multiply that by 90 to convert to degrees.',
    +    tiltFB : 'Convert the value from acceleration to degrees.'
     }

    Example

    // Get DeviceMotion event normalized data.
    -Crafty.device.deviceMotion(function(data){
    -    console.log('data.moAccel : '+data.rawAcceleration+', data.moCalcTiltLR : '+Math.round(data.tiltLR)+', data.moCalcTiltFB : '+Math.round(data.tiltFB)+'');
    +Crafty.device.deviceMotion(function(data){
    +    Crafty.log('data.moAccel : '+data.rawAcceleration+', data.moCalcTiltLR : '+Math.round(data.tiltLR)+', data.moCalcTiltFB : '+Math.round(data.tiltFB)+'');
     });

    See browser support at http://caniuse.com/#search=motion.

    -
    Back to top

    Crafty.device.deviceOrientation

    public Crafty.device.deviceOrientation(Function callback)
    callback

    Callback method executed once as soon as device orientation is change

    +
    Back to top

    Crafty.device.deviceOrientation

    public Crafty.device.deviceOrientation(Function callback)
    callback

    Callback method executed once as soon as device orientation is change

    Do something with normalized device orientation data:

    {
    -  'tiltLR'    :   'gamma the angle in degrees the device is tilted left-to-right.',
    -  'tiltFB'    :   'beta the angle in degrees the device is tilted front-to-back',
    -  'dir'       :   'alpha the direction the device is facing according to the compass',
    -  'motUD'     :   'The angles values increase as you tilt the device to the right or towards you.'
    +  tiltLR    :   'gamma -- the angle in degrees the device is tilted left-to-right.',
    +  tiltFB    :   'beta -- the angle in degrees the device is tilted front-to-back',
    +  dir       :   'alpha -- the direction the device is facing according to the compass',
    +  motUD     :   'The angle's values increase as you tilt the device to the right or towards you.'
     }

    Example

    // Get DeviceOrientation event normalized data.
    -Crafty.device.deviceOrientation(function(data){
    -    console.log('data.tiltLR : '+Math.round(data.tiltLR)+', data.tiltFB : '+Math.round(data.tiltFB)+', data.dir : '+Math.round(data.dir)+', data.motUD : '+data.motUD+'');
    +Crafty.device.deviceOrientation(function(data){
    +    Crafty.log('data.tiltLR : '+Math.round(data.tiltLR)+', data.tiltFB : '+Math.round(data.tiltFB)+', data.dir : '+Math.round(data.dir)+', data.motUD : '+data.motUD+'');
     });

    See browser support at http://caniuse.com/#search=device orientation.

    -
    Back to top

    Crafty.mobile

    Determines if Crafty is running on mobile device.

    +
    Back to top

    Crafty.mobile

    Determines if Crafty is running on mobile device.

    If Crafty.mobile is equal true Crafty does some things under hood:

    - set viewport on max device width and height
     - set Crafty.stage.fullscreen on true
    diff --git a/api/Crafty-diamondIso.html b/api/Crafty-diamondIso.html
    index 524dfb5..844efd2 100644
    --- a/api/Crafty-diamondIso.html
    +++ b/api/Crafty-diamondIso.html
    @@ -55,17 +55,21 @@
     
     
     
    -

    Crafty.diamondIso

    Place entities in a 45deg diamond isometric fashion. It is similar to isometric but has another grid locations

    -

    Methods and Properties

    Back to top

    Crafty.diamondIso.init

    public this Crafty.diamondIso.init(Number tileWidth,Number tileHeight,Number mapWidth,Number mapHeight)
    tileWidth

    The size of base tile width in Pixel

    -
    tileHeight

    The size of base tile height in Pixel

    +

    Crafty.diamondIso

    Place entities in a 45deg diamond isometric fashion. It is similar to isometric but has another grid locations +In this mode, the x axis and y axis are aligned to the edges of tiles with x increasing being down and to the +right and y being down and to the left.

    +

    Methods and Properties

    Back to top

    Crafty.diamondIso.init

    public this Crafty.diamondIso.init(Number tileWidth,Number tileHeight,Number mapWidth,Number mapHeight)
    tileWidth

    The size of base tile width's grid space in Pixel

    +
    tileHeight

    The size of base tile height grid space in Pixel

    mapWidth

    The width of whole map in Tiles

    mapHeight

    The height of whole map in Tiles

    +
    x

    the x coordinate of the TOP corner of the 0,0 tile

    +
    y

    the y coordinate of the TOP corner of the 0,0, tile

    Method used to initialize the size of the isometric placement. Recommended to use a size alues in the power of 2 (128, 64 or 32). This makes it easy to calculate positions and implement zooming.

    -

    Example

    var iso = Crafty.diamondIso.init(64,128,20,20);

    See Also

    Back to top

    Crafty.diamondIso.place

    public this Crafty.diamondIso.place(Entity tile,Number x, Number y, Number layer)
    x

    The x position to place the tile

    +

    Example

    var iso = Crafty.diamondIso.init(64,128,20,20);

    See Also

    Back to top

    Crafty.diamondIso.place

    public this Crafty.diamondIso.place(Entity tile,Number x, Number y, Number layer)
    x

    The x position to place the tile

    y

    The y position to place the tile

    -
    layer

    The z position to place the tile (calculated by y position * layer)

    +
    layer

    The z position to place the tile

    tile

    The entity that should be position in the isometric fashion

    Use this method to place an entity in an isometric grid.

    Example

    var iso = Crafty.diamondIso.init(64,128,20,20);
    diff --git a/api/Crafty-domHelper.html b/api/Crafty-domHelper.html
    new file mode 100644
    index 0000000..ba20528
    --- /dev/null
    +++ b/api/Crafty-domHelper.html
    @@ -0,0 +1,107 @@
    +
    +
    +
    +	Crafty - Crafty.domHelper
    +	
    +
    +	
    +	
    +	
    +	
    +	
    +	
    +
    +
    +	
    +
    + + + +
    +
    + + + + +

    Crafty.domHelper

    Collection of utilities for using the DOM.

    +

    Methods and Properties

    Back to top

    Crafty.domHelper.getStyle

    public Object Crafty.domHelper.getStyle(HTMLElement obj, String property)
    obj

    HTML element to find the style

    +
    property

    Style to return

    +

    Determine the value of a style on an HTML element. Notation can be +in either CSS or JS.

    +
    Back to top

    Crafty.domHelper.innerPosition

    public Object Crafty.domHelper.innerPosition(HTMLElement obj)
    obj

    HTML element to calculate the position

    +
    [Returns]

    Object with x key being the x position, y being the y position

    +

    Find a DOM elements position including +padding and border.

    +
    Back to top

    Crafty.domHelper.translate

    public Object Crafty.domHelper.translate(Number clientX, Number clientY)
    clientX

    clientX position in the browser screen

    +
    clientY

    clientY position in the browser screen

    +
    [Returns]

    Object {x: ..., y: ...} with Crafty coordinates.

    +

    The parameters clientX and clientY are pixel coordinates within the visible +browser window. This function translates those to Crafty coordinates (i.e., +the coordinates that you might apply to an entity), by taking into account +where the stage is within the screen, what the current viewport is, etc.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-domLayer.html b/api/Crafty-domLayer.html new file mode 100644 index 0000000..dbba877 --- /dev/null +++ b/api/Crafty-domLayer.html @@ -0,0 +1,100 @@ + + + + Crafty - Crafty.domLayer + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.domLayer

    Collection of mostly private methods to represent entities using the DOM.

    +

    Methods and Properties

    Back to top

    Crafty.domLayer._div

    Crafty.domLayer._div is a div inside the #cr-stage div that holds all DOM entities. +If you use canvas, a canvas element is created at the same level in the dom +as the the Crafty.domLayer._div div. So the hierarchy in the DOM is

    +
    Crafty.stage.elem
    + - Crafty.domLayer._div (a div HTMLElement)
    + - Crafty.canvasLayer._canvas (a canvas HTMLElement)
    Back to top

    Crafty.domLayer._render

    public Crafty.domLayer.render()

    When "RenderScene" is triggered, draws all DOM entities that have been flagged

    +

    See Also

    Back to top

    Crafty.domLayer.add

    public Crafty.domLayer.add(ent)
    ent

    The entity to add

    +

    Add an entity to the list of DOM object to draw

    +
    Back to top

    Crafty.domLayer.debug

    public Crafty.domLayer.debug()
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-e.html b/api/Crafty-e.html index 10f6ba5..95088bf 100644 --- a/api/Crafty-e.html +++ b/api/Crafty-e.html @@ -55,8 +55,8 @@ -

    Crafty.e

    Events

    NewEntity [ Data { { id:Number } }]
    When the entity is created and all components are added
    public Entity Crafty.e(String componentList)
    componentList

    List of components to assign to new entity

    -
    public Entity Crafty.e(String component1[, .., String componentN])
    component#

    Component to add

    +

    Crafty.e

    Events

    NewEntity [Data = { id:Number }]
    When the entity is created and all components are added
    public Entity Crafty.e(String componentList)
    componentList

    List of components to assign to new entity

    +
    public Entity Crafty.e(String component1[, .., String componentN])
    component#

    Component to add

    Creates an entity. Any arguments will be applied in the same way .addComponent() is applied as a quick way to add components.

    Any component added will augment the functionality of diff --git a/api/Crafty-easing.html b/api/Crafty-easing.html new file mode 100644 index 0000000..b02aaa8 --- /dev/null +++ b/api/Crafty-easing.html @@ -0,0 +1,101 @@ + + + + Crafty - Crafty.easing + + + + + + + + + + +

    +
    + + + +
    +
    + + + + +

    Crafty.easing

    An object for tracking transitions. Typically used indirectly through "SpriteAnimation", "Tween", or viewport animations.

    +

    If a method allows you to specify the type of easing, you can do so by providing a custom function or a string corresponding to the name of a built-in method.

    +

    Built-in easing functions are "linear", "smoothStep", "smootherStep", "easeInQuad", "easeOutQuad", and "easeInOutQuad".

    +

    A custom function will be passed a parameter t which will vary between 0 and 1, and should return the progress of the animation between 0 and 1.

    +

    Example

    Here is how you might use easing functions with the "Tween" component.

    +
    var e = Crafty.e("2D, Tween");
    +// Use built-in easing functions
    +e.tween({x:100}, 1000, "smoothStep");
    +e.tween({y:100}, 1000, "easeInQuad");
    +// Define a custom easing function: 2t^2 - t
    +e.tween({w:0}, 1000, function(t){return 2*t*t - t;});
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-error.html b/api/Crafty-error.html new file mode 100644 index 0000000..a14f033 --- /dev/null +++ b/api/Crafty-error.html @@ -0,0 +1,94 @@ + + + + Crafty - Crafty.error + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.error

    Crafty.error( arguments )
    arguments

    arguments which are passed to console.error

    +

    This is a simple wrapper for console.error. You can disable logging messages by setting Crafty.loggingEnabled to false. +It is recommended to use Crafty.error, as console.error can crash on IE9.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-eventObject.html b/api/Crafty-eventObject.html index 16aeac4..3523753 100644 --- a/api/Crafty-eventObject.html +++ b/api/Crafty-eventObject.html @@ -55,8 +55,8 @@ -

    Crafty.eventObject

    Event Object used in Crafty for cross browser compatibility

    -

    Methods and Properties

    Back to top

    .key

    Unicode of the key pressed

    +

    Crafty.eventObject

    Event Object used in Crafty for cross browser compatibility

    +

    Methods and Properties

    Back to top

    .key

    Unicode of the key pressed

    diff --git a/api/Crafty-extend.html b/api/Crafty-extend.html index a33b586..8f95448 100644 --- a/api/Crafty-extend.html +++ b/api/Crafty-extend.html @@ -55,8 +55,16 @@ - +

    Crafty.extend

    public this Crafty.extend(Object obj)
    obj

    An object whose fields will be copied onto Crafty. This is a shallow copy.

    +

    Used to extend the Crafty namespace by passing in an object of properties and methods to add.

    +

    Example

    Crafty.extend({
    +  isArray: function(arg){
    +    return Object.prototype.toString.call(arg) === '[object Array]'
    +  }
    +});
    +
    +Crafty.isArray([4, 5, 6]);  // returns true
    +Crafty.isArray('hi');       // returns false
    diff --git a/api/Crafty-findClosestEntityByComponent.html b/api/Crafty-findClosestEntityByComponent.html new file mode 100644 index 0000000..7d2ef3e --- /dev/null +++ b/api/Crafty-findClosestEntityByComponent.html @@ -0,0 +1,104 @@ + + + + Crafty - Crafty.findClosestEntityByComponent + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.findClosestEntityByComponent

    public this .findClosestEntityByComponent(String comp, Number x, Number y[, Object target])

    Finds closest entity with certain component at given coordinates.

    +
    comp

    Component name

    +
    x

    x position where to look for entities

    +
    y

    y position where to look for entities

    +
    target

    Target element wherein to look for entities

    +

    This method is used internally by the .mouseDispatch and .touchDispatch methods, but can be used otherwise for +Canvas entities.

    +

    Finds the top most entity (with the highest z) with a given component at a given point (x, y). +For having a detection area specified for the enity, add the AreaMap component to the entity expected to be found.

    +

    The 'target' argument is only meant to be used by .mouseDispatch and touchDispatch; defaults to Crafty.stage.elem, +thus using this function directly is only worth anything for canvas entities.

    +

    Returns the found entity, or undefined if no entity was found.

    +

    Example

    var coords = { x: 455, y: 267 },
    +    closestText = Crafty.findClosestEntityByComponent("Text", coords.x, coords.y);
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-frame.html b/api/Crafty-frame.html index cafab4b..4372b82 100644 --- a/api/Crafty-frame.html +++ b/api/Crafty-frame.html @@ -55,8 +55,8 @@ - +

    Crafty.frame

    public Number Crafty.frame(void)
    [Returns]

    the current frame number

    +
    diff --git a/api/Crafty-getVersion.html b/api/Crafty-getVersion.html index 5a611e9..a63d0da 100644 --- a/api/Crafty-getVersion.html +++ b/api/Crafty-getVersion.html @@ -55,7 +55,7 @@ -

    Crafty.getVersion

    public String Crafty.getVersion()
    [Returns]

    Current version of Crafty as a string

    +

    Crafty.getVersion

    public String Crafty.getVersion()
    [Returns]

    Current version of Crafty as a string

    Return current version of crafty

    Example

    Crafty.getVersion(); //'0.5.2'
    diff --git a/api/Crafty-image_whitelist.html b/api/Crafty-image_whitelist.html index fc9d1d6..50feb04 100644 --- a/api/Crafty-image_whitelist.html +++ b/api/Crafty-image_whitelist.html @@ -55,7 +55,7 @@ -

    Crafty.image_whitelist

    A list of file extensions that can be loaded as images by Crafty.load

    +

    Crafty.image_whitelist

    A list of file extensions that can be loaded as images by Crafty.load

    Example

    // add tif extension to list of supported image files
     Crafty.image_whitelist.push("tif");
     
    @@ -73,15 +73,15 @@
     };
     
     Crafty.load( assets, // preload the assets
    -    function() {     //when loaded
    +    function() {     //when loaded
             Crafty.audio.play("jump"); //Play the audio file
             Crafty.e('2D, DOM, sprite_car'); // create entity with sprite
         },
     
    -    function(e) { //progress
    +    function(e) { //progress
         },
     
    -    function(e) { //uh oh, error loading
    +    function(e) { //uh oh, error loading
         }
     );
    diff --git a/api/Crafty-init.html b/api/Crafty-init.html index 1dbf3c2..74a794e 100644 --- a/api/Crafty-init.html +++ b/api/Crafty-init.html @@ -55,12 +55,12 @@ -

    Crafty.init

    Events

    Load
    Just after the viewport is initialised. Before the EnterFrame loops is started
    public this Crafty.init([Number width, Number height, String stage_elem])
    public this Crafty.init([Number width, Number height, HTMLElement stage_elem])
    Number width

    Width of the stage

    +

    Crafty.init

    Events

    Load
    Just after the viewport is initialised. Before the EnterFrame loops is started
    public this Crafty.init([Number width, Number height, String stage_elem])
    public this Crafty.init([Number width, Number height, HTMLElement stage_elem])
    Number width

    Width of the stage

    Number height

    Height of the stage

    String or HTMLElement stage_elem

    the element to use for the stage

    Sets the element to use as the stage, creating it if necessary. By default a div with id 'cr-stage' is used, but if the 'stage_elem' argument is provided that will be used instead. (see Crafty.viewport.init)

    Starts the EnterFrame interval. This will call the EnterFrame event for every frame.

    -

    Can pass width and height values for the stage otherwise will default to window size (see Crafty.DOM.window).

    +

    Can pass width and height values for the stage otherwise will default to window size.

    All Load events will be executed.

    Uses requestAnimationFrame to sync the drawing with the browser but will default to setInterval if the browser does not support it.

    diff --git a/api/Crafty-isPaused.html b/api/Crafty-isPaused.html index 01502ea..10bc9d4 100644 --- a/api/Crafty-isPaused.html +++ b/api/Crafty-isPaused.html @@ -55,8 +55,8 @@ - +

    Crafty.isPaused

    public Boolean Crafty.isPaused()
    [Returns]

    Whether the game is currently paused.

    +

    Example

    Crafty.isPaused();
    diff --git a/api/Crafty-isometric.html b/api/Crafty-isometric.html index 4b879a2..a1549e4 100644 --- a/api/Crafty-isometric.html +++ b/api/Crafty-isometric.html @@ -55,32 +55,42 @@ -

    Crafty.isometric

    Place entities in a 45deg isometric fashion.

    -

    Methods and Properties

    Back to top

    Crafty.isometric.area

    public this Crafty.isometric.area()
    [Returns]

    Object {x:{start Number,end Number},y:{start Number,end Number}}

    -

    This method get the Area surrounding by the centerpoint depends on viewport height and width

    +

    Crafty.isometric

    Place entities in a 45deg isometric fashion. The alignment of this +grid's axes for tile placement is 90 degrees. If you are looking +to have the grid of tile indicies for this.place aligned to the tiles +themselves, use DiamondIso instead.

    +

    Methods and Properties

    Back to top

    Crafty.isometric.area

    public Object Crafty.isometric.area()
    [Returns]

    An obect with x and y fields, each of which have a start and end field. In other words, the object has this structure: {x:{start Number,end Number},y:{start Number,end Number}}

    +

    This method returns an object representing the bounds of the viewport

    Example

    var iso = Crafty.isometric.size(128,96).centerAt(10,10); //Viewport is now moved
     var area = iso.area(); //get the area
     for(var y = area.y.start;y <= area.y.end;y++){
       for(var x = area.x.start ;x <= area.x.end;x++){
           iso.place(x,y,0,Crafty.e("2D,DOM,gras")); //Display tiles in the Screen
       }
    -}
    Back to top

    Crafty.isometric.centerAt

    public this Crafty.isometric.centerAt(Number x,Number y)
    top
    left

    This method center the Viewport at x/y location or gives the current centerpoint of the viewport

    +}
    Back to top

    Crafty.isometric.centerAt

    public Obect Crafty.isometric.centerAt()
    [Returns]

    An object with top and left fields represneting the viewport's current center

    +
    public this Crafty.isometric.centerAt(Number x, Number y)
    x

    The x position to center at

    +
    y

    The y position to center at

    +

    This method centers the Viewport at an x,y location or gives the current centerpoint of the viewport

    Example

    var iso = Crafty.isometric.size(128,96).centerAt(10,10); //Viewport is now moved
     //After moving the viewport by another event you can get the new center point
    -console.log(iso.centerAt());
    Back to top

    Crafty.isometric.place

    public this Crafty.isometric.place(Number x, Number y, Number z, Entity tile)
    x

    The x position to place the tile

    +Crafty.log(iso.centerAt());
    Back to top

    Crafty.isometric.place

    public this Crafty.isometric.place(Number x, Number y, Number z, Entity tile)
    x

    The x position to place the tile

    y

    The y position to place the tile

    z

    The z position or height to place the tile

    tile

    The entity that should be position in the isometric fashion

    Use this method to place an entity in an isometric grid.

    Example

    var iso = Crafty.isometric.size(128);
    -iso.place(2, 1, 0, Crafty.e('2D, DOM, Color').color('red').attr({w:128, h:128}));

    See Also

    Back to top

    Crafty.isometric.pos2px

    public this Crafty.isometric.pos2px(Number x,Number y)
    x
    y
    [Returns]

    Object {left Number,top Number}

    -

    This method calculate the X and Y Coordinates to Pixel Positions

    +iso.place(2, 1, 0, Crafty.e('2D, DOM, Color').color('red').attr({w:128, h:128}));

    See Also

    Back to top

    Crafty.isometric.pos2px

    public Object Crafty.isometric.pos2px(Number x,Number y)
    x

    A position along the x axis

    +
    y

    A position along the y axis

    +
    [Returns]

    An object with left and top fields {left Number,top Number}

    +

    This method converts a position in x and y coordinates to one in pixels

    Example

    var iso = Crafty.isometric.size(128,96);
    -var position = iso.pos2px(100,100); //Object { left=12800, top=4800}
    Back to top

    Crafty.isometric.px2pos

    public this Crafty.isometric.px2pos(Number left,Number top)
    top
    left
    [Returns]

    Object {x Number,y Number}

    -

    This method calculate pixel top,left positions to x,y coordinates

    +var position = iso.pos2px(100,100); //Object { left=12800, top=4800}
    Back to top

    Crafty.isometric.px2pos

    public Object Crafty.isometric.px2pos(Number left,Number top)
    top

    Offset from the top in pixels

    +
    left

    Offset from the left in pixels

    +
    [Returns]

    An object with x and y fields representing the position

    +

    This method converts a position in pixels to x,y coordinates

    Example

    var iso = Crafty.isometric.size(128,96);
     var px = iso.pos2px(12800,4800);
    -console.log(px); //Object { x=100, y=100}
    Back to top

    Crafty.isometric.size

    public this Crafty.isometric.size(Number tileSize)
    tileSize

    The size of the tiles to place.

    +Crafty.log(px); //Object { x=100, y=100}
    Back to top

    Crafty.isometric.size

    public this Crafty.isometric.size(Number tileSize)
    tileSize

    The size of the tiles to place.

    Method used to initialize the size of the isometric placement. Recommended to use a size values in the power of 2 (128, 64 or 32). This makes it easy to calculate positions and implement zooming.

    diff --git a/api/Crafty-keydown.html b/api/Crafty-keydown.html index 6bb326f..df80e88 100644 --- a/api/Crafty-keydown.html +++ b/api/Crafty-keydown.html @@ -55,9 +55,9 @@ -

    Crafty.keydown

    Remembering what keys (referred by Unicode) are down.

    +

    Crafty.keydown

    Check which keys (referred by Unicode values) are currently down.

    Example

    Crafty.c("Keyboard", {
    -  isDown: function (key) {
    +  isDown: function (key) {
         if (typeof key === "string") {
           key = Crafty.keys[key];
         }
    diff --git a/api/Crafty-keys.html b/api/Crafty-keys.html
    index 27f8ff8..5fa7062 100644
    --- a/api/Crafty-keys.html
    +++ b/api/Crafty-keys.html
    @@ -55,7 +55,7 @@
     
     
     
    -

    Crafty.keys

    Object of key names and the corresponding key code.

    +

    Crafty.keys

    Object of key names and the corresponding key code.

    BACKSPACE: 8,
     TAB: 9,
     ENTER: 13,
    diff --git a/api/Crafty-load.html b/api/Crafty-load.html
    new file mode 100644
    index 0000000..d7dd499
    --- /dev/null
    +++ b/api/Crafty-load.html
    @@ -0,0 +1,149 @@
    +
    +
    +
    +	Crafty - Crafty.load
    +	
    +
    +	
    +	
    +	
    +	
    +	
    +	
    +
    +
    +	
    +
    + + + +
    +
    + + + + +

    Crafty.load

    public void Crafty.load(Object assets, Function onLoad[, Function onProgress[, Function onError]])
    assets

    Object JSON formatted (or JSON string), with assets to load (accepts sounds, images and sprites)

    +
    onLoad

    Callback when the assets are loaded

    +
    onProgress

    Callback when an asset is loaded. Contains information about assets loaded

    +
    onError

    Callback when an asset fails to load

    +

    Preloader for all assets. Takes a JSON formatted object (or JSON string) of files and adds them to the +Crafty.assets object, as well as setting sprites accordingly.

    +

    Format must follow the pattern shown in the example below, but it's not required to pass all "audio", +"images" and "sprites" properties, only those you'll need. For example, if you don't need to preload +sprites, you can omit that property.

    +

    By default, Crafty will assume all files are in the current path. For changing these, +use the function Crafty.paths.

    +

    Files with suffixes in image_whitelist (case insensitive) will be loaded.

    +

    It's possible to pass the full file path(including protocol), instead of just the filename.ext, in case +you want some asset to be loaded from another domain.

    +

    If Crafty.support.audio is true, files with the following suffixes mp3, wav, ogg and +mp4 (case insensitive) can be loaded.

    +

    The onProgress function will be passed on object with information about +the progress including how many assets loaded, total of all the assets to +load and a percentage of the progress.

    +
    { loaded: j, total: total, percent: (j / total * 100), src:src }

    onError will be passed with the asset that couldn't load.

    +

    When onError is not provided, the onLoad is loaded even when some assets are not successfully loaded. +Otherwise, onLoad will be called no matter whether there are errors or not.

    +

    Example

    var assetsObj = {
    +    "audio": {
    +        "beep": ["beep.wav", "beep.mp3", "beep.ogg"],
    +        "boop": "boop.wav",
    +        "slash": "slash.wav"
    +    },
    +    "images": ["badguy.bmp", "goodguy.png"],
    +    "sprites": {
    +        "animals.png": {
    +            "tile": 50,
    +            "tileh": 40,
    +            "map": { "ladybug": [0,0], "lazycat": [0,1], "ferociousdog": [0,2] }
    +            "paddingX": 5,
    +            "paddingY": 5,
    +            "paddingAroundBorder": 10
    +        },
    +        "vehicles.png": {
    +            "tile": 150,
    +            "tileh": 75,
    +            "map": { "car": [0,0], "truck": [0,1] }
    +        }
    +    },
    +};
    +
    +Crafty.load(assetsObj, // preload assets
    +    function() { //when loaded
    +        Crafty.scene("main"); //go to main scene
    +        Crafty.audio.play("boop"); //Play the audio file
    +        Crafty.e('2D, DOM, lazycat'); // create entity with sprite
    +    },
    +
    +    function(e) { //progress
    +    },
    +
    +    function(e) { //uh oh, error loading
    +    }
    +);
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-log.html b/api/Crafty-log.html new file mode 100644 index 0000000..9ed8baa --- /dev/null +++ b/api/Crafty-log.html @@ -0,0 +1,94 @@ + + + + Crafty - Crafty.log + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.log

    Crafty.log( arguments )
    arguments

    arguments which are passed to console.log

    +

    This is a simple wrapper for console.log. You can disable logging messages by setting Crafty.loggingEnabled to false. +It is recommended to use Crafty.log, as console.log can crash on IE9.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-map.html b/api/Crafty-map.html index 48dd4f7..7d22457 100644 --- a/api/Crafty-map.html +++ b/api/Crafty-map.html @@ -55,9 +55,9 @@ -

    Crafty.map

    Functions related with querying entities.

    -

    Methods and Properties

    Back to top

    Crafty.map.boundaries

    public Object Crafty.map.boundaries()

    The return Object is of the following format.

    -
    {
    +

    Crafty.map

    Functions related with querying entities.

    +

    Methods and Properties

    Back to top

    Crafty.map.boundaries

    public Object Crafty.map.boundaries()
    [Returns]

    An object with the following structure, which represents an MBR which contains all entities

    +
    {
       min: {
         x: val_x,
         y: val_y
    @@ -66,25 +66,28 @@
         x: val_x,
         y: val_y
       }
    -}
    Back to top

    Crafty.map.insert

    public Object Crafty.map.insert(Object obj)
    obj

    An entity to be inserted.

    +}
    Back to top

    Crafty.map.insert

    public Object Crafty.map.insert(Object obj)
    obj

    An entity to be inserted.

    +
    [Returns]

    An object representing this object's entry in the HashMap

    obj is inserted in '.map' of the corresponding broad phase cells. An object of the following fields is returned.

    -
    - the object that keep track of cells (keys)
    -- `obj`
    -- the HashMap object
    Back to top

    Crafty.map.refresh

    public void Crafty.map.remove(Entry entry)
    entry

    An entry to update

    -

    Refresh an entry's keys, and its position in the broad phrase map.

    -

    Example

    Crafty.map.refresh(e);
    Back to top

    Crafty.map.remove

    public void Crafty.map.remove([Object keys, ]Object obj)
    keys

    key region. If omitted, it will be derived from obj by Crafty.HashMap.key.

    -
    obj

    need more document.

    +
    {
    +  keys: the object that keep track of cells
    +  obj: The inserted object
    +  map: the HashMap object
    +}
    Back to top

    Crafty.map.refresh

    public void Crafty.map.remove(Entry entry)
    entry

    An entry to update

    +

    Update an entry's keys, and its position in the broad phrase map.

    +

    Example

    Crafty.map.refresh(e);
    Back to top

    Crafty.map.remove

    public void Crafty.map.remove([Object keys, ]Object obj)
    keys

    key region. If omitted, it will be derived from obj by Crafty.HashMap.key.

    +
    obj

    An object to remove from the hashmap

    Remove an entity in a broad phase map.

    • The second form is only used in Crafty.HashMap to save time for computing keys again, where keys were computed previously from obj. End users should not call this form directly.
    -

    Example

    Crafty.map.remove(e);
    diff --git a/api/Crafty-math-Matrix2D.html b/api/Crafty-math-Matrix2D.html index 889ba91..23faa65 100644 --- a/api/Crafty-math-Matrix2D.html +++ b/api/Crafty-math-Matrix2D.html @@ -55,47 +55,46 @@ -

    Crafty.math.Matrix2D

    The third row is always assumed to be [0, 0, 1].

    -

    Matrix2D uses the following form, as per the whatwg.org specifications for canvas.transform(): +

    Crafty.math.Matrix2D

    Matrix2D uses the following form, as per the whatwg.org specifications for canvas.transform(): [a, c, e] [b, d, f] [0, 0, 1]

    -
    public {Matrix2D} new Matrix2D();
    public {Matrix2D} new Matrix2D(Matrix2D);
    public {Matrix2D} new Matrix2D(Number, Number, Number, Number, Number, Number);
    {Matrix2D|Number=1} a
    {Number=0} b
    {Number=0} c
    {Number=1} d
    {Number=0} e
    {Number=0} f

    Methods and Properties

    Back to top

    .apply

    Applies the matrix transformations to the passed object

    -
    public {Vector2D} apply(Vector2D);
    {Vector2D} vecRH

    vector to be transformed

    +
    public {Matrix2D} new Matrix2D();
    public {Matrix2D} new Matrix2D(Matrix2D);
    public {Matrix2D} new Matrix2D(Number, Number, Number, Number, Number, Number);
    {Matrix2D|Number=1} a
    {Number=0} b
    {Number=0} c
    {Number=1} d
    {Number=0} e
    {Number=0} f

    Methods and Properties

    Back to top

    .apply

    Applies the matrix transformations to the passed object

    +
    public {Vector2D} apply(Vector2D);
    {Vector2D} vecRH

    vector to be transformed

    [Returns]

    {Vector2D} the passed vector object after transforming

    -
    Back to top

    .clone

    Creates an exact, numeric copy of the current matrix

    -
    public {Matrix2D} clone();
    [Returns]

    {Matrix2D}

    -
    Back to top

    .combine

    Multiplies this matrix with another, overriding the values of this matrix. +

    Back to top

    .clone

    Creates an exact, numeric copy of the current matrix

    +
    public {Matrix2D} clone();
    [Returns]

    {Matrix2D}

    +
    Back to top

    .combine

    Multiplies this matrix with another, overriding the values of this matrix. The passed matrix is assumed to be on the right-hand side.

    -
    public {Matrix2D} combine(Matrix2D);
    {Matrix2D} mtrxRH
    [Returns]

    {Matrix2D} this matrix after combination

    -
    Back to top

    .determinant

    Calculates the determinant of this matrix

    -
    public {Number} determinant();
    [Returns]

    {Number} det(this matrix)

    -
    Back to top

    .equals

    Checks for the numeric equality of this matrix versus another.

    -
    public {Boolean} equals(Matrix2D);
    {Matrix2D} mtrxRH
    [Returns]

    {Boolean} true if the two matrices are numerically equal

    -
    Back to top

    .invert

    Inverts this matrix if possible

    -
    public {Matrix2D} invert();
    [Returns]

    {Matrix2D} this inverted matrix or the original matrix on failure

    -
    Back to top

    .isIdentity

    Returns true if this matrix is the identity matrix

    -
    public {Boolean} isIdentity();
    [Returns]

    {Boolean}

    -
    Back to top

    .isInvertible

    Determines is this matrix is invertible.

    -
    public {Boolean} isInvertible();
    [Returns]

    {Boolean} true if this matrix is invertible

    -

    See Also

    Back to top

    .preRotate

    Applies a counter-clockwise pre-rotation to this matrix

    -
    public {Matrix2D} preRotate(Number);
    {number} rads

    angle to rotate in radians

    +
    public {Matrix2D} combine(Matrix2D);
    {Matrix2D} mtrxRH
    [Returns]

    {Matrix2D} this matrix after combination

    +
    Back to top

    .determinant

    Calculates the determinant of this matrix

    +
    public {Number} determinant();
    [Returns]

    {Number} det(this matrix)

    +
    Back to top

    .equals

    Checks for the numeric equality of this matrix versus another.

    +
    public {Boolean} equals(Matrix2D);
    {Matrix2D} mtrxRH
    [Returns]

    {Boolean} true if the two matrices are numerically equal

    +
    Back to top

    .invert

    Inverts this matrix if possible

    +
    public {Matrix2D} invert();
    [Returns]

    {Matrix2D} this inverted matrix or the original matrix on failure

    +
    Back to top

    .isIdentity

    Returns true if this matrix is the identity matrix

    +
    public {Boolean} isIdentity();
    [Returns]

    {Boolean}

    +
    Back to top

    .isInvertible

    Determines is this matrix is invertible.

    +
    public {Boolean} isInvertible();
    [Returns]

    {Boolean} true if this matrix is invertible

    +

    See Also

    Back to top

    .preRotate

    Applies a counter-clockwise pre-rotation to this matrix

    +
    public {Matrix2D} preRotate(Number);
    {number} rads

    angle to rotate in radians

    [Returns]

    {Matrix2D} this matrix after pre-rotation

    -
    Back to top

    .preScale

    Applies a pre-scaling to this matrix

    -
    public {Matrix2D} preScale(Number[, Number]);
    {Number} scalarX
    {Number} [scalarY] scalarX is used if scalarY is undefined
    [Returns]

    {Matrix2D} this after pre-scaling

    -
    Back to top

    .preTranslate

    Applies a pre-translation to this matrix

    -
    public {Matrix2D} preTranslate(Vector2D);
    public {Matrix2D} preTranslate(Number, Number);
    {Number|Vector2D} dx
    {Number} dy
    [Returns]

    {Matrix2D} this matrix after pre-translation

    -
    Back to top

    .rotate

    Applies a counter-clockwise post-rotation to this matrix

    -
    public {Matrix2D} rotate(Number);
    {Number} rads

    angle to rotate in radians

    +
    Back to top

    .preScale

    Applies a pre-scaling to this matrix

    +
    public {Matrix2D} preScale(Number[, Number]);
    {Number} scalarX
    {Number} [scalarY] scalarX is used if scalarY is undefined
    [Returns]

    {Matrix2D} this after pre-scaling

    +
    Back to top

    .preTranslate

    Applies a pre-translation to this matrix

    +
    public {Matrix2D} preTranslate(Vector2D);
    public {Matrix2D} preTranslate(Number, Number);
    {Number|Vector2D} dx
    {Number} dy
    [Returns]

    {Matrix2D} this matrix after pre-translation

    +
    Back to top

    .rotate

    Applies a counter-clockwise post-rotation to this matrix

    +
    public {Matrix2D} rotate(Number);
    {Number} rads

    angle to rotate in radians

    [Returns]

    {Matrix2D} this matrix after rotation

    -
    Back to top

    .scale

    Applies a post-scaling to this matrix

    -
    public {Matrix2D} scale(Number[, Number]);
    {Number} scalarX
    {Number} [scalarY] scalarX is used if scalarY is undefined
    [Returns]

    {Matrix2D} this after post-scaling

    -
    Back to top

    .setValues

    Sets the values of this matrix

    -
    public {Matrix2D} setValues(Matrix2D);
    public {Matrix2D} setValues(Number, Number, Number, Number, Number, Number);
    {Matrix2D|Number} a
    {Number} b
    {Number} c
    {Number} d
    {Number} e
    {Number} f
    [Returns]

    {Matrix2D} this matrix containing the new values

    -
    Back to top

    .toString

    Returns the string representation of this matrix.

    -
    public {String} toString();
    [Returns]

    {String}

    -
    Back to top

    .translate

    Applies a post-translation to this matrix

    -
    public {Matrix2D} translate(Vector2D);
    public {Matrix2D} translate(Number, Number);
    {Number|Vector2D} dx
    {Number} dy
    [Returns]

    {Matrix2D} this matrix after post-translation

    +
    Back to top

    .scale

    Applies a post-scaling to this matrix

    +
    public {Matrix2D} scale(Number[, Number]);
    {Number} scalarX
    {Number} [scalarY] scalarX is used if scalarY is undefined
    [Returns]

    {Matrix2D} this after post-scaling

    +
    Back to top

    .setValues

    Sets the values of this matrix

    +
    public {Matrix2D} setValues(Matrix2D);
    public {Matrix2D} setValues(Number, Number, Number, Number, Number, Number);
    {Matrix2D|Number} a
    {Number} b
    {Number} c
    {Number} d
    {Number} e
    {Number} f
    [Returns]

    {Matrix2D} this matrix containing the new values

    +
    Back to top

    .toString

    Returns the string representation of this matrix.

    +
    public {String} toString();
    [Returns]

    {String}

    +
    Back to top

    .translate

    Applies a post-translation to this matrix

    +
    public {Matrix2D} translate(Vector2D);
    public {Matrix2D} translate(Number, Number);
    {Number|Vector2D} dx
    {Number} dy
    [Returns]

    {Matrix2D} this matrix after post-translation

    diff --git a/api/Crafty-math-Vector2D.html b/api/Crafty-math-Vector2D.html index 611071d..ff5c9b0 100644 --- a/api/Crafty-math-Vector2D.html +++ b/api/Crafty-math-Vector2D.html @@ -55,69 +55,69 @@ -

    Crafty.math.Vector2D

    Vector2D uses the following form:

    +

    Crafty.math.Vector2D

    Vector2D uses the following form:

    -
    public {Vector2D} Vector2D();
    public {Vector2D} Vector2D(Vector2D);
    public {Vector2D} Vector2D(Number, Number);
    {Vector2D|Number=0} x
    {Number=0} y

    Methods and Properties

    Back to top

    .add

    Adds the passed vector to this vector

    -
    public {Vector2D} add(Vector2D);
    {vector2D} vecRH
    [Returns]

    {Vector2D} this after adding

    -
    Back to top

    .angleBetween

    Calculates the angle between the passed vector and this vector, using <0,0> as the point of reference. +

    public {Vector2D} Vector2D();
    public {Vector2D} Vector2D(Vector2D);
    public {Vector2D} Vector2D(Number, Number);
    {Vector2D|Number=0} x
    {Number=0} y

    Methods and Properties

    Back to top

    .add

    Adds the passed vector to this vector

    +
    public {Vector2D} add(Vector2D);
    {vector2D} vecRH
    [Returns]

    {Vector2D} this after adding

    +
    Back to top

    .angleBetween

    Calculates the angle between the passed vector and this vector, using <0,0> as the point of reference. Angles returned have the range (−π, π].

    -
    public {Number} angleBetween(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the angle between the two vectors in radians

    -
    Back to top

    .angleTo

    Calculates the angle to the passed vector from this vector, using this vector as the point of reference.

    -
    public {Number} angleTo(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the angle to the passed vector in radians

    -
    Back to top

    .clone

    Creates and exact, numeric copy of this vector

    -
    public {Vector2D} clone();
    [Returns]

    {Vector2D} the new vector

    -
    Back to top

    .crossProduct

    Calculates the z component of the cross product of the two vectors augmented to 3D.

    -
    public {Number} crossProduct(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the resultant cross product

    -
    Back to top

    .distance

    Calculates the distance from this vector to the passed vector.

    -
    public {Number} distance(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the distance between the two vectors

    -
    Back to top

    .distanceSq

    Calculates the squared distance from this vector to the passed vector. +

    public {Number} angleBetween(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the angle between the two vectors in radians

    +
    Back to top

    .angleTo

    Calculates the angle to the passed vector from this vector, using this vector as the point of reference.

    +
    public {Number} angleTo(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the angle to the passed vector in radians

    +
    Back to top

    .clone

    Creates and exact, numeric copy of this vector

    +
    public {Vector2D} clone();
    [Returns]

    {Vector2D} the new vector

    +
    Back to top

    .crossProduct

    Calculates the z component of the cross product of the two vectors augmented to 3D.

    +
    public {Number} crossProduct(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the resultant cross product

    +
    Back to top

    .distance

    Calculates the distance from this vector to the passed vector.

    +
    public {Number} distance(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the distance between the two vectors

    +
    Back to top

    .distanceSq

    Calculates the squared distance from this vector to the passed vector. This function avoids calculating the square root, thus being slightly faster than .distance( ).

    -
    public {Number} distanceSq(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the squared distance between the two vectors

    -

    See Also

    Back to top

    .divide

    Divides this vector by the passed vector.

    -
    public {Vector2D} divide(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Vector2D} this vector after dividing

    -
    Back to top

    .dotProduct

    Calculates the dot product of this and the passed vectors

    -
    public {Number} dotProduct(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the resultant dot product

    -
    Back to top

    .equals

    Determines if this vector is numerically equivalent to the passed vector.

    -
    public {Boolean} equals(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Boolean} true if the vectors are equivalent

    -
    Back to top

    .getNormal

    Calculates a new right-handed unit vector that is perpendicular to the line created by this and the passed vector.

    -
    public {Vector2D} getNormal(Vector2D[, Vector2D]);
    {Vector2D} vecRH
    {Vector2D} [result]

    An optional parameter to save the result in

    +
    public {Number} distanceSq(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the squared distance between the two vectors

    +

    See Also

    Back to top

    .divide

    Divides this vector by the passed vector.

    +
    public {Vector2D} divide(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Vector2D} this vector after dividing

    +
    Back to top

    .dotProduct

    Calculates the dot product of this and the passed vectors

    +
    public {Number} dotProduct(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Number} the resultant dot product

    +
    Back to top

    .equals

    Determines if this vector is numerically equivalent to the passed vector.

    +
    public {Boolean} equals(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Boolean} true if the vectors are equivalent

    +
    Back to top

    .getNormal

    Calculates a new right-handed unit vector that is perpendicular to the line created by this and the passed vector.

    +
    public {Vector2D} getNormal(Vector2D[, Vector2D]);
    {Vector2D} vecRH
    {Vector2D} [result]

    An optional parameter to save the result in

    [Returns]

    {Vector2D} the new normal vector

    -
    Back to top

    .isZero

    Determines if this vector is equal to <0,0>

    -
    public {Boolean} isZero();
    [Returns]

    {Boolean} true if this vector is equal to <0,0>

    -
    Back to top

    .magnitude

    Calculates the magnitude of this vector. +

    Back to top

    .isZero

    Determines if this vector is equal to <0,0>

    +
    public {Boolean} isZero();
    [Returns]

    {Boolean} true if this vector is equal to <0,0>

    +
    Back to top

    .magnitude

    Calculates the magnitude of this vector. Note: Function objects in JavaScript already have a 'length' member, hence the use of magnitude instead.

    -
    public {Number} magnitude();
    [Returns]

    {Number} the magnitude of this vector

    -
    Back to top

    .magnitudeSq

    Calculates the square of the magnitude of this vector. +

    public {Number} magnitude();
    [Returns]

    {Number} the magnitude of this vector

    +
    Back to top

    .magnitudeSq

    Calculates the square of the magnitude of this vector. This function avoids calculating the square root, thus being slightly faster than .magnitude( ).

    -
    public {Number} magnitudeSq();
    [Returns]

    {Number} the square of the magnitude of this vector

    -

    See Also

    Back to top

    .multiply

    Multiplies this vector by the passed vector

    -
    public {Vector2D} multiply(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Vector2D} this vector after multiplying

    -
    Back to top

    .negate

    Negates this vector (ie. <-x,-y>)

    -
    public {Vector2D} negate();
    [Returns]

    {Vector2D} this vector after negation

    -
    Back to top

    .normalize

    Normalizes this vector (scales the vector so that its new magnitude is 1) +

    public {Number} magnitudeSq();
    [Returns]

    {Number} the square of the magnitude of this vector

    +

    See Also

    Back to top

    .multiply

    Multiplies this vector by the passed vector

    +
    public {Vector2D} multiply(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {Vector2D} this vector after multiplying

    +
    Back to top

    .negate

    Negates this vector (ie. <-x,-y>)

    +
    public {Vector2D} negate();
    [Returns]

    {Vector2D} this vector after negation

    +
    Back to top

    .normalize

    Normalizes this vector (scales the vector so that its new magnitude is 1) For vectors where magnitude is 0, <1,0> is returned.

    -
    public {Vector2D} normalize();
    [Returns]

    {Vector2D} this vector after normalization

    -
    Back to top

    .perpendicular

    Calculates a new vector that is perpendicular to this vector. +

    public {Vector2D} normalize();
    [Returns]

    {Vector2D} this vector after normalization

    +
    Back to top

    .perpendicular

    Calculates a new vector that is perpendicular to this vector. The perpendicular vector has the same magnitude as this vector and is obtained by a counter-clockwise rotation of 90° of this vector.

    -
    public {Vector2D} perpendicular([Vector2D]);
    {Vector2D} [result]

    An optional parameter to save the result in

    +
    public {Vector2D} perpendicular([Vector2D]);
    {Vector2D} [result]

    An optional parameter to save the result in

    [Returns]

    {Vector2D} the perpendicular vector

    -
    Back to top

    .scale

    Scales this vector by the passed amount(s) +

    Back to top

    .scale

    Scales this vector by the passed amount(s) If scalarY is omitted, scalarX is used for both axes

    -
    public {Vector2D} scale(Number[, Number]);
    {Number} scalarX
    {Number} [scalarY]
    [Returns]

    {Vector2D} this after scaling

    -
    Back to top

    .scaleToMagnitude

    Scales this vector such that its new magnitude is equal to the passed value.

    -
    public {Vector2D} scaleToMagnitude(Number);
    {Number} mag
    [Returns]

    {Vector2D} this vector after scaling

    -
    Back to top

    .setValues

    Sets the values of this vector using a passed vector or pair of numbers.

    -
    public {Vector2D} setValues(Vector2D);
    public {Vector2D} setValues(Number, Number);
    {Number|Vector2D} x
    {Number} y
    [Returns]

    {Vector2D} this vector after setting of values

    -
    Back to top

    .subtract

    Subtracts the passed vector from this vector.

    -
    public {Vector2D} subtract(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {vector2D} this vector after subtracting

    -
    Back to top

    .toString

    Returns a string representation of this vector.

    -
    public {String} toString();
    [Returns]

    {String}

    -
    Back to top

    .translate

    Translates (moves) this vector by the passed amounts. +

    public {Vector2D} scale(Number[, Number]);
    {Number} scalarX
    {Number} [scalarY]
    [Returns]

    {Vector2D} this after scaling

    +
    Back to top

    .scaleToMagnitude

    Scales this vector such that its new magnitude is equal to the passed value.

    +
    public {Vector2D} scaleToMagnitude(Number);
    {Number} mag
    [Returns]

    {Vector2D} this vector after scaling

    +
    Back to top

    .setValues

    Sets the values of this vector using a passed vector or pair of numbers.

    +
    public {Vector2D} setValues(Vector2D);
    public {Vector2D} setValues(Number, Number);
    {Number|Vector2D} x
    {Number} y
    [Returns]

    {Vector2D} this vector after setting of values

    +
    Back to top

    .subtract

    Subtracts the passed vector from this vector.

    +
    public {Vector2D} subtract(Vector2D);
    {Vector2D} vecRH
    [Returns]

    {vector2D} this vector after subtracting

    +
    Back to top

    .toString

    Returns a string representation of this vector.

    +
    public {String} toString();
    [Returns]

    {String}

    +
    Back to top

    .translate

    Translates (moves) this vector by the passed amounts. If dy is omitted, dx is used for both axes.

    -
    public {Vector2D} translate(Number[, Number]);
    {Number} dx
    {Number} [dy]
    [Returns]

    {Vector2D} this vector after translating

    -
    Back to top

    .tripleProduct

    Calculates the triple product of three vectors. +

    public {Vector2D} translate(Number[, Number]);
    {Number} dx
    {Number} [dy]
    [Returns]

    {Vector2D} this vector after translating

    +
    Back to top

    .tripleProduct

    Calculates the triple product of three vectors. triple vector product = b(a•c) - a(b•c)

    -
    public {Vector2D} tripleProduct(Vector2D, Vector2D, Vector2D, [Vector2D]);
    {Vector2D} a
    {Vector2D} b
    {Vector2D} c
    {Vector2D} [result]

    An optional parameter to save the result in

    +
    public {Vector2D} tripleProduct(Vector2D, Vector2D, Vector2D, [Vector2D]);
    {Vector2D} a
    {Vector2D} b
    {Vector2D} c
    {Vector2D} [result]

    An optional parameter to save the result in

    [Returns]

    {Vector2D} the triple product as a new vector

    diff --git a/api/Crafty-math.html b/api/Crafty-math.html index 0bd6767..76b4f03 100644 --- a/api/Crafty-math.html +++ b/api/Crafty-math.html @@ -55,60 +55,59 @@ -

    Crafty.math

    Static functions.

    -

    Methods and Properties

    Back to top

    Crafty.math.abs

    public this Crafty.math.abs(Number n)
    n

    Some value.

    +

    Crafty.math

    A set of utility functions for common (and not so common) operations.

    +

    Methods and Properties

    Back to top

    Crafty.math.abs

    public this Crafty.math.abs(Number n)
    n

    Some value.

    [Returns]

    Absolute value.

    Returns the absolute value.

    -
    Back to top

    Crafty.math.amountOf

    public Number Crafty.math.amountOf(Number checkValue, Number minValue, Number maxValue)
    checkValue

    Value that should checked with minimum and maximum.

    -
    minValue

    Minimum value to check.

    -
    maxValue

    Maximum value to check.

    -
    [Returns]

    Amount of checkValue compared to minValue and maxValue.

    -

    Returns the amount of how much a checkValue is more like minValue (=0) -or more like maxValue (=1)

    -
    Back to top

    Crafty.math.clamp

    public Number Crafty.math.clamp(Number value, Number min, Number max)
    value

    A value.

    +
    Back to top

    Crafty.math.amountOf

    public Number Crafty.math.amountOf(Number checkValue, Number minValue, Number maxValue)
    checkValue

    Value that should checked with minimum and maximum.

    +
    minValue

    Bottom of the range

    +
    maxValue

    Top of the range

    +
    [Returns]

    The position of the checked value in a coordinate system normalized such that minValue is 0 and maxValue is 1.

    +

    If checkValue is within the range, this will return a number between 0 and 1.

    +
    Back to top

    Crafty.math.clamp

    public Number Crafty.math.clamp(Number value, Number min, Number max)
    value

    A value.

    max

    Maximum that value can be.

    min

    Minimum that value can be.

    [Returns]

    The value between minimum and maximum.

    Restricts a value to be within a specified range.

    -
    Back to top

    Crafty.math.degToRad

    Converts angle from degree to radian.

    -
    angleInDeg

    The angle in degree.

    -
    [Returns]

    The angle in radian.

    -
    Back to top

    Crafty.math.distance

    public Number Crafty.math.distance(Number x1, Number y1, Number x2, Number y2)
    x1

    First x coordinate.

    +
    Back to top

    Crafty.math.degToRad

    Converts angle from degree to radian.

    +
    public Number degToRad(angleInDeg)
    angleInDeg

    The angle in degrees.

    +
    [Returns]

    The angle in radians.

    +
    Back to top

    Crafty.math.distance

    public Number Crafty.math.distance(Number x1, Number y1, Number x2, Number y2)
    x1

    First x coordinate.

    y1

    First y coordinate.

    x2

    Second x coordinate.

    y2

    Second y coordinate.

    [Returns]

    The distance between the two points.

    Distance between two points.

    -
    Back to top

    Crafty.math.lerp

    public Number Crafty.math.lerp(Number value1, Number value2, Number amount)
    value1

    One value.

    +
    Back to top

    Crafty.math.lerp

    public Number Crafty.math.lerp(Number value1, Number value2, Number amount)
    value1

    One value.

    value2

    Another value.

    amount

    Amount of value2 to value1.

    [Returns]

    Linear interpolated value.

    Linear interpolation. Passing amount with a value of 0 will cause value1 to be returned, a value of 1 will cause value2 to be returned.

    -
    Back to top

    Crafty.math.negate

    public Number Crafty.math.negate(Number percent)
    percent

    If you pass 1 a -1 will be returned. If you pass 0 a 1 will be returned.

    +
    Back to top

    Crafty.math.negate

    public Number Crafty.math.negate(Number percent)
    percent

    The probability of returning -1

    [Returns]

    1 or -1.

    -

    Returnes "randomly" -1.

    -
    Back to top

    Crafty.math.radToDeg

    public Number Crafty.math.radToDeg(Number angle)
    angleInRad

    The angle in radian.

    +

    Returns 1 or -1 randomly.

    +
    Back to top

    Crafty.math.radToDeg

    public Number Crafty.math.radToDeg(Number angle)
    angleInRad

    The angle in radian.

    [Returns]

    The angle in degree.

    Converts angle from radian to degree.

    -
    Back to top

    Crafty.math.randomElementOfArray

    public Object Crafty.math.randomElementOfArray(Array array)
    array

    A specific array.

    +
    Back to top

    Crafty.math.randomElementOfArray

    public Object Crafty.math.randomElementOfArray(Array array)
    array

    A specific array.

    [Returns]

    A random element of a specific array.

    Returns a random element of a specific array.

    -
    Back to top

    Crafty.math.randomInt

    public Number Crafty.math.randomInt(Number start, Number end)
    start

    Smallest int value that can be returned.

    +
    Back to top

    Crafty.math.randomInt

    public Number Crafty.math.randomInt(Number start, Number end)
    start

    Smallest int value that can be returned.

    end

    Biggest int value that can be returned.

    [Returns]

    A random int.

    -

    Returns a random int in within a specific range.

    -
    Back to top

    Crafty.math.randomNumber

    public Number Crafty.math.randomInt(Number start, Number end)
    start

    Smallest number value that can be returned.

    +

    Returns a random int within a specific range.

    +
    Back to top

    Crafty.math.randomNumber

    public Number Crafty.math.randomInt(Number start, Number end)
    start

    Smallest number value that can be returned.

    end

    Biggest number value that can be returned.

    [Returns]

    A random number.

    Returns a random number in within a specific range.

    -
    Back to top

    Crafty.math.squaredDistance

    public Number Crafty.math.squaredDistance(Number x1, Number y1, Number x2, Number y2)
    x1

    First x coordinate.

    +
    Back to top

    Crafty.math.squaredDistance

    public Number Crafty.math.squaredDistance(Number x1, Number y1, Number x2, Number y2)
    x1

    First x coordinate.

    y1

    First y coordinate.

    x2

    Second x coordinate.

    y2

    Second y coordinate.

    [Returns]

    The squared distance between the two points.

    Squared distance between two points.

    -
    Back to top

    Crafty.math.withinRange

    public Boolean Crafty.math.withinRange(Number value, Number min, Number max)
    value

    The specific value.

    +
    Back to top

    Crafty.math.withinRange

    public Boolean Crafty.math.withinRange(Number value, Number min, Number max)
    value

    The specific value.

    min

    Minimum value.

    max

    Maximum value.

    [Returns]

    Returns true if value is within a specific range.

    diff --git a/api/Crafty-mouseButtons.html b/api/Crafty-mouseButtons.html index 20003b6..ff3c9a2 100644 --- a/api/Crafty-mouseButtons.html +++ b/api/Crafty-mouseButtons.html @@ -55,7 +55,7 @@ -

    Crafty.mouseButtons

    An object mapping mouseButton names to the corresponding button ID. +

    Crafty.mouseButtons

    An object mapping mouseButton names to the corresponding button ID. In all mouseEvents, we add the e.mouseButton property with a value normalized to match e.button of modern webkit browsers:

    LEFT: 0,
     MIDDLE: 1,
    diff --git a/api/Crafty-mouseDispatch.html b/api/Crafty-mouseDispatch.html
    index 252de7b..556d25f 100644
    --- a/api/Crafty-mouseDispatch.html
    +++ b/api/Crafty-mouseDispatch.html
    @@ -55,20 +55,21 @@
     
     
     
    -

    Crafty.mouseDispatch

    Internal method which dispatches mouse events received by Crafty (crafty.stage.elem). +

    Crafty.mouseDispatch

    Internal method which dispatches mouse events received by Crafty (crafty.stage.elem). The mouse events get dispatched to the closest entity to the source of the event (if available).

    You can read more about the MouseEvent, which is the parameter passed to the callback. https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent

    This method also sets a global property Crafty.lastEvent, which holds the most recent event that occured (useful for determining mouse position in every frame).

    -
    var newestX = Crafty.lastEvent.realX,
    +

    ```

    +

    Example

    var newestX = Crafty.lastEvent.realX,
         newestY = Crafty.lastEvent.realY;

    Notable properties of a MouseEvent e:

    //(x,y) coordinates of mouse event in web browser screen space
     e.clientX, e.clientY
     //(x,y) coordinates of mouse event in world/viewport space
     e.realX, e.realY
     // Normalized mouse button according to Crafty.mouseButtons
    -e.mouseButton
    +e.mouseButton
    diff --git a/api/Crafty-mouseWheelDispatch.html b/api/Crafty-mouseWheelDispatch.html new file mode 100644 index 0000000..940ce88 --- /dev/null +++ b/api/Crafty-mouseWheelDispatch.html @@ -0,0 +1,102 @@ + + + + Crafty - Crafty.mouseWheelDispatch + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.mouseWheelDispatch

    Mouse wheel event triggered by Crafty.

    +

    Events

    MouseWheelScroll [Scroll direction (up | down) = { direction: +1 | -1}]
    is triggered when mouse is scrolled on stage

    Internal method which dispatches mouse wheel events received by Crafty (crafty.stage.elem). +The mouse wheel events get dispatched to Crafty, as well as all entities.

    +

    The native event parameter is passed to the callback. +You can read more about the native mousewheel event (all browsers except Firefox) https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel +or the native DOMMouseScroll event (Firefox only) https://developer.mozilla.org/en-US/docs/Web/Events/DOMMouseScroll .

    +

    Note that the wheel delta properties of the event vary in magnitude across browsers, thus it is recommended to check for .direction instead. +The .direction equals +1 if wheel was scrolled up, -1 if wheel was scrolled down. +See http://stackoverflow.com/questions/5527601/normalizing-mousewheel-speed-across-browsers .

    +

    Example

    Crafty.bind("MouseWheelScroll", function(evt) {
    +    Crafty.viewport.scale(Crafty.viewport._scale * (1 + evt.direction * 0.1));
    +});
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-multitouch.html b/api/Crafty-multitouch.html new file mode 100644 index 0000000..7e211a2 --- /dev/null +++ b/api/Crafty-multitouch.html @@ -0,0 +1,109 @@ + + + + Crafty - Crafty.multitouch + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.multitouch

    public this .multitouch(Boolean bool)
    bool

    Turns multitouch on and off. The initial state is off (false).

    +
    public Boolean .multitouch()
    [Returns]

    Whether multitouch is currently enabled;

    +

    Enables/disables support for multitouch feature.

    +

    If this is set to true, it is expected that your entities have the Touch component instead of Mouse component. +If false (default), then only entities with the Mouse component will respond to touch.

    +

    If no boolean is passed to the function call, it will just return whether multitouch is on or not.

    +

    Note: The Touch component (and thus the multitouch feature) is currently incompatible with the Draggable component.

    +

    Example

    Crafty.multitouch(true);
    +
    +var myEntity1 = Crafty.e('2D, Canvas, Color, Touch')
    +   .attr({x: 100, y: 100, w:200, h:200, z:1 })
    +   .color('black')
    +   .bind('TouchStart',function(e){ alert('big black box was touched', e); }),
    + myEntity2 = Crafty.e('2D, Canvas, Color, Touch')
    +   .attr({x: 40, y: 150, w:90, h:300, z:2 })
    +   .color('green')
    +   .bind('TouchStart',function(e){ alert('big GREEN box was touched', e); });
    +
    +Crafty.log("multitouch is "+Crafty.multitouch());
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-one.html b/api/Crafty-one.html index 0eab1f7..1a22f21 100644 --- a/api/Crafty-one.html +++ b/api/Crafty-one.html @@ -55,7 +55,7 @@ -

    Crafty.one

    public Number one(String eventName, Function callback)
    eventName

    Name of the event to bind to

    +

    Crafty.one

    public Function one(String eventName, Function callback)
    eventName

    Name of the event to bind to

    callback

    Method to execute upon event triggered

    [Returns]

    callback function which can be used for unbind

    Works like Crafty.bind, but will be unbound once the event triggers.

    diff --git a/api/Crafty-paths.html b/api/Crafty-paths.html index 4d7cfbd..aebb2f3 100644 --- a/api/Crafty-paths.html +++ b/api/Crafty-paths.html @@ -55,7 +55,7 @@ -

    Crafty.paths

    public void Crafty.paths([Object paths])
    paths

    Object containing paths for audio and images folders

    +

    Crafty.paths

    public void Crafty.paths([Object paths])
    paths

    Object containing paths for audio and images folders

    Function to define custom folder for audio and images. You should use this function to avoid typing the same paths again and again when loading assets with the Crafty.load() function.

    @@ -69,8 +69,8 @@ "audio": { "ray": ['ray.mp3'] // This loads ray.mp3 from custom/audio/path/ray.mp3 } -}, function() { - console.log('loaded'); +}, function() { + Crafty.log('loaded'); });

    See Also

    diff --git a/api/Crafty-pause.html b/api/Crafty-pause.html index 9008351..a295f41 100644 --- a/api/Crafty-pause.html +++ b/api/Crafty-pause.html @@ -55,12 +55,12 @@ -

    Crafty.pause

    Events

    Pause
    when the game is paused
    Unpause
    when the game is unpaused
    public this Crafty.pause(void)

    Pauses the game by stopping the EnterFrame event from firing. If the game is already paused it is unpaused. +

    Crafty.pause

    Events

    Pause
    when the game is paused
    Unpause
    when the game is unpaused
    public this Crafty.pause(void)

    Pauses the game by stopping the EnterFrame event from firing. If the game is already paused it is unpaused. You can pass a boolean parameter if you want to pause or unpause no matter what the current state is. Modern browsers pauses the game when the page is not visible to the user. If you want the Pause event to be triggered when that happens you can enable autoPause in Crafty.settings.

    Example

    Have an entity pause the game when it is clicked.

    -
    button.bind("click", function() {
    +
    button.bind("click", function() {
         Crafty.pause();
     });
    diff --git a/api/Crafty-pixelart.html b/api/Crafty-pixelart.html index b5e2df2..4ada765 100644 --- a/api/Crafty-pixelart.html +++ b/api/Crafty-pixelart.html @@ -55,22 +55,19 @@ -

    Crafty.pixelart

    public void Crafty.pixelart(Boolean enabled)

    Sets the image smoothing for drawing images (for both DOM and Canvas). -Setting this to true disables smoothing for images, which is the preferred +

    Crafty.pixelart

    public void Crafty.pixelart(Boolean enabled)
    enabled

    whether to preserve sharp edges when rendering images

    +

    Sets the image smoothing for drawing images (for all layer types).

    +

    Setting this to true disables smoothing for images, which is the preferred way for drawing pixel art. Defaults to false.

    This feature is experimental and you should be careful with cross-browser compatibility. The best way to disable image smoothing is to use the Canvas render method and the Sprite component for drawing your entities.

    If you want to switch modes in the middle of a scene, be aware that canvas entities won't be drawn in the new style until something else invalidates them. (You can manually invalidate all canvas entities with Crafty("Canvas").trigger("Invalidate");)

    -

    Note that Firefox_26 currently has a bug -which prevents disabling image smoothing for Canvas entities that use the Image component. Use the Sprite -component instead. -Note that Webkit (Chrome & Safari) currently has a bug link1 -link2 that prevents disabling image smoothing -for DOM entities.

    -

    Example

    This is the preferred way to draw pixel art with the best cross-browser compatibility.

    -
    Crafty.canvas.init();
    +

    Note: Firefox_26 currently has a bug which prevents disabling image smoothing for Canvas entities that use the Image component. Use the Sprite component instead.

    +

    Note: Webkit (Chrome & Safari) currently has a bug link1 link2 that prevents disabling image smoothing for DOM entities.

    +

    Example

    This is the preferred way to draw pixel art with the best cross-browser compatibility.

    +
    Crafty.canvasLayer.init();
     Crafty.pixelart(true);
     
     Crafty.sprite(imgWidth, imgHeight, "spriteMap.png", {sprite1:[0,0]});
    diff --git a/api/Crafty-polygon.html b/api/Crafty-polygon.html
    index 7147412..65449ee 100644
    --- a/api/Crafty-polygon.html
    +++ b/api/Crafty-polygon.html
    @@ -55,24 +55,28 @@
     
     
     
    -

    Crafty.polygon

    Polygon object used for hitboxes and click maps. Must pass an Array for each point as an -argument where index 0 is the x position and index 1 is the y position.

    -

    For example one point of a polygon will look like this: [0,5] where the x is 0 and the y is 5.

    -

    Can pass an array of the points or simply put each point as an argument.

    +

    Crafty.polygon

    The constructor for a polygon object used for hitboxes and click maps. Takes a set of points as an +argument, giving alternately the x and y coordinates of the polygon's vertices in order.

    +

    The constructor accepts the coordinates as either a single array or as a set of individual arguments. +If passed an array, the current implementation will use that array internally -- do not attempt to reuse it.

    When creating a polygon for an entity, each point should be offset or relative from the entities x and y (don't include the absolute values as it will automatically calculate this).

    -

    Example

    new Crafty.polygon([50,0],[100,100],[0,100]);
    -new Crafty.polygon([[50,0],[100,100],[0,100]]);

    Methods and Properties

    Back to top

    .containsPoint

    public Boolean .containsPoint(Number x, Number y)
    x

    X position of the point

    +

    Example

    Two ways to create a triangle with vertices at (50, 0), (100, 100) and (0, 100).

    +
    new Crafty.polygon([50, 0, 100, 100, 0, 100]);
    +new Crafty.polygon(50, 0, 100, 100, 0, 100);

    Methods and Properties

    Back to top

    .clone

    public void .clone()

    Returns a clone of the polygon.

    +

    Example

    var poly = new Crafty.polygon([50, 0, 100, 100, 0, 100]);
    +var shiftedpoly = poly.clone().shift(5,5);
    +//[55, 5, 105, 5, 5, 105], but the original polygon is unchanged
    Back to top

    .containsPoint

    public Boolean .containsPoint(Number x, Number y)
    x

    X position of the point

    y

    Y position of the point

    Method is used to determine if a given point is contained by the polygon.

    -

    Example

    var poly = new Crafty.polygon([50,0],[100,100],[0,100]);
    +

    Example

    var poly = new Crafty.polygon([50, 0, 100, 100, 0, 100]);
     poly.containsPoint(50, 50); //TRUE
    -poly.containsPoint(0, 0); //FALSE
    Back to top

    .shift

    public void .shift(Number x, Number y)
    x

    Amount to shift the x axis

    +poly.containsPoint(0, 0); //FALSE
    Back to top

    .shift

    public void .shift(Number x, Number y)
    x

    Amount to shift the x axis

    y

    Amount to shift the y axis

    Shifts every single point in the polygon by the specified amount.

    -

    Example

    var poly = new Crafty.polygon([50,0],[100,100],[0,100]);
    +

    Example

    var poly = new Crafty.polygon([50, 0, 100, 100, 0, 100]);
     poly.shift(5,5);
    -//[[55,5], [105,5], [5,105]];
    +//[[55, 5, 105, 5, 5, 105];
    diff --git a/api/Crafty-rectManager.html b/api/Crafty-rectManager.html new file mode 100644 index 0000000..4455090 --- /dev/null +++ b/api/Crafty-rectManager.html @@ -0,0 +1,107 @@ + + + + Crafty - Crafty.rectManager + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.rectManager

    Collection of methods for handling rectangles

    +

    Methods and Properties

    Back to top

    Crafty.rectManager.boundingRect

    public Crafty.rectManager.boundingRect(set)
    set

    An array of rectangles

    +
      +
    • Calculate the common bounding rect of multiple canvas entities.
    • +
    • Returns coords
    • +
    +
    Back to top

    Crafty.rectManager.mergeSet

    public Object Crafty.rectManager.mergeSet(Object set)
    set

    an array of rectangular regions

    +

    Merge any consecutive, overlapping rects into each other. +Its an optimization for the redraw regions.

    +

    The order of set isn't strictly meaningful, +but overlapping objects will often cause each other to change, +and so might be consecutive.

    +
    Back to top

    Crafty.rectManager.overlap

    public Boolean Crafty.rectManager.overlap(Object rectA, Object rectA)
    rectA

    An object that must have the _x, _y, _w, _h values as properties

    +
    rectB

    An object that must have the _x, _y, _w, _h values as properties

    +
    [Returns]

    true if the rectangles overlap; false otherwise

    +

    Checks whether two rectangles overlap.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-removeAssets.html b/api/Crafty-removeAssets.html index 4fb3561..46f9b31 100644 --- a/api/Crafty-removeAssets.html +++ b/api/Crafty-removeAssets.html @@ -55,7 +55,7 @@ -

    Crafty.removeAssets

    public void Crafty.removeAssets(Object assets)
    data

    Object JSON formatted (or JSON string), with assets to remove (accepts sounds, images and sprites)

    +

    Crafty.removeAssets

    public void Crafty.removeAssets(Object assets)
    data

    Object JSON formatted (or JSON string), with assets to remove (accepts sounds, images and sprites)

    Removes assets (audio, images, sprites - and related sprite components) in order to allow the browser to free memory.

    Recieves a JSON fomatted object (or JSON string) containing 'audio', 'images' and/or 'sprites' diff --git a/api/Crafty-removeEvent.html b/api/Crafty-removeEvent.html index cde6c26..dc01726 100644 --- a/api/Crafty-removeEvent.html +++ b/api/Crafty-removeEvent.html @@ -55,7 +55,7 @@ -

    Crafty.removeEvent

    public this Crafty.removeEvent(Object ctx, HTMLElement obj, String event, Function callback)
    ctx

    Context of the callback or the value of this

    +

    Crafty.removeEvent

    public this Crafty.removeEvent(Object ctx, HTMLElement obj, String event, Function callback)
    ctx

    Context of the callback or the value of this

    obj

    Element the event is on

    event

    Name of the event

    callback

    Method executed when triggered

    diff --git a/api/Crafty-s.html b/api/Crafty-s.html new file mode 100644 index 0000000..5f21542 --- /dev/null +++ b/api/Crafty-s.html @@ -0,0 +1,104 @@ + + + + Crafty - Crafty.s + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.s

    Registers a system.

    +

    Events

    SystemLoaded [system object = {obj}]
    When the system has initialized itself
    SystemDestroyed [system object = {obj}]
    Right before the system is destroyed
    void Crafty.s(String name, Obj template[, Boolean lazy])

    Register a system

    +
    name

    The name of the system

    +
    template

    an object whose methods and properties will be copied to the new system

    +
    lazy

    a flag that indicates whether the system should be initialized right away or the first time it is referenced

    +
    System Crafty.s(String name)

    Access the named system

    +
    name

    The system to return

    +
    [Returns]

    The referenced system. If the system has not been initialized, it will be before it is returned.

    +

    Objects which handle entities might want to subscribe to the event system without being entities themselves. +When you declare a system with a template object, all the methods and properties of that template are copied to a new object. +This new system will automatically have the following event related methods, which function like those of components: .bind(), unbind(), trigger(), one(), uniqueBind(), destroy(). +Much like components, you can also provide init() and remove() methods, as well as an events parameter for automatically binding to events.

    +

    Note: The init() method is for setting up the internal state of the system -- if you create entities in it that then reference the system, that'll create an infinite loop.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty-scene.html b/api/Crafty-scene.html index 143ae73..40ea48d 100644 --- a/api/Crafty-scene.html +++ b/api/Crafty-scene.html @@ -55,11 +55,11 @@ -

    Crafty.scene

    Events

    SceneChange [ Data { { oldScene:String, newScene:String } }]
    just before a new scene is initialized
    SceneDestroy [ Data { { newScene:String } }]
    just before the current scene is destroyed
    public void Crafty.scene(String sceneName, Function init[, Function uninit])
    sceneName

    Name of the scene to add

    +

    Crafty.scene

    Events

    SceneChange [Data = { oldScene:String, newScene:String }]
    just before a new scene is initialized
    SceneDestroy [Data = { newScene:String }]
    just before the current scene is destroyed
    public void Crafty.scene(String sceneName, Function init[, Function uninit])
    sceneName

    Name of the scene to add

    init

    Function to execute when scene is played

    uninit

    Function to execute before next scene is played, after entities with 2D are destroyed

    This is equivalent to calling Crafty.defineScene.

    -
    public void Crafty.scene(String sceneName[, Data])
    sceneName

    Name of scene to play

    +
    public void Crafty.scene(String sceneName[, Data])
    sceneName

    Name of scene to play

    Data

    The init function of the scene will be called with this data as its parameter. Can be of any type other than a function.

    This is equivalent to calling Crafty.enterScene.

    Method to create scenes on the stage. Pass an ID and function to register a scene.

    @@ -69,7 +69,7 @@

    You can optionally specify an arugment that will be passed to the scene's init function.

    If you want some entities to persist over scenes (as in, not be destroyed) simply add the component Persist.

    -

    Example

    Crafty.defineScene("loading", function() {
    +

    Example

    Crafty.defineScene("loading", function() {
         Crafty.background("#000");
         Crafty.e("2D, DOM, Text")
               .attr({ w: 100, h: 20, x: 150, y: 120 })
    @@ -79,11 +79,11 @@
     });
     
     Crafty.defineScene("UFO_dance",
    -             function() {Crafty.background("#444"); Crafty.e("UFO");},
    -             function() {...send message to server...});
    +             function() {Crafty.background("#444"); Crafty.e("UFO");},
    +             function() {...send message to server...});
     
     // An example of an init function which accepts arguments, in this case an object.
    -Crafty.defineScene("square", function(attributes) {
    +Crafty.defineScene("square", function(attributes) {
         Crafty.background("#000");
         Crafty.e("2D, DOM, Color")
               .attr(attributes)
    diff --git a/api/Crafty-settings.html b/api/Crafty-settings.html
    index a89e579..667dfc6 100644
    --- a/api/Crafty-settings.html
    +++ b/api/Crafty-settings.html
    @@ -55,14 +55,14 @@
     
     
     
    -

    Crafty.settings

    Modify the inner workings of Crafty through the settings.

    -

    Methods and Properties

    Back to top

    Crafty.settings.get

    public * Crafty.settings.get(String settingName)
    settingName

    Name of the setting

    +

    Crafty.settings

    Modify the inner workings of Crafty through the settings.

    +

    Methods and Properties

    Back to top

    Crafty.settings.get

    public * Crafty.settings.get(String settingName)
    settingName

    Name of the setting

    [Returns]

    Current value of the setting

    Returns the current value of the setting.

    -
    Back to top

    Crafty.settings.modify

    public void Crafty.settings.modify(String settingName, * value)
    settingName

    Name of the setting

    +
    Back to top

    Crafty.settings.modify

    public void Crafty.settings.modify(String settingName, * value)
    settingName

    Name of the setting

    value

    Value to set the setting to

    Modify settings through this method.

    -
    Back to top

    Crafty.settings.register

    public void Crafty.settings.register(String settingName, Function callback)
    settingName

    Name of the setting

    +
    Back to top

    Crafty.settings.register

    public void Crafty.settings.register(String settingName, Function callback)
    settingName

    Name of the setting

    callback

    Function to execute when use modifies setting

    Use this to register custom settings. Callback will be executed when Crafty.settings.modify is used.

    See Also

    diff --git a/api/Crafty-sprite.html b/api/Crafty-sprite.html index d0bac41..4c0127e 100644 --- a/api/Crafty-sprite.html +++ b/api/Crafty-sprite.html @@ -55,7 +55,7 @@ -

    Crafty.sprite

    public this Crafty.sprite([Number tile, [Number tileh]], String url, Object map[, Number paddingX[, Number paddingY[, Boolean paddingAroundBorder]]])
    tile

    Tile size of the sprite map, defaults to 1

    +

    Crafty.sprite

    public this Crafty.sprite([Number tile, [Number tileh]], String url, Object map[, Number paddingX[, Number paddingY[, Boolean paddingAroundBorder]]])
    tile

    Tile size of the sprite map, defaults to 1

    tileh

    Height of the tile; if provided, tile is interpreted as the width

    url

    URL of the sprite image

    map

    Object where the key is what becomes a new component and the value points to a position on the sprite map

    diff --git a/api/Crafty-stage.html b/api/Crafty-stage.html index ea68a1a..dfb75f6 100644 --- a/api/Crafty-stage.html +++ b/api/Crafty-stage.html @@ -55,17 +55,12 @@ -

    Crafty.stage

    The stage where all the DOM entities will be placed.

    -

    Methods and Properties

    Back to top

    Crafty.stage.elem

    The #cr-stage div element.

    -
    Back to top

    Crafty.stage.inner

    Crafty.stage.inner is a div inside the #cr-stage div that holds all DOM entities. -If you use canvas, a canvas element is created at the same level in the dom -as the the Crafty.stage.inner div. So the hierarchy in the DOM is

    -
    Crafty.stage.elem
    - - Crafty.stage.inner (a div HTMLElement)
    - - Crafty.canvas._canvas (a canvas HTMLElement)
    Back to top

    Crafty.viewport.reload

    public Crafty.viewport.reload()

    Recalculate and reload stage width, height and position. +

    Crafty.stage

    The stage where all the DOM entities will be placed.

    +

    Methods and Properties

    Back to top

    Crafty.stage.elem

    The #cr-stage div element.

    +
    Back to top

    Crafty.viewport.reload

    public Crafty.viewport.reload()

    Recalculate and reload stage width, height and position. Useful when browser return wrong results on init (like safari on Ipad2). You should also call this method if you insert custom DOM elements that affect Crafty's stage offset.

    -
    Back to top

    Crafty.viewport.reset

    Events

    StopCamera
    called to cancel camera animations
    public Crafty.viewport.reset()

    Resets the viewport to starting values, and cancels any existing camera animations. +

    Back to top

    Crafty.viewport.reset

    Events

    StopCamera
    called to cancel camera animations
    public Crafty.viewport.reset()

    Resets the viewport to starting values, and cancels any existing camera animations. Called when scene() is run.

    diff --git a/api/Crafty-stop.html b/api/Crafty-stop.html index c897ea7..0f72c56 100644 --- a/api/Crafty-stop.html +++ b/api/Crafty-stop.html @@ -55,7 +55,7 @@ -

    Crafty.stop

    Events

    CraftyStop
    when the game is stopped
    public this Crafty.stop([bool clearState])
    clearState

    if true the stage and all game state is cleared.

    +

    Crafty.stop

    Events

    CraftyStop [Data = {bool clearState}]
    when the game is stopped
    public this Crafty.stop([bool clearState])
    clearState

    if true the stage and all game state is cleared.

    Stops the EnterFrame interval and removes the stage element.

    To restart, use Crafty.init().

    See Also

    diff --git a/api/Crafty-support.html b/api/Crafty-support.html index 5591844..3bcbe51 100644 --- a/api/Crafty-support.html +++ b/api/Crafty-support.html @@ -55,17 +55,17 @@ -

    Crafty.support

    Determines feature support for what Crafty can do.

    -

    Methods and Properties

    Back to top

    Crafty.support.audio

    Is HTML5 Audio supported?

    -
    Back to top

    Crafty.support.canvas

    Is the canvas element supported?

    -
    Back to top

    Crafty.support.css3dtransform

    Is css3Dtransform supported by browser.

    -
    Back to top

    Crafty.support.defineProperty

    Is Object.defineProperty supported?

    -
    Back to top

    Crafty.support.devicemotion

    Is devicemotion event supported by browser.

    -
    Back to top

    Crafty.support.deviceorientation

    Is deviceorientation event supported by browser.

    -
    Back to top

    Crafty.support.prefix

    Returns the browser specific prefix (Moz, O, ms, webkit).

    -
    Back to top

    Crafty.support.version

    Version number of the browser as an Integer (first number)

    -
    Back to top

    Crafty.support.versionName

    Version of the browser

    -
    Back to top

    Crafty.support.webgl

    Is WebGL supported on the canvas element?

    +

    Crafty.support

    Determines feature support for what Crafty can do.

    +

    Methods and Properties

    Back to top

    Crafty.support.audio

    Is HTML5 Audio supported?

    +
    Back to top

    Crafty.support.canvas

    Is the canvas element supported?

    +
    Back to top

    Crafty.support.css3dtransform

    Is css3Dtransform supported by browser.

    +
    Back to top

    Crafty.support.defineProperty

    Is Object.defineProperty supported?

    +
    Back to top

    Crafty.support.devicemotion

    Is devicemotion event supported by browser.

    +
    Back to top

    Crafty.support.deviceorientation

    Is deviceorientation event supported by browser.

    +
    Back to top

    Crafty.support.prefix

    Returns the browser specific prefix (Moz, O, ms, webkit, node).

    +
    Back to top

    Crafty.support.version

    Version number of the browser as an Integer (first number)

    +
    Back to top

    Crafty.support.versionName

    Version of the browser

    +
    Back to top

    Crafty.support.webgl

    Is WebGL supported on the canvas element?

    diff --git a/api/Crafty-timer.html b/api/Crafty-timer.html index 885e5b2..c82e5b6 100644 --- a/api/Crafty-timer.html +++ b/api/Crafty-timer.html @@ -55,19 +55,19 @@ -

    Crafty.timer

    Handles game ticks

    -

    Methods and Properties

    Back to top

    Crafty.timer.FPS

    public void Crafty.timer.FPS()

    Returns the target frames per second. This is not an actual frame rate.

    -
    public void Crafty.timer.FPS(Number value)
    value

    the target rate

    -

    Sets the target frames per second. This is not an actual frame rate. +

    Crafty.timer

    Handles game ticks

    +

    Methods and Properties

    Back to top

    Crafty.timer.FPS

    public void Crafty.timer.FPS()

    Returns the target frames per second. This is not an actual frame rate.

    +
    public void Crafty.timer.FPS(Number value)
    value

    the target rate

    +

    Events

    FPSChange [new target FPS = {Number}]
    Triggered when the target FPS is changed by user

    Sets the target frames per second. This is not an actual frame rate. The default rate is 50.

    -
    Back to top

    Crafty.timer.simulateFrames

    public this Crafty.timer.simulateFrames(Number frames[, Number timestep])

    Advances the game state by a number of frames and draws the resulting stage at the end. Useful for tests and debugging.

    +
    Back to top

    Crafty.timer.simulateFrames

    public this Crafty.timer.simulateFrames(Number frames[, Number timestep])

    Advances the game state by a number of frames and draws the resulting stage at the end. Useful for tests and debugging.

    frames

    number of frames to simulate

    timestep

    the duration to pass each frame. Defaults to milliSecPerFrame (20 ms) if not specified.

    -
    Back to top

    Crafty.timer.step

    public void Crafty.timer.step()

    Events

    EnterFrame [ Data { { frame: Number, dt:Number } }]
    Triggered on each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)
    ExitFrame [ Data { { frame: Number, dt:Number } }]
    Triggered after each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)
    PreRender
    Triggered every time immediately before a scene should be rendered
    RenderScene
    Triggered every time a scene should be rendered
    PostRender
    Triggered every time immediately after a scene should be rendered
    MeasureWaitTime [ Data { Number }]
    Triggered at the beginning of each step after the first. Passes the time the game loop waited between steps.
    MeasureFrameTime [ Data { Number }]
    Triggered after each frame. Passes the time it took to advance one frame.
    MeasureRenderTime [ Data { Number }]
    Triggered after each render. Passes the time it took to render the scene

    Advances the game by performing a step. A step consists of one/multiple frames followed by a render. The amount of frames depends on the timer's steptype. +

    Back to top

    Crafty.timer.step

    public void Crafty.timer.step()

    Events

    EnterFrame [Data = { frame: Number, dt:Number }]
    Triggered on each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)
    ExitFrame [Data = { frame: Number, dt:Number }]
    Triggered after each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)
    PreRender
    Triggered every time immediately before a scene should be rendered
    RenderScene
    Triggered every time a scene should be rendered
    PostRender
    Triggered every time immediately after a scene should be rendered
    MeasureWaitTime [Data = {Number}]
    Triggered at the beginning of each step after the first. Passes the time the game loop waited between steps.
    MeasureFrameTime [Data = {Number}]
    Triggered after each frame. Passes the time it took to advance one frame.
    MeasureRenderTime [Data = {Number}]
    Triggered after each render. Passes the time it took to render the scene

    Advances the game by performing a step. A step consists of one/multiple frames followed by a render. The amount of frames depends on the timer's steptype. Specifically it triggers EnterFrame & ExitFrame events for each frame and PreRender, RenderScene & PostRender events for each render.

    -

    See Also

    Back to top

    Crafty.timer.steptype

    public void Crafty.timer.steptype(mode [, maxTimeStep])

    Can be called to set the type of timestep the game loop uses

    +

    See Also

    Back to top

    Crafty.timer.steptype

    public void Crafty.timer.steptype(mode [, maxTimeStep])

    Can be called to set the type of timestep the game loop uses

    mode

    the type of time loop. Allowed values are "fixed", "semifixed", and "variable". Crafty defaults to "fixed".

    -
    mode

    For "fixed", sets the max number of frames per step. For "variable" and "semifixed", sets the maximum time step allowed.

    +
    maxTimeStep

    For "fixed", sets the max number of frames per step. For "variable" and "semifixed", sets the maximum time step allowed.

    diff --git a/api/Crafty-trigger.html b/api/Crafty-trigger.html index 4bd9b9c..7cbf302 100644 --- a/api/Crafty-trigger.html +++ b/api/Crafty-trigger.html @@ -55,7 +55,7 @@ -

    Crafty.trigger

    public void Crafty.trigger(String eventName, * data)
    eventName

    Name of the event to trigger

    +

    Crafty.trigger

    public void Crafty.trigger(String eventName, * data)
    eventName

    Name of the event to trigger

    data

    Arbitrary data to pass into the callback as an argument

    This method will trigger every single callback attached to the event name. This means every global event and every entity that has a callback.

    diff --git a/api/Crafty-unbind.html b/api/Crafty-unbind.html index 5667804..2ee91a6 100644 --- a/api/Crafty-unbind.html +++ b/api/Crafty-unbind.html @@ -55,12 +55,9 @@ -

    Crafty.unbind

    public Boolean Crafty.unbind(String eventName, Function callback)
    eventName

    Name of the event to unbind

    +

    Crafty.unbind

    public Boolean Crafty.unbind(String eventName, Function callback)
    eventName

    Name of the event to unbind

    callback

    Function to unbind

    -
    public Boolean Crafty.unbind(String eventName, Number callbackID)
    callbackID

    ID of the callback

    -
    [Returns]

    True or false depending on if a callback was unbound

    -

    Unbind any event from any entity or global event.

    -

    Example

       var play_gameover_sound = function () {...};
    +

    Example

       var play_gameover_sound = function () {...};
        Crafty.bind('GameOver', play_gameover_sound);
        ...
        Crafty.unbind('GameOver', play_gameover_sound);

    The first line defines a callback function. The second line binds that diff --git a/api/Crafty-uniqueBind.html b/api/Crafty-uniqueBind.html index 88bfa3d..93d3148 100644 --- a/api/Crafty-uniqueBind.html +++ b/api/Crafty-uniqueBind.html @@ -55,7 +55,7 @@ -

    Crafty.uniqueBind

    public Number uniqueBind(String eventName, Function callback)
    eventName

    Name of the event to bind to

    +

    Crafty.uniqueBind

    public Function uniqueBind(String eventName, Function callback)
    eventName

    Name of the event to bind to

    callback

    Method to execute upon event triggered

    [Returns]

    callback function which can be used for unbind

    Works like Crafty.bind, but prevents a callback from being bound multiple times.

    diff --git a/api/Crafty-viewport.html b/api/Crafty-viewport.html index 8dbc03c..615a3e1 100644 --- a/api/Crafty-viewport.html +++ b/api/Crafty-viewport.html @@ -55,51 +55,69 @@ -

    Crafty.viewport

    Events

    ViewportScroll
    when the viewport's x or y coordinates change
    ViewportScale
    when the viewport's scale changes
    ViewportResize
    when the viewport's dimension's change
    InvalidateViewport
    when the viewport changes
    StopCamera
    when any camera animations should stop, such as at the start of a new animation.
    CameraAnimationDone
    when a camera animation comes reaches completion

    Viewport is essentially a 2D camera looking at the stage. Can be moved or zoomed, which +

    Crafty.viewport

    Events

    ViewportScroll
    when the viewport's x or y coordinates change
    ViewportScale
    when the viewport's scale changes
    ViewportResize
    when the viewport's dimension's change
    InvalidateViewport
    when the viewport changes
    StopCamera
    when any camera animations should stop, such as at the start of a new animation.
    CameraAnimationDone
    when a camera animation reaches completion

    Viewport is essentially a 2D camera looking at the stage. Can be moved or zoomed, which in turn will react just like a camera moving in that direction.

    +

    There are multiple camera animation methods available - these are the viewport methods with an animation time parameter and the follow method. +Only one animation can run at a time. Starting a new animation will cancel the previous one and the appropriate events will be fired.

    Tip: At any given moment, the stuff that you can see is...

    x between (-Crafty.viewport._x) and (-Crafty.viewport._x + (Crafty.viewport._width / Crafty.viewport._scale))

    y between (-Crafty.viewport._y) and (-Crafty.viewport._y + (Crafty.viewport._height / Crafty.viewport._scale))

    -

    Methods and Properties

    Back to top

    Crafty.viewport._scale

    This value is the current scale (zoom) of the viewport. When the value is bigger than 1, everything +

    Example

    Prevent viewport from adjusting itself when outside the game world. +Scale the viewport so that entities appear twice as large. +Then center the viewport on an entity over the duration of 3 seconds. +After that animation finishes, start following the entity.

    +
    var ent = Crafty.e('2D, DOM').attr({x: 250, y: 250, w: 100, h: 100});
    +
    +Crafty.viewport.clampToEntities = false;
    +Crafty.viewport.scale(2);
    +Crafty.one("CameraAnimationDone", function() {
    +    Crafty.viewport.follow(ent, 0, 0);
    +});
    +Crafty.viewport.centerOn(ent, 3000);

    Methods and Properties

    Back to top

    Crafty.viewport._scale

    This value is the current scale (zoom) of the viewport. When the value is bigger than 1, everything looks bigger (zoomed in). When the value is less than 1, everything looks smaller (zoomed out). This does not alter the size of the stage itself, just the magnification of what it shows.

    This is a read-only property: Do not set it directly. Instead, use Crafty.viewport.scale(...) or Crafty.viewport.zoom(...)

    -
    Back to top

    Crafty.viewport.bounds

    A rectangle which defines the bounds of the viewport. +

    Back to top

    Crafty.viewport.bounds

    A rectangle which defines the bounds of the viewport. It should be an object with two properties, max and min, which are each an object with x and y properties.

    If this property is null, Crafty uses the bounding box of all the items on the stage. This is the initial value. (To prevent this behavior, set Crafty.viewport.clampToEntities to false)

    If you wish to bound the viewport along one axis but not the other, you can use -Infinity and +Infinity as bounds.

    -

    Example

    Set the bounds to a 500 by 500 square:

    -
    Crafty.viewport.bounds = {min:{x:0, y:0}, max:{x:500, y:500}};
    Back to top

    Crafty.viewport.centerOn

    public void Crafty.viewport.centerOn(Object target, Number time)
    Object target

    An entity with the 2D component

    +

    Example

    Set the bounds to a 500 by 500 square:

    +
    Crafty.viewport.bounds = {min:{x:0, y:0}, max:{x:500, y:500}};
    Back to top

    Crafty.viewport.centerOn

    public void Crafty.viewport.centerOn(Object target, Number time)
    Object target

    An entity with the 2D component

    Number time

    The duration in ms of the camera motion

    Centers the viewport on the given entity.

    -
    Back to top

    Crafty.viewport.clampToEntities

    Decides if the viewport functions should clamp to game entities. +

    Example

    var ent = Crafty.e('2D, DOM').attr({x: 250, y: 250, w: 100, h: 100});
    +Crafty.viewport.centerOn(ent, 3000);
    Back to top

    Crafty.viewport.clampToEntities

    Decides if the viewport functions should clamp to game entities. When set to true functions such as Crafty.viewport.mouselook() will not allow you to move the viewport over areas of the game that has no entities. For development it can be useful to set this to false.

    -
    Back to top

    Crafty.viewport.follow

    public void Crafty.viewport.follow(Object target, Number offsetx, Number offsety)
    Object target

    An entity with the 2D component

    -
    Number offsetx

    Follow target should be offsetx pixels away from center

    -
    Number offsety

    Positive puts target to the right of center

    +
    Back to top

    Crafty.viewport.follow

    public void Crafty.viewport.follow(Object target, Number offsetx, Number offsety)
    Object target

    An entity with the 2D component

    +
    Number offsetx

    Follow target's center should be offsetx pixels away from viewport's center. Positive values puts target to the right of the screen.

    +
    Number offsety

    Follow target's center should be offsety pixels away from viewport's center. Positive values puts target to the bottom of the screen.

    Follows a given entity with the 2D component. If following target will take a portion of the viewport out of bounds of the world, following will stop until the target moves away.

    -

    Example

    var ent = Crafty.e('2D, DOM').attr({w: 100, h: 100:});
    -Crafty.viewport.follow(ent, 0, 0);
    Back to top

    Crafty.viewport.init

    public void Crafty.viewport.init([Number width, Number height, String stage_elem])
    public void Crafty.viewport.init([Number width, Number height, HTMLElement stage_elem])
    Number width

    Width of the viewport

    +

    Example

    var ent = Crafty.e('2D, DOM').attr({w: 100, h: 100});
    +Crafty.viewport.follow(ent, 0, 0);
    Back to top

    Crafty.viewport.init

    public void Crafty.viewport.init([Number width, Number height, String stage_elem])
    public void Crafty.viewport.init([Number width, Number height, HTMLElement stage_elem])
    Number width

    Width of the viewport

    Number height

    Height of the viewport

    String or HTMLElement stage_elem

    the element to use as the stage (either its id or the actual element).

    -

    Initialize the viewport. If the arguments 'width' or 'height' are missing, use Crafty.DOM.window.width and Crafty.DOM.window.height (full screen model).

    +

    Initialize the viewport. If the arguments 'width' or 'height' are missing, use window.innerWidth and window.innerHeight (full screen model).

    The argument 'stage_elem' is used to specify a stage element other than the default, and can be either a string or an HTMLElement. If a string is provided, it will look for an element with that id and, if none exists, create a div. If an HTMLElement is provided, that is used directly. Omitting this argument is the same as passing an id of 'cr-stage'.

    -
    Back to top

    Crafty.viewport.mouselook

    public void Crafty.viewport.mouselook(Boolean active)
    Boolean active

    Activate or deactivate mouselook

    +
    Back to top

    Crafty.viewport.mouselook

    public void Crafty.viewport.mouselook(Boolean active)
    Boolean active

    Activate or deactivate mouselook

    Toggle mouselook on the current viewport. Simply call this function and the user will be able to drag the viewport around.

    If the user starts a drag, "StopCamera" will be triggered, which will cancel any existing camera animations.

    -
    Back to top

    Crafty.viewport.pan

    public void Crafty.viewport.pan(Number dx, Number dy, Number time)
    Number dx

    The distance along the x axis

    +
    Back to top

    Crafty.viewport.onScreen

    public Crafty.viewport.onScreen(Object rect)
    rect

    A rectangle with field {_x: x_val, _y: y_val, _w: w_val, _h: h_val}

    +

    Test if a rectangle is completely in viewport

    +
    Back to top

    Crafty.viewport.pan

    public void Crafty.viewport.pan(Number dx, Number dy, Number time[, String|function easingFn])
    Number dx

    The distance along the x axis

    Number dy

    The distance along the y axis

    Number time

    The duration in ms for the entire camera movement

    +
    easingFn

    A string or custom function specifying an easing. (Defaults to linear behavior.) See Crafty.easing for more information.

    Pans the camera a given number of pixels over the specified time

    -
    Back to top

    Crafty.viewport.scale

    public void Crafty.viewport.scale(Number amt)
    Number amt

    amount to zoom/scale in on the elements

    +

    Example

    // pan the camera 100 px right and down over the duration of 2 seconds using linear easing behaviour
    +Crafty.viewport.pan(100, 100, 2000);
    Back to top

    Crafty.viewport.scale

    public void Crafty.viewport.scale(Number amt)
    Number amt

    amount to zoom/scale in on the elements

    Adjusts the scale (zoom). When amt is 1, it is set to the normal scale, e.g. an entity with this.w == 20 would appear exactly 20 pixels wide. When amt is 10, that same entity would appear 200 pixels wide (i.e., zoomed in @@ -107,29 +125,31 @@ (i.e., zoomed out by a factor of (1 / 0.1)).

    If you pass an amt of 0, it is treated the same as passing 1, i.e. the scale is reset.

    This method sets the absolute scale, while Crafty.viewport.zoom sets the scale relative to the existing value.

    -

    See Also

    Example

    Crafty.viewport.scale(2); // Zoom in -- all entities will appear twice as large.
    Back to top

    Crafty.viewport.scroll

    Crafty.viewport.scroll(String axis, Number val)
    axis

    'x' or 'y'

    +

    See Also

    Example

    Crafty.viewport.scale(2); // Zoom in -- all entities will appear twice as large.
    Back to top

    Crafty.viewport.scroll

    Crafty.viewport.scroll(String axis, Number val)
    axis

    'x' or 'y'

    val

    The new absolute position on the axis

    Will move the viewport to the position given on the specified axis

    Example

    Will move the camera 500 pixels right of its initial position, in effect shifting everything in the viewport 500 pixels to the left.

    -
    Crafty.viewport.scroll('_x', 500);
    Back to top

    Crafty.viewport.x

    Will move the stage and therefore every visible entity along the x +

    Crafty.viewport.scroll('_x', 500);
    Back to top

    Crafty.viewport.x

    Will move the stage and therefore every visible entity along the x axis in the opposite direction.

    When this value is set, it will shift the entire stage. This means that entity positions are not exactly where they are on screen. To get the exact position, simply add Crafty.viewport.x onto the entities x position.

    -
    Back to top

    Crafty.viewport.y

    Will move the stage and therefore every visible entity along the y +

    Back to top

    Crafty.viewport.y

    Will move the stage and therefore every visible entity along the y axis in the opposite direction.

    When this value is set, it will shift the entire stage. This means that entity positions are not exactly where they are on screen. To get the exact position, simply add Crafty.viewport.y onto the entities y position.

    -
    Back to top

    Crafty.viewport.zoom

    public void Crafty.viewport.zoom(Number amt, Number cent_x, Number cent_y, Number time)
    Number amt

    amount to zoom in on the target by (eg. 2, 4, 0.5)

    +
    Back to top

    Crafty.viewport.zoom

    public void Crafty.viewport.zoom(Number amt, Number cent_x, Number cent_y, Number time[, String|function easingFn])
    Number amt

    amount to zoom in on the target by (eg. 2, 4, 0.5)

    Number cent_x

    the center to zoom on

    Number cent_y

    the center to zoom on

    Number time

    the duration in ms of the entire zoom operation

    +
    easingFn

    A string or custom function specifying an easing. (Defaults to linear behavior.) See Crafty.easing for more information.

    Zooms the camera in on a given point. amt > 1 will bring the camera closer to the subject amt < 1 will bring it farther away. amt = 0 will reset to the default zoom level Zooming is multiplicative. To reset the zoom amount, pass 0.

    -
    +

    Example

    // Make the entities appear twice as large by zooming in on the specified coordinates over the duration of 3 seconds using linear easing behavior
    +Crafty.viewport.zoom(2, 100, 100, 3000);
    diff --git a/api/Crafty-webgl.html b/api/Crafty-webgl.html new file mode 100644 index 0000000..16f1d66 --- /dev/null +++ b/api/Crafty-webgl.html @@ -0,0 +1,96 @@ + + + + Crafty - Crafty.webgl + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Crafty.webgl

    A collection of methods to handle webgl contexts.

    +

    Methods and Properties

    Back to top

    Crafty.webgl.context

    This will return the context of the webgl canvas element.

    +
    Back to top

    Crafty.webgl.init

    public void Crafty.webgl.init(void)

    Events

    NoWebGL
    triggered if `Crafty.support.webgl` is false

    This will create a canvas element inside Crafty.stage.elem, used for displaying "WebGL" components.

    +

    This method will automatically be called by any "WebGL" component if no Crafty.webgl.context is +found, so it is not neccessary to call this manually.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/Crafty.html b/api/Crafty.html index 6feec4c..cac060a 100644 --- a/api/Crafty.html +++ b/api/Crafty.html @@ -55,10 +55,16 @@ -

    Crafty

    Select a set of or single entities by components or an entity's ID.

    +

    Crafty

    Crafty is both an object, and a function for selecting entities. +Its many methods and properties are discussed individually. +Below is the documentation for use as a selector.

    +
    public EntitySelection Crafty( String selector)
    selector

    A string representing which entities to select

    +
    public Entity Crafty( Number selector )
    selector

    An entity's id

    +

    Select a set of or single entities by components or an entity's ID.

    Crafty uses syntax similar to jQuery by having a selector engine to select entities by their components.

    If there is more than one match, the return value is an Array-like object listing the ID numbers of each matching entity. If there is exactly one match, the entity itself is returned. If you're not sure how many matches to expect, check the number of matches via Crafty(...).length. Alternatively, use Crafty(...).each(...), which works in all cases.

    -

    Example

       Crafty("MyComponent")
    +

    Note: You can treat an entity as if it was a selection of length 1 -- it implements all the same methods.

    +

    Example

       Crafty("MyComponent")
        Crafty("Hello 2D Component")
        Crafty("Hello, 2D, Component")

    The first selector will return all entities that have the component MyComponent. The second will return all entities that have Hello and 2D and Component whereas the last will return all entities that have at least one of those components (or).

      Crafty("*")

    Passing * will select all entities.

    @@ -66,7 +72,7 @@

    To work directly with an array of entities, use the get() method on a selection. To call a function in the context of each entity, use the .each() method.

    The event related methods such as bind and trigger will work on selections of entities.

    -

    See Also

    +
    diff --git a/api/DOM.html b/api/DOM.html index 44d1083..2d65a0d 100644 --- a/api/DOM.html +++ b/api/DOM.html @@ -55,12 +55,12 @@ -

    DOM

    Draws entities as DOM nodes, specifically <DIV>s.

    -

    Methods and Properties

    Back to top

    ._element

    The DOM element used to represent the entity.

    -
    Back to top

    .avoidCss3dTransforms

    Avoids using of CSS 3D Transform for positioning when true. Default value is false.

    -
    Back to top

    .css

    public css(String property, String value)
    property

    CSS property to modify

    +

    DOM

    A component which renders entities as DOM nodes, specifically <div>s.

    +

    Methods and Properties

    Back to top

    ._element

    The DOM element used to represent the entity.

    +
    Back to top

    .avoidCss3dTransforms

    Avoids using of CSS 3D Transform for positioning when true. Default value is false.

    +
    Back to top

    .css

    public css(String property, String value)
    property

    CSS property to modify

    value

    Value to give the CSS property

    -
    public css(Object map)
    map

    Object where the key is the CSS property and the value is CSS value

    +
    public css(Object map)
    map

    Object where the key is the CSS property and the value is CSS value

    Apply CSS styles to the element.

    Can pass an object where the key is the style property and the value is style value.

    For setting one style, simply pass the style as the first argument and the value as the second.

    @@ -70,11 +70,11 @@ .textFont() and .textColor(), and ignore .css() settings. See Text component for details.

    Example

    this.css({'text-align': 'center', 'text-decoration': 'line-through'});
     this.css("textAlign", "center");
    -this.css("text-align"); //returns center
    Back to top

    .DOM

    Events

    Draw [ Data { { style:String, type:"DOM", co} }]
    when the entity is ready to be drawn to the stage
    public this .DOM(HTMLElement elem)
    elem

    HTML element that will replace the dynamically created one

    +this.css("text-align"); //returns center
    Back to top

    .DOM

    Events

    Draw [Data = { style:String, type:"DOM", co}]
    when the entity is ready to be drawn to the stage
    public this .DOM(HTMLElement elem)
    elem

    HTML element that will replace the dynamically created one

    Pass a DOM element to use rather than one created. Will set ._element to this value. Removes the old element.

    -
    Back to top

    .draw

    public this .draw(void)

    Updates the CSS properties of the node to draw on the stage.

    -
    Back to top

    .getDomId

    public this .getId()

    Get the Id of the DOM element used to represent the entity.

    -
    Back to top

    .undraw

    public this .undraw(void)

    Removes the element from the stage.

    +
    Back to top

    .draw

    public this .draw(void)

    Updates the CSS properties of the node to draw on the stage.

    +
    Back to top

    .getDomId

    public this .getId()

    Get the Id of the DOM element used to represent the entity.

    +
    Back to top

    .undraw

    public this .undraw(void)

    Removes the element from the stage.

    diff --git a/api/DebugCanvas.html b/api/DebugCanvas.html index 4b1d949..74ff428 100644 --- a/api/DebugCanvas.html +++ b/api/DebugCanvas.html @@ -55,12 +55,12 @@ -

    DebugCanvas

    Events

    Draw
    when the entity is ready to be drawn to the stage
    NoCanvas
    if the browser does not support canvas

    When this component is added to an entity it will be drawn by the DebugCanvas layer.

    +

    DebugCanvas

    Events

    Draw
    when the entity is ready to be drawn to the stage
    NoCanvas
    if the browser does not support canvas

    When this component is added to an entity it will be drawn by the DebugCanvas layer.

    Crafty.debugCanvas.init() will be automatically called if it is not called already to initialize the canvas element.

    To visualise an object's MBR, use "VisibleMBR". To visualise a "Collision" object's hitbox, use "WiredHitBox" or "SolidHitBox".

    -

    Methods and Properties

    Back to top

    .debugAlpha

    public .debugAlpha(Number alpha)
    alpha

    The alpha level the component will be drawn with

    -
    Back to top

    .debugFill

    public .debugFill([String fillStyle])
    fillStyle

    The color the component will be filled with. Defaults to "red". Pass the boolean false to turn off filling.

    -

    Example

    var myEntity = Crafty.e("2D, Collision, SolidHitBox ").debugFill("purple")
    Back to top

    .debugStroke

    public .debugStroke([String strokeStyle])
    strokeStyle

    The color the component will be outlined with. Defaults to "red". Pass the boolean false to turn this off.

    +

    Methods and Properties

    Back to top

    .debugAlpha

    public .debugAlpha(Number alpha)
    alpha

    The alpha level the component will be drawn with

    +
    Back to top

    .debugFill

    public .debugFill([String fillStyle])
    fillStyle

    The color the component will be filled with. Defaults to "red". Pass the boolean false to turn off filling.

    +

    Example

    var myEntity = Crafty.e("2D, Collision, SolidHitBox ").debugFill("purple")
    Back to top

    .debugStroke

    public .debugStroke([String strokeStyle])
    strokeStyle

    The color the component will be outlined with. Defaults to "red". Pass the boolean false to turn this off.

    Example

    var myEntity = Crafty.e("2D, Collision, WiredHitBox ").debugStroke("white")
    diff --git a/api/DebugPolygon.html b/api/DebugPolygon.html index 3197296..0058912 100644 --- a/api/DebugPolygon.html +++ b/api/DebugPolygon.html @@ -55,10 +55,10 @@ -

    DebugPolygon

    For drawing a polygon to the debug canvas

    +

    DebugPolygon

    For drawing a polygon to the debug canvas

    The methods of DebugCanvas can be used to control this component's appearance -- by default it is neither filled nor outlined

    For debugging hitboxes, use WiredHitBox or SolidHitBox. For debugging MBR, use VisibleMBR

    -

    See Also

    Methods and Properties

    Back to top

    .debugPolygon

    public .debugPolygon(Polygon poly)
    poly

    a polygon to render

    +

    See Also

    Methods and Properties

    Back to top

    .debugPolygon

    public .debugPolygon(Polygon poly)
    poly

    a polygon to render

    Sets the polygon that this component renders to the debug canvas.

    diff --git a/api/DebugRectangle.html b/api/DebugRectangle.html index 6ffd77b..1727f63 100644 --- a/api/DebugRectangle.html +++ b/api/DebugRectangle.html @@ -55,11 +55,11 @@ -

    DebugRectangle

    A component for rendering an object with a position and dimensions to the debug canvas.

    +

    DebugRectangle

    A component for rendering an object with a position and dimensions to the debug canvas.

    var myEntity = Crafty.e("2D, DebugRectangle")
                          .attr({x: 13, y: 37, w: 42, h: 42})
                          .debugStroke("green");
    -myEntity.debugRectangle(myEntity)

    See Also

    Methods and Properties

    Back to top

    .debugRectangle

    public .debugRectangle(Object rect)
    rect

    an object with _x, _y, _w, and _h to draw

    +myEntity.debugRectangle(myEntity)

    See Also

    Methods and Properties

    Back to top

    .debugRectangle

    public .debugRectangle(Object rect)
    rect

    an object with _x, _y, _w, and _h to draw

    Sets the rectangle that this component draws to the debug canvas.

    diff --git a/api/Delay.html b/api/Delay.html index 57173a8..8d0e611 100644 --- a/api/Delay.html +++ b/api/Delay.html @@ -55,38 +55,36 @@ -

    Delay

    Methods and Properties

    Back to top

    .cancelDelay

    public this.cancelDelay(Function callback)
    callback

    Method reference passed to .delay

    +

    Delay

    A component for triggering functions after a given amount of time.

    +

    This syncs with Crafty's internal clock, and so should generally be preferred to using methods such as setTimeout.

    +

    Methods and Properties

    Back to top

    .cancelDelay

    public this.cancelDelay(Function callback)
    callback

    Method reference passed to .delay

    The cancelDelay method will cancel a delay set previously.

    -

    Example

    var doSomething = function(){
    -  console.log("doing something");
    +

    Example

    var doSomething = function(){
    +  Crafty.log("doing something");
     };
     
     // execute doSomething each 100 miliseconds indefinetely
     var ent = Crafty.e("Delay").delay(doSomething, 100, -1);
     
     // and some time later, cancel further execution of doSomething
    -ent.cancelDelay(doSomething);
    Back to top

    .delay

    public this.delay(Function callback, Number delay[, Number repeat[, Function callbackOff]])
    callback

    Method to execute after given amount of milliseconds. If reference of a

    -

    method is passed, there's possibility to cancel the delay.

    -
    delay

    Amount of milliseconds to execute the method.

    -
    repeat

    (optional) How often to repeat the delayed function. A value of 0 triggers the delayed

    -

    function exactly once. A value n > 0 triggers the delayed function exactly n+1 times. A -value of -1 triggers the delayed function indefinitely. Defaults to one execution.

    -
    callbackOff

    (optional) Method to execute after delay ends(after all iterations are executed).

    -

    If repeat value equals -1, callbackOff will never be triggered.

    -

    The delay method will execute a function after a given amount of time in milliseconds.

    +ent.cancelDelay(doSomething);
    Back to top

    .delay

    public this.delay(Function callback, Number delay[, Number repeat[, Function callbackOff]])
    callback

    Method to execute after given amount of milliseconds. If reference of a method is passed, there's possibility to cancel the delay.

    +
    delay

    Amount of milliseconds to execute the method.

    +
    repeat

    (optional) How often to repeat the delayed function. A value of 0 triggers the delayed function exactly once. A value n > 0 triggers the delayed function exactly n+1 times. A value of -1 triggers the delayed function indefinitely. Defaults to one execution.

    +
    callbackOff

    (optional) Method to execute after delay ends(after all iterations are executed). If repeat value equals -1, callbackOff will never be triggered.

    +

    The delay method will execute a function after a given amount of time in milliseconds.

    It is not a wrapper for setTimeout.

    If Crafty is paused, the delay is interrupted with the pause and then resume when unpaused

    If the entity is destroyed, the delay is also destroyed and will not have effect.

    Example

    The simplest delay

    -
    console.log("start");
    -Crafty.e("Delay").delay(function() {
    -  console.log("100ms later");
    +
    Crafty.log("start");
    +Crafty.e("Delay").delay(function() {
    +  Crafty.log("100ms later");
     }, 100, 0);

    Delay with callbackOff to be executed after all delay iterations

    -
    console.log("start");
    -Crafty.e("Delay").delay(function() {
    -  console.log("100ms later");
    -}, 100, 3, function() {
    -  console.log("delay finished");
    +
    Crafty.log("start");
    +Crafty.e("Delay").delay(function() {
    +  Crafty.log("100ms later");
    +}, 100, 3, function() {
    +  Crafty.log("delay finished");
     });
    diff --git a/api/Draggable.html b/api/Draggable.html index 0405622..7dffafb 100644 --- a/api/Draggable.html +++ b/api/Draggable.html @@ -55,13 +55,14 @@ -

    Draggable

    Enable drag and drop of the entity.

    -

    Events

    Dragging [ Data { MouseEvent }]
    is triggered each frame the entity is being dragged
    StartDrag [ Data { MouseEvent }]
    is triggered when dragging begins
    StopDrag [ Data { MouseEvent }]
    is triggered when dragging ends

    Methods and Properties

    Back to top

    ._startDrag

    Internal method for starting a drag of an entity either programatically or via Mouse click

    -
    e

    a mouse event

    -
    Back to top

    .disableDrag

    public this .disableDrag(void)

    Stops entity from being draggable. Reenable with .enableDrag().

    -

    See Also

    Back to top

    .dragDirection

    public this .dragDirection()

    Remove any previously specified direction.

    -
    public this .dragDirection(vector)
    vector

    Of the form of {x: valx, y: valy}, the vector (valx, valy) denotes the move direction.

    -
    public this .dragDirection(degree)
    degree

    A number, the degree (clockwise) of the move direction with respect to the x axis.

    +

    Draggable

    Enable drag and drop of the entity. Listens to events from MouseDrag and moves entity accordingly.

    +

    See Also

    Methods and Properties

    Back to top

    .disableDrag

    public this .disableDrag(void)

    Disables entity dragging. Reenable with .enableDrag().

    +

    See Also

    Back to top

    .dragDirection

    Method used for modifying the drag direction. +If direction is set, the entity being dragged will only move along the specified direction. +If direction is not set, the entity being dragged will move along any direction.

    +
    public this .dragDirection()

    Remove any previously specified direction.

    +
    public this .dragDirection(vector)
    vector

    Of the form of {x: valx, y: valy}, the vector (valx, valy) denotes the move direction.

    +
    public this .dragDirection(degree)
    degree

    A number, the degree (clockwise) of the move direction with respect to the x axis.

    Specify the dragging direction.

    Example

    this.dragDirection()
     this.dragDirection({x:1, y:0}) //Horizontal
    @@ -69,10 +70,8 @@
     // Note: because of the orientation of x and y axis,
     // this is 45 degree clockwise with respect to the x axis.
     this.dragDirection({x:1, y:1}) //45 degree.
    -this.dragDirection(60) //60 degree.
    Back to top

    .enableDrag

    public this .enableDrag(void)

    Rebind the mouse events. Use if .disableDrag has been called.

    -

    See Also

    Back to top

    .startDrag

    public this .startDrag(void)

    Make the entity follow the mouse positions.

    -

    See Also

    Back to top

    .stopDrag

    public this .stopDrag(void)

    Events

    StopDrag
    Called right after the mouse listeners are removed

    Stop the entity from dragging. Essentially reproducing the drop.

    -

    See Also

    +this.dragDirection(60) //60 degree.
    Back to top

    .enableDrag

    public this .enableDrag(void)

    Reenable dragging of entity. Use if .disableDrag has been called.

    +

    See Also

    diff --git a/api/Fourway.html b/api/Fourway.html index 362a529..d1d9c7f 100644 --- a/api/Fourway.html +++ b/api/Fourway.html @@ -55,13 +55,11 @@ -

    Fourway

    Move an entity in four directions by using the +

    Fourway

    Events

    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.

    Move an entity in four directions by using the arrow keys or W, A, S, D.

    -

    Methods and Properties

    Back to top

    .fourway

    public this .fourway(Number speed)
    speed

    Amount of pixels to move the entity whilst a key is down

    +

    See Also

    Methods and Properties

    Back to top

    .fourway

    public this .fourway([Number speed])
    speed

    The speed of motion in pixels per second.

    Constructor to initialize the speed. Component will listen for key events and move the entity appropriately. This includes Up Arrow, Right Arrow, Down Arrow, Left Arrow as well as W, A, S, D.

    -

    When direction changes a NewDirection event is triggered with an object detailing the new direction: {x: x_movement, y: y_movement} -When entity has moved on either x- or y-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}

    The key presses will move the entity in that direction by the speed passed in the argument.

    See Also

    diff --git a/api/Gravity.html b/api/Gravity.html index 7988220..52c6dd5 100644 --- a/api/Gravity.html +++ b/api/Gravity.html @@ -55,23 +55,24 @@ -

    Gravity

    Events

    Moved
    When entity has moved on y-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}

    Adds gravitational pull to the entity.

    -

    Methods and Properties

    Back to top

    .antigravity

    public this .antigravity()

    Disable gravity for this component. It can be reenabled by calling .gravity()

    -
    Back to top

    .gravity

    public this .gravity([comp])
    comp

    The name of a component that will stop this entity from falling

    -

    Enable gravity for this entity no matter whether comp parameter is not specified, +

    Gravity

    Events

    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.
    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.

    Adds gravitational pull to the entity.

    +

    Methods and Properties

    Back to top

    .antigravity

    public this .antigravity()

    Disable gravity for this component. It can be reenabled by calling .gravity()

    +
    Back to top

    .gravity

    public this .gravity([comp])
    comp

    The name of a component that will stop this entity from falling

    +

    Enable gravity for this entity no matter whether comp parameter is specified or not. If comp parameter is specified all entities with that component will stop this entity from falling. For a player entity in a platform game this would be a component that is added to all entities -that the player should be able to walk on.

    +that the player should be able to walk on. +See the Supportable component documentation for additional methods & events that are available.

    Example

    Crafty.e("2D, DOM, Color, Gravity")
       .color("red")
       .attr({ w: 100, h: 100 })
    -  .gravity("platform");
    Back to top

    .gravityConst

    public this .gravityConst(g)
    g

    gravitational constant

    -

    Set the gravitational constant to g. The default is .2. The greater g, the faster the object falls.

    + .gravity("platform");
    Back to top

    .gravityConst

    public this .gravityConst(g)
    g

    gravitational constant in pixels per second squared

    +

    Set the gravitational constant to g for this entity. The default is 500. The greater g, the stronger the downwards acceleration.

    Example

    Crafty.e("2D, DOM, Color, Gravity")
       .color("red")
       .attr({ w: 100, h: 100 })
    -  .gravity("platform")
    -  .gravityConst(2)
    + .gravityConst(5) + .gravity("platform");
    diff --git a/api/GroundAttacher.html b/api/GroundAttacher.html new file mode 100644 index 0000000..62d2d26 --- /dev/null +++ b/api/GroundAttacher.html @@ -0,0 +1,94 @@ + + + + Crafty - GroundAttacher + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    GroundAttacher

    Component that attaches the entity to the ground when it lands. Useful for platformers with moving platforms. +Remove the component to disable the functionality.

    +

    Example

    Crafty.e("2D, Gravity, GroundAttacher")
    +    .gravity("Platform"); // entity will land on and move with entites that have the "Platform" component
    + +
    +
    +
    + +
    + + diff --git a/api/HTML.html b/api/HTML.html index cdf1dc1..bd4b9d2 100644 --- a/api/HTML.html +++ b/api/HTML.html @@ -55,18 +55,19 @@ -

    HTML

    Component allow for insertion of arbitrary HTML into an entity

    -

    Methods and Properties

    Back to top

    .append

    public this .append(String html)
    html

    arbitrary html

    +

    HTML

    A component which allows for the insertion of arbitrary HTML into a DOM entity.

    +

    Adding this to an entity will automatically add the DOM component.

    +

    Methods and Properties

    Back to top

    .append

    public this .append(String html)
    html

    arbitrary html

    This method will add the supplied html in the end of the entity

    Example

    Create a link

    Crafty.e("HTML")
        .attr({x:20, y:20, w:100, h:100})
    -   .append("<a href='index.html'>Index</a>");
    Back to top

    .prepend

    public this .prepend(String html)
    html

    arbitrary html

    + .append("<a href='index.html'>Index</a>");
    Back to top

    .prepend

    public this .prepend(String html)
    html

    arbitrary html

    This method will add the supplied html in the beginning of the entity

    Example

    Create a link

    Crafty.e("HTML")
        .attr({x:20, y:20, w:100, h:100})
    -   .prepend("<a href='index.html'>Index</a>");
    Back to top

    .replace

    public this .replace(String html)
    html

    arbitrary html

    + .prepend("<a href='index.html'>Index</a>");
    Back to top

    .replace

    public this .replace(String html)
    html

    arbitrary html

    This method will replace the content of this entity with the supplied html

    Example

    Create a link

    Crafty.e("HTML")
    diff --git a/api/Image.html b/api/Image.html
    index 60ebd04..9237d86 100644
    --- a/api/Image.html
    +++ b/api/Image.html
    @@ -55,14 +55,16 @@
     
     
     
    -

    Image

    Draw an image with or without repeating (tiling).

    -

    Methods and Properties

    Back to top

    .image

    Events

    Invalidate
    when the image is loaded
    public this .image(String url[, String repeat])
    url

    URL of the image

    -
    repeat

    If the image should be repeated to fill the entity.

    -

    Draw specified image. Repeat follows CSS syntax ("no-repeat", "repeat", "repeat-x", "repeat-y");

    -

    Note: Default repeat is no-repeat which is different to standard DOM (which is repeat)

    -

    If the width and height are 0 and repeat is set to no-repeat the width and +

    Image

    Draw an image with or without repeating (tiling).

    +

    Methods and Properties

    Back to top

    .image

    Events

    Invalidate
    when the image is loaded
    public this .image(String url[, String repeat])
    url

    URL of the image

    +
    repeat

    If the image should be repeated to fill the entity. This follows CSS syntax: ("no-repeat", "repeat", "repeat-x", "repeat-y"), but defaults to no-repeat.

    +

    Draw the specified image.

    +

    Note: The default value of repeat is no-repeat, which is different than the standard CSS default

    +

    If the width and height are 0 and repeat is set to no-repeat the width and height will automatically assume that of the image. This is an easy way to create an image without needing sprites.

    +

    If set to no-repeat and given dimensions larger than that of the image, +the exact appearance will depend on what renderer (WebGL, DOM, or Canvas) is used.

    Example

    Will default to no-repeat. Entity width and height will be set to the images width and height

    var ent = Crafty.e("2D, DOM, Image").image("myimage.png");

    Create a repeating background.

    var bg = Crafty.e("2D, DOM, Image")
    diff --git a/api/Jumper.html b/api/Jumper.html
    new file mode 100644
    index 0000000..fb314b0
    --- /dev/null
    +++ b/api/Jumper.html
    @@ -0,0 +1,115 @@
    +
    +
    +
    +	Crafty - Jumper
    +	
    +
    +	
    +	
    +	
    +	
    +	
    +	
    +
    +
    +	
    +
    + + + +
    +
    + + + + +

    Jumper

    Events

    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.
    CheckJumping
    When entity is about to jump. This event is triggered with the object the entity is about to jump from (if it exists). Third parties can respond to this event and enable the entity to jump.

    Make an entity jump in response to key events.

    +

    Methods and Properties

    Back to top

    .canJump

    The canJump function determines if the entity is allowed to jump or not (e.g. perhaps the entity should be able to double jump). +The Jumper component will trigger a "CheckJumping" event. +Interested parties can listen to this event and enable the entity to jump by setting canJump to true.

    +

    Example

    var player = Crafty.e("2D, Jumper");
    +player.hasDoubleJumpPowerUp = true; // allow player to double jump by granting him a powerup
    +player.bind("CheckJumping", function(ground) {
    +    if (!ground && player.hasDoubleJumpPowerUp) { // allow player to double jump by using up his double jump powerup
    +        player.canJump = true;
    +        player.hasDoubleJumpPowerUp = false;
    +    }
    +});
    +player.bind("LandedOnGround", function(ground) {
    +    player.hasDoubleJumpPowerUp = true; // give player new double jump powerup upon landing
    +});
    Back to top

    .disableControl

    public this .disableControl()

    Disable the component to listen to key events.

    +

    Example

    this.disableControl();
    Back to top

    .enableControl

    public this .enableControl()

    Enable the component to listen to key events.

    +

    Example

    this.enableControl();
    Back to top

    .jumper

    public this .jumper([Number jumpSpeed,] Array jumpKeys)
    jumpSpeed

    Vertical jump speed in pixels per second

    +
    jumpKeys

    Keys to listen for and make entity jump in response

    +

    Constructor to initialize the power of jump and keys to listen to. Component will +listen for key events and move the entity appropriately. Used with the +gravity component will simulate jumping.

    +

    Example

    this.jumper(300, ['UP_ARROW', 'W']);
    +this.jumper(['UP_ARROW', 'W']);
    Back to top

    .jumpSpeed

    public this .jumpSpeed(Number jumpSpeed)
    jumpSpeed

    new vertical jump speed

    +

    Change the vertical jump speed.

    +

    Example

    this.jumpSpeed(300);
    + +
    +
    +
    + +
    + + diff --git a/api/Keyboard.html b/api/Keyboard.html index 740acb9..5b06fec 100644 --- a/api/Keyboard.html +++ b/api/Keyboard.html @@ -55,11 +55,14 @@ -

    Keyboard

    Give entities keyboard events (keydown and keyup).

    -

    Methods and Properties

    Back to top

    .isDown

    public Boolean isDown(String keyName)
    keyName

    Name of the key to check. See Crafty.keys.

    -
    public Boolean isDown(Number keyCode)
    keyCode

    Key code in Crafty.keys.

    +

    Keyboard

    Give entities keyboard events (Keydown and Keyup).

    +

    In particular, changes to the key state are broadcasted by KeyboardEvents; interested entities can bind to these events.

    +

    The current state (pressed/released) of a key can also be queried using the .isDown method.

    +

    All available key codes are described in Crafty.keys.

    +

    Methods and Properties

    Back to top

    .isDown

    public Boolean isDown(String keyName)
    keyName

    Name of the key to check. See Crafty.keys.

    +
    public Boolean isDown(Number keyCode)
    keyCode

    Key code in Crafty.keys.

    Determine if a certain key is currently down.

    -

    Example

    entity.requires('Keyboard').bind('KeyDown', function () { if (this.isDown('SPACE')) jump(); });

    See Also

    +

    Example

    entity.requires('Keyboard').bind('KeyDown', function () { if (this.isDown('SPACE')) jump(); });

    See Also

    diff --git a/api/KeyboardEvent.html b/api/KeyboardEvent.html index 058b5c2..68bcf12 100644 --- a/api/KeyboardEvent.html +++ b/api/KeyboardEvent.html @@ -55,11 +55,11 @@ -

    KeyboardEvent

    Keyboard Event triggered by Crafty Core

    -

    Events

    KeyDown
    is triggered for each entity when the DOM 'keydown' event is triggered.
    KeyUp
    is triggered for each entity when the DOM 'keyup' event is triggered.

    Example

    Crafty.e("2D, DOM, Color")
    +

    KeyboardEvent

    Keyboard Event triggered by Crafty Core

    +

    Events

    KeyDown
    is triggered for each entity when the DOM 'keydown' event is triggered.
    KeyUp
    is triggered for each entity when the DOM 'keyup' event is triggered.

    Example

    Crafty.e("2D, DOM, Color")
       .attr({x: 100, y: 100, w: 50, h: 50})
       .color("red")
    -  .bind('KeyDown', function(e) {
    +  .bind('KeyDown', function(e) {
         if(e.key == Crafty.keys.LEFT_ARROW) {
           this.x = this.x-1;
         } else if (e.key == Crafty.keys.RIGHT_ARROW) {
    diff --git a/api/Model.html b/api/Model.html
    index bd4509e..a9a23e5 100644
    --- a/api/Model.html
    +++ b/api/Model.html
    @@ -55,7 +55,7 @@
     
     
     
    -

    Model

    Model is a component that offers new features for isolating business +

    Model

    Model is a component that offers new features for isolating business logic in your application. It offers default values, dirty values, and deep events on your data.

    All data should be accessed via the appropriate methods .get, .set, @@ -66,15 +66,15 @@ like contact.email and get notified when those specific fields are updated.

    Events

    Change
    When any data on the model has changed.
    Change[key]
    When the specific key on the model has changed.
    Change[key.key]
    The nested key value has changed.

    Example

    Crafty.c('Person', {
       name: 'Fox',
    -  init: function() { this.requires('Model'); }
    +  init: function() { this.requires('Model'); }
     });
     person = Crafty.e('Person').attr({name: 'blaine'});
    -person.bind('Change[name]', function() {
    -  console.log('name changed!');
    +person.bind('Change[name]', function() {
    +  Crafty.log('name changed!');
     });
     person.attr('name', 'blainesch'); // Triggers event
     person.is_dirty('name'); // true
    -person.changed // name

    Methods and Properties

    Back to top

    .is_dirty

    Helps determine when data or the entire component is "dirty" or has changed attributes.

    +person.changed // name

    Methods and Properties

    Back to top

    .is_dirty

    Helps determine when data or the entire component is "dirty" or has changed attributes.

    Example

    person = Crafty.e('Person').attr({name: 'Fox', age: 24})
     person.is_dirty() // false
     person.is_dirty('name') // false
    diff --git a/api/Motion.html b/api/Motion.html
    new file mode 100644
    index 0000000..8928c2c
    --- /dev/null
    +++ b/api/Motion.html
    @@ -0,0 +1,148 @@
    +
    +
    +
    +	Crafty - Motion
    +	
    +
    +	
    +	
    +	
    +	
    +	
    +	
    +
    +
    +	
    +
    + + + +
    +
    + + + + +

    Motion

    Events

    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.
    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    MotionChange [Motion property name and old value = { key: String, oldValue: Number }]
    When a motion property has changed a MotionChange event is triggered.

    Component that allows moving an entity by applying linear velocity and acceleration. +All linear motion values are expressed in pixels per second (e.g. an entity with vx of 1 will move 1px on the x axis each second).

    +

    Note: Several methods return Vector2D objects that dynamically reflect the entity's underlying properties. If you want a static copy instead, use the vector's clone() method.

    +

    Methods and Properties

    Back to top

    .acceleration

    Method for accessing/modifying the linear(x,y) acceleration. +The acceleration increases the velocity over time, resulting in ever increasing speed.

    +
    public Vector2D .acceleration()
    [Returns]

    The acceleration Vector2D with the properties {x, y} that reflects the acceleration in the direction of the entity.

    +

    Returns the current acceleration. You can access/modify the properties in order to retrieve/change the acceleration.

    +

    Example

    var ent = Crafty.e("2D, Motion");
    +
    +var acc = ent.acceleration(); //returns the acceleration object
    +acc.x;       // retrieve the acceleration in the x direction
    +acc.x = 0;   // set the acceleration in the x direction
    +acc.x += 4   // add to the acceleration in the x direction
    Back to top

    .ax

    A property for accessing/modifying the linear acceleration in the x axis. +The acceleration changes the velocity over time.

    +

    Example

    var ent = Crafty.e("2D, Motion");
    +
    +var ax = ent.ax; // retrieve the linear acceleration in the x axis
    +ent.ax += 1; // increase the linear acceleration in the x axis
    +ent.ax = 0; // reset the linear acceleration in the x axis
    Back to top

    .ay

    A property for accessing/modifying the linear acceleration in the y axis. +The acceleration changes the velocity over time.

    +

    Example

    var ent = Crafty.e("2D, Motion");
    +
    +var ay = ent.ay; // retrieve the linear acceleration in the y axis
    +ent.ay += 1; // increase the linear acceleration in the y axis
    +ent.ay = 0; // reset the linear acceleration in the y axis
    Back to top

    .dx

    A number that reflects the change in x (difference between the old & new x) that was applied in the last frame.

    +

    Example

    var ent = Crafty.e("2D, Motion");
    +
    +var dx = ent.dx; // the change of x in the last frame
    Back to top

    .dy

    A number that reflects the change in y (difference between the old & new y) that was applied in the last frame.

    +

    Example

    var ent = Crafty.e("2D, Motion");
    +
    +var dy = ent.dy; // the change of y in the last frame
    Back to top

    .motionDelta

    public Vector2D .motionDelta()
    [Returns]

    A Vector2D with the properties {x, y} that reflect the change in x & y.

    +

    Returns the difference between the old & new position that was applied in the last frame.

    +

    Example

    var ent = Crafty.e("2D, Motion");
    +
    +var deltaY = ent.motionDelta().y; // the change of y in the last frame
    Back to top

    .resetMotion

    public this .resetMotion()
    [Returns]

    this

    +

    Reset all linear motion (resets velocity, acceleration, motionDelta).

    +
    Back to top

    .velocity

    Method for accessing/modifying the linear(x,y) velocity. +The velocity remains constant over time, unless the acceleration increases the velocity.

    +
    public Vector2D .velocity()
    [Returns]

    The velocity Vector2D with the properties {x, y} that reflect the velocities in the direction of the entity.

    +

    Returns the current velocity. You can access/modify the properties in order to retrieve/change the velocity.

    +

    Example

    var ent = Crafty.e("2D, Motion");
    +
    +var vel = ent.velocity(); //returns the velocity vector
    +vel.x;       // retrieve the velocity in the x direction
    +vel.x = 0;   // set the velocity in the x direction
    +vel.x += 4   // add to the velocity in the x direction
    Back to top

    .vx

    A property for accessing/modifying the linear velocity in the x axis. +The velocity remains constant over time, unless the acceleration changes the velocity.

    +

    Example

    var ent = Crafty.e("2D, Motion");
    +
    +var vx = ent.vx; // retrieve the linear velocity in the x axis
    +ent.vx += 1; // increase the linear velocity in the x axis
    +ent.vx = 0; // reset the linear velocity in the x axis
    Back to top

    .vy

    A property for accessing/modifying the linear velocity in the y axis. +The velocity remains constant over time, unless the acceleration changes the velocity.

    +

    Example

    var ent = Crafty.e("2D, Motion");
    +
    +var vy = ent.vy; // retrieve the linear velocity in the y axis
    +ent.vy += 1; // increase the linear velocity in the y axis
    +ent.vy = 0; // reset the linear velocity in the y axis
    + +
    +
    +
    + +
    + + diff --git a/api/Mouse.html b/api/Mouse.html index c5a825b..5f9008e 100644 --- a/api/Mouse.html +++ b/api/Mouse.html @@ -55,35 +55,28 @@ -

    Mouse

    Provides the entity with mouse related events

    -

    Events

    MouseOver [ Data { MouseEvent }]
    when the mouse enters
    MouseOut [ Data { MouseEvent }]
    when the mouse leaves
    MouseDown [ Data { MouseEvent }]
    when the mouse button is pressed on
    MouseUp [ Data { MouseEvent }]
    when the mouse button is released on
    Click [ Data { MouseEvent }]
    when the user clicks
    DoubleClick [ Data { MouseEvent }]
    when the user double clicks
    MouseMove [ Data { MouseEvent }]
    when the mouse is over and moves

    To be able to use the events on a entity, you have to remember to include the Mouse component, else the events will not get triggered.

    +

    Mouse

    Provides the entity with mouse related events

    +

    Events

    MouseOver [Data = {MouseEvent}]
    when the mouse enters
    MouseOut [Data = {MouseEvent}]
    when the mouse leaves
    MouseDown [Data = {MouseEvent}]
    when the mouse button is pressed on
    MouseUp [Data = {MouseEvent}]
    when the mouse button is released on
    Click [Data = {MouseEvent}]
    when the user clicks
    DoubleClick [Data = {MouseEvent}]
    when the user double clicks
    MouseMove [Data = {MouseEvent}]
    when the mouse is over and moves

    If you do not add this component, mouse events will not be triggered on an entity.

    You can read more about the MouseEvent, which is the parameter passed to the callback. https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent

    -

    Crafty adds the mouseButton property to MouseEvents that match one of

    +

    Crafty will add the mouseButton property to MouseEvents that match one of

    • Crafty.mouseButtons.LEFT
    • Crafty.mouseButtons.RIGHT
    • Crafty.mouseButtons.MIDDLE
    -

    Example

    var myEntity = Crafty.e('2D, Canvas, Color, Mouse')
    +

    Note: If you're targeting mobile, you should know that by default Crafty turns touch events into mouse events, making mouse dependent components work with touch. However, if you need multitouch, you'll have to make use of the Touch component instead, which can break compatibility with things which directly interact with the Mouse component.

    +

    Example

    var myEntity = Crafty.e('2D, Canvas, Color, Mouse')
     .attr({x: 10, y: 10, w: 40, h: 40})
     .color('red')
    -.bind('Click', function(MouseEvent){
    +.bind('Click', function(MouseEvent){
       alert('clicked', MouseEvent);
     });
     
    -myEntity.bind('MouseUp', function(e) {
    +myEntity.bind('MouseUp', function(e) {
        if( e.mouseButton == Crafty.mouseButtons.RIGHT )
    -       console.log("Clicked right button");
    -})

    Methods and Properties

    Back to top

    .areaMap

    public this .areaMap(Crafty.polygon polygon)
    polygon

    Instance of Crafty.polygon used to check if the mouse coordinates are inside this region

    -
    public this .areaMap(Array point1, .., Array pointN)
    point#

    Array with an x and y position to generate a polygon

    -

    Assign a polygon to the entity so that mouse events will only be triggered if -the coordinates are inside the given polygon.

    -

    Example

    Crafty.e("2D, DOM, Color, Mouse")
    -    .color("red")
    -    .attr({ w: 100, h: 100 })
    -    .bind('MouseOver', function() {console.log("over")})
    -    .areaMap([0,0], [50,0], [50,50], [0,50])
    + Crafty.log("Clicked right button"); +})
    diff --git a/api/MouseDrag.html b/api/MouseDrag.html new file mode 100644 index 0000000..efbe82c --- /dev/null +++ b/api/MouseDrag.html @@ -0,0 +1,94 @@ + + + + Crafty - MouseDrag + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    MouseDrag

    Provides the entity with drag and drop mouse events.

    +

    Events

    Dragging [Data = {MouseEvent}]
    is triggered each frame the entity is being dragged
    StartDrag [Data = {MouseEvent}]
    is triggered when dragging begins
    StopDrag [Data = {MouseEvent}]
    is triggered when dragging ends

    See Also

    Methods and Properties

    Back to top

    .startDrag

    public this .startDrag(void)

    Make the entity produce drag events, essentially making the entity follow the mouse positions.

    +

    See Also

    Back to top

    .stopDrag

    public this .stopDrag(void)

    Stop the entity from producing drag events, essentially reproducing the drop.

    +

    See Also

    + +
    +
    +
    + +
    + + diff --git a/api/Multiway.html b/api/Multiway.html index a7b3e5e..45f0635 100644 --- a/api/Multiway.html +++ b/api/Multiway.html @@ -55,19 +55,22 @@ -

    Multiway

    Used to bind keys to directions and have the entity move accordingly

    -

    Events

    NewDirection [ New direction { { x:Number, y:Number } }]
    triggered when direction changes
    Moved [ Old position { { x:Number, y:Number } }]
    triggered on movement on either x or y axis. If the entity has moved on both axes for diagonal movement the event is triggered twice

    Methods and Properties

    Back to top

    .disableControl

    public this .disableControl()

    Disable the component to listen to key events.

    -

    Example

    this.disableControl();
    Back to top

    .enableControl

    public this .enableControl()

    Enable the component to listen to key events.

    -

    Example

    this.enableControl();
    Back to top

    .multiway

    public this .multiway([Number speed,] Object keyBindings )
    speed

    Amount of pixels to move the entity whilst a key is down

    +

    Multiway

    Events

    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.

    Used to bind keys to directions and have the entity move accordingly.

    +

    Methods and Properties

    Back to top

    .disableControl

    public this .disableControl()

    Disable the component to listen to key events.

    +

    Example

    this.disableControl();
    Back to top

    .enableControl

    public this .enableControl()

    Enable the component to listen to key events.

    +

    Example

    this.enableControl();
    Back to top

    .multiway

    public this .multiway([Number speed,] Object keyBindings)
    speed

    A speed in pixels per second

    keyBindings

    What keys should make the entity go in which direction. Direction is specified in degrees

    -

    Constructor to initialize the speed and keyBindings. Component will listen to key events and move the entity appropriately.

    -

    When direction changes a NewDirection event is triggered with an object detailing the new direction: {x: x_movement, y: y_movement} -When entity has moved on either x- or y-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}

    -

    Example

    this.multiway(3, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});
    -this.multiway({x:3,y:1.5}, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});
    -this.multiway({W: -90, S: 90, D: 0, A: 180});
    Back to top

    .speed

    public this .speed(Number speed)
    speed

    The speed the entity has.

    -

    Change the speed that the entity moves with.

    -

    Example

    this.speed(2);
    +

    Constructor to initialize the speed and keyBindings. Component will listen to key events and move the entity appropriately. +Can be called while a key is pressed to change direction & speed on the fly.

    +

    Multiway acts by adding a velocity on key press and removing the same velocity when the respective key is released. +This works well in most cases, but can cause undesired behavior if you manipulate velocities by yourself while this component is in effect. +If you need to resolve collisions, it's advised to correct the position directly rather than to manipulate the velocity. If you still need to reset the velocity once a collision happens, make sure to re-add the previous velocity once the collision is resolved.

    +

    Example

    this.multiway(150, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});
    +this.multiway({x:150,y:75}, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});
    +this.multiway({W: -90, S: 90, D: 0, A: 180});
    Back to top

    .speed

    public this .speed(Object speed)
    speed

    New speed the entity has, for x and y axis.

    +

    Change the speed that the entity moves with, in units of pixels per second.

    +

    Can be called while a key is pressed to change speed on the fly.

    +

    Example

    this.speed({ x: 150, y: 50 });
    diff --git a/api/Particles.html b/api/Particles.html index 68ead28..8710fe5 100644 --- a/api/Particles.html +++ b/api/Particles.html @@ -55,39 +55,41 @@ -

    Particles

    Events

    ParticleEnd
    when the particle animation has finished

    Based on Parcycle by Mr. Speaker, licensed under the MIT, Ported by Leo Koppelkamm -This is canvas only & won't do anything if the browser doesn't support it! -To see how this works take a look in https://github.com/craftyjs/Crafty/blob/master/src/particles.js

    -

    Methods and Properties

    Back to top

    .particles

    public this .particles(Object options)
    options

    Map of options that specify the behavior and look of the particles.

    -

    Example

    var options = {
    -    maxParticles: 150,
    -    size: 18,
    -    sizeRandom: 4,
    -    speed: 1,
    -    speedRandom: 1.2,
    -    // Lifespan in frames
    -    lifeSpan: 29,
    -    lifeSpanRandom: 7,
    -    // Angle is calculated clockwise: 12pm is 0deg, 3pm is 90deg etc.
    -    angle: 65,
    -    angleRandom: 34,
    -    startColour: [255, 131, 0, 1],
    -    startColourRandom: [48, 50, 45, 0],
    -    endColour: [245, 35, 0, 0],
    -    endColourRandom: [60, 60, 60, 0],
    -    // Only applies when fastMode is off, specifies how sharp the gradients are drawn
    -    sharpness: 20,
    -    sharpnessRandom: 10,
    -    // Random spread from origin
    -    spread: 10,
    -    // How many frames should this last
    -    duration: -1,
    -    // Will draw squares instead of circle gradients
    -    fastMode: false,
    -    gravity: { x: 0, y: 0.1 },
    -    // sensible values are 0-3
    -    jitter: 0
    -}
    +

    Particles

    Events

    ParticleEnd
    when the particle animation has finished

    Based on Parcycle by Mr. Speaker, licensed under the MIT, Ported by Leo Koppelkamm

    +

    Note: This requires the canvas element, and won't do anything if the browser doesn't support it!

    +

    For implementation details, check out the source code.

    +

    Methods and Properties

    Back to top

    .particles

    public this .particles(Object options)
    options

    Map of options that specify the behavior and look of the particles.

    +

    Example

    var options = {
    +  maxParticles: 150,
    +  size: 18,
    +  sizeRandom: 4,
    +  speed: 1,
    +  speedRandom: 1.2,
    +  // Lifespan in frames
    +  lifeSpan: 29,
    +  lifeSpanRandom: 7,
    +  // Angle is calculated clockwise: 12pm is 0deg, 3pm is 90deg etc.
    +  angle: 65,
    +  angleRandom: 34,
    +  startColour: [255, 131, 0, 1],
    +  startColourRandom: [48, 50, 45, 0],
    +  endColour: [245, 35, 0, 0],
    +  endColourRandom: [60, 60, 60, 0],
    +  // Only applies when fastMode is off, specifies how sharp the gradients are drawn
    +  sharpness: 20,
    +  sharpnessRandom: 10,
    +  // Random spread from origin
    +  spread: 10,
    +  // How many frames should this last
    +  duration: -1,
    +  // Will draw squares instead of circle gradients
    +  fastMode: false,
    +  gravity: { x: 0, y: 0.1 },
    +  // sensible values are 0-3
    +  jitter: 0,
    +  // Offset for the origin of the particles
    +  originOffset: {x: 0, y: 0}
    +};
     
     Crafty.e("2D,Canvas,Particles").particles(options);
    diff --git a/api/SolidAreaMap.html b/api/SolidAreaMap.html new file mode 100644 index 0000000..d40fb83 --- /dev/null +++ b/api/SolidAreaMap.html @@ -0,0 +1,94 @@ + + + + Crafty - SolidAreaMap + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    SolidAreaMap

    Adding this component to an entity with an AreaMap component will cause its click polygon to be drawn to the debug canvas, with a default alpha level of 0.7. +Following click areas exist for an entity (in decreasing order of priority): AreaMap, Hitbox, MBR. Use the appropriate debug components to display them.

    +

    The methods of DebugCanvas can be used to control this component's appearance.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/SolidHitBox.html b/api/SolidHitBox.html index 7a371d1..e313676 100644 --- a/api/SolidHitBox.html +++ b/api/SolidHitBox.html @@ -55,7 +55,7 @@ -

    SolidHitBox

    Adding this component to an entity with a Collision component will cause its collision polygon to be drawn to the debug canvas, with a default alpha level of 0.7.

    +

    SolidHitBox

    Adding this component to an entity with a Collision component will cause its collision polygon to be drawn to the debug canvas, with a default alpha level of 0.7.

    The methods of DebugCanvas can be used to control this component's appearance.

    diff --git a/api/Sprite.html b/api/Sprite.html index fd9bab8..c07241e 100644 --- a/api/Sprite.html +++ b/api/Sprite.html @@ -55,16 +55,18 @@ -

    Sprite

    Events

    Invalidate
    when the sprites change

    Component for using tiles in a sprite map.

    -

    Methods and Properties

    Back to top

    .__coord

    The coordinate of the slide within the sprite in the format of [x, y, w, h].

    -
    Back to top

    .crop

    public this .crop(Number x, Number y, Number w, Number h)
    x

    Offset x position

    +

    Sprite

    Events

    Invalidate
    when the sprites change

    A component for using tiles in a sprite map.

    +

    This is automatically added to entities which use the components created by Crafty.sprite or Crafty.load. +Since these are also used to define tile size, you'll rarely need to use this components methods directly.

    +

    Methods and Properties

    Back to top

    .__coord

    The coordinate of the slide within the sprite in the format of [x, y, w, h].

    +
    Back to top

    .crop

    public this .crop(Number x, Number y, Number w, Number h)
    x

    Offset x position

    y

    Offset y position

    w

    New width

    h

    New height

    If the entity needs to be smaller than the tile size, use this method to crop it.

    The values should be in pixels rather than tiles.

    Example

    Crafty.e("2D, DOM, Sprite")
    -  .crop(40, 40, 22, 23);
    Back to top

    .sprite

    public this .sprite(Number x, Number y[, Number w, Number h])
    x

    X cell position

    + .crop(40, 40, 22, 23);
    Back to top

    .sprite

    public this .sprite(Number x, Number y[, Number w, Number h])
    x

    X cell position

    y

    Y cell position

    w

    Width in cells. Optional.

    h

    Height in cells. Optional.

    diff --git a/api/SpriteAnimation.html b/api/SpriteAnimation.html index b941b28..df52ee4 100644 --- a/api/SpriteAnimation.html +++ b/api/SpriteAnimation.html @@ -55,7 +55,7 @@ -

    SpriteAnimation

    Events

    StartAnimation [ Data { {Reel} }]
    When an animation starts playing, or is resumed from the paused state
    AnimationEnd [ Data { { Reel } }]
    When the animation finishes
    FrameChange [ Data { { Reel } }]
    Each time the frame of the current reel changes
    ReelChange [ Data { { Reel } }]
    When the reel changes

    Used to animate sprites by treating a sprite map as a set of animation frames. +

    SpriteAnimation

    Events

    StartAnimation [Data = {Reel}]
    When an animation starts playing, or is resumed from the paused state
    AnimationEnd [Data = { Reel }]
    When the animation finishes
    FrameChange [Data = { Reel }]
    Each time the frame of the current reel changes
    ReelChange [Data = { Reel }]
    When the reel changes

    Used to animate sprites by treating a sprite map as a set of animation frames. Must be applied to an entity that has a sprite-map component.

    To define an animation, see the reel method. To play an animation, see the animate method.

    A reel is an object that contains the animation frames and current state for an animation. The reel object has the following properties:

    @@ -65,7 +65,7 @@
    easing: (Crafty.easing object)

    The object that handles the internal progress of the animation.

    duration: (Number)

    The duration in milliseconds.

    Many animation related events pass a reel object as data. As typical with events, this should be treated as read only data that might be later altered by the entity. If you wish to preserve the data, make a copy of it.

    -

    Methods and Properties

    Back to top

    .animate

    public this .animate([String reelId] [, Number loopCount])
    reelId

    ID of the animation reel to play. Defaults to the current reel if none is specified.

    +

    Methods and Properties

    Back to top

    .animate

    public this .animate([String reelId] [, Number loopCount])
    reelId

    ID of the animation reel to play. Defaults to the current reel if none is specified.

    loopCount

    Number of times to repeat the animation. Use -1 to repeat indefinitely. Defaults to 1.

    Play one of the reels previously defined through .reel(...). Simply pass the name of the reel. If you wish the animation to play multiple times in succession, pass in the amount of times as an additional parameter. @@ -81,34 +81,34 @@ // Play the animation across 20 frames (so each sprite in the 4 sprite animation should be seen for 5 frames) and repeat indefinitely Crafty.e("2D, DOM, SpriteAnimation, PlayerSprite") .reel('PlayerRunning', 20, 0, 0, 3) // setup animation - .animate('PlayerRunning', -1); // start animation

    Back to top

    .animationSpeed

    The playback rate of the animation. This property defaults to 1.

    -
    Back to top

    .getReel

    public Reel .getReel()
    [Returns]

    The current reel, or null if there is no active reel

    -
    public Reel .getReel(reelId)
    reelId

    The id of the reel to fetch.

    + .animate('PlayerRunning', -1); // start animation
    Back to top

    .animationSpeed

    The playback rate of the animation. This property defaults to 1.

    +
    Back to top

    .getReel

    public Reel .getReel()
    [Returns]

    The current reel, or null if there is no active reel

    +
    public Reel .getReel(reelId)
    reelId

    The id of the reel to fetch.

    [Returns]

    The specified reel, or undefined if no such reel exists.

    -
    Back to top

    .isPlaying

    public Boolean .isPlaying([String reelId])
    reelId

    The reelId of the reel we wish to examine

    +
    Back to top

    .isPlaying

    public Boolean .isPlaying([String reelId])
    reelId

    The reelId of the reel we wish to examine

    [Returns]

    The current animation state

    Determines if the specified animation is currently playing. If no reelId is specified, checks if any animation is playing.

    Example

    myEntity.isPlaying() // is any animation playing
    -myEntity.isPlaying('PlayerRunning') // is the PlayerRunning animation playing
    Back to top

    .loops

    public this .loops(Number loopCount)
    loopCount

    The number of times to play the animation

    +myEntity.isPlaying('PlayerRunning') // is the PlayerRunning animation playing
    Back to top

    .loops

    public this .loops(Number loopCount)
    loopCount

    The number of times to play the animation

    Sets the number of times the animation will loop for. If called while an animation is in progress, the current state will be considered the first loop.

    -
    public Number .loops()
    [Returns]

    The number of loops left. Returns 0 if no reel is active.

    -
    Back to top

    .pauseAnimation

    public this .pauseAnimation(void)

    Pauses the currently playing animation, or does nothing if no animation is playing.

    -
    Back to top

    .reel

    Used to define reels, to change the active reel, and to fetch the id of the active reel.

    -
    public this .reel(String reelId, Duration duration, Number fromX, Number fromY, Number frameCount)

    Defines a reel by starting and ending position on the sprite sheet.

    +
    public Number .loops()
    [Returns]

    The number of loops left. Returns 0 if no reel is active.

    +
    Back to top

    .pauseAnimation

    public this .pauseAnimation(void)

    Pauses the currently playing animation, or does nothing if no animation is playing.

    +
    Back to top

    .reel

    Used to define reels, to change the active reel, and to fetch the id of the active reel.

    +
    public this .reel(String reelId, Duration duration, Number fromX, Number fromY, Number frameCount)

    Defines a reel by starting and ending position on the sprite sheet.

    reelId

    ID of the animation reel being created

    duration

    The length of the animation in milliseconds.

    fromX

    Starting x position on the sprite map (x's unit is the horizontal size of the sprite in the sprite map).

    fromY

    y position on the sprite map (y's unit is the horizontal size of the sprite in the sprite map). Remains constant through the animation.

    frameCount

    The number of sequential frames in the animation. If negative, the animation will play backwards.

    -
    public this .reel(String reelId, Duration duration, Array frames)

    Defines a reel by an explicit list of frames

    +
    public this .reel(String reelId, Duration duration, Array frames)

    Defines a reel by an explicit list of frames

    reelId

    ID of the animation reel being created

    duration

    The length of the animation in milliseconds.

    frames

    An array of arrays containing the x and y values of successive frames: [[x1,y1],[x2,y2],...] (the values are in the unit of the sprite map's width/height respectively).

    -
    public this .reel(String reelId)

    Switches to the specified reel. The sprite will be updated to that reel's current frame

    +
    public this .reel(String reelId)

    Switches to the specified reel. The sprite will be updated to that reel's current frame

    reelID

    the ID to switch to

    -
    public Reel .reel()
    [Returns]

    The id of the current reel

    +
    public Reel .reel()
    [Returns]

    The id of the current reel

    A method to handle animation reels. Only works for sprites built with the Crafty.sprite methods. See the Tween component for animation of 2D properties.

    To setup an animation reel, pass the name of the reel (used to identify the reel later), and either an @@ -124,15 +124,15 @@ Crafty.e("2D, DOM, SpriteAnimation, PlayerSprite").reel('PlayerRunning', 1000, 0, 1, 4); // This is the same animation definition, but using the alternative method -Crafty.e("2D, DOM, SpriteAnimation, PlayerSprite").reel('PlayerRunning', 1000, [[0, 1], [1, 1], [2, 1], [3, 1]]);

    Back to top

    .reelPosition

    public this .reelPosition(Integer position)

    Sets the position of the current reel by frame number.

    +Crafty.e("2D, DOM, SpriteAnimation, PlayerSprite").reel('PlayerRunning', 1000, [[0, 1], [1, 1], [2, 1], [3, 1]]);
    Back to top

    .reelPosition

    public this .reelPosition(Integer position)

    Sets the position of the current reel by frame number.

    position

    the frame to jump to. This is zero-indexed. A negative values counts back from the last frame.

    -
    public this .reelPosition(Number position)

    Sets the position of the current reel by percent progress.

    +
    public this .reelPosition(Number position)

    Sets the position of the current reel by percent progress.

    position

    a non-integer number between 0 and 1

    -
    public this .reelPosition(String position)

    Jumps to the specified position. The only currently accepted value is "end", which will jump to the end of the reel.

    -
    public Number .reelPosition()
    [Returns]

    The current frame number

    -
    Back to top

    .resetAnimation

    public this .resetAnimation()

    Resets the current animation to its initial state. Resets the number of loops to the last specified value, which defaults to 1.

    +
    public this .reelPosition(String position)

    Jumps to the specified position. The only currently accepted value is "end", which will jump to the end of the reel.

    +
    public Number .reelPosition()
    [Returns]

    The current frame number

    +
    Back to top

    .resetAnimation

    public this .resetAnimation()

    Resets the current animation to its initial state. Resets the number of loops to the last specified value, which defaults to 1.

    Neither pauses nor resumes the current animation.

    -
    Back to top

    .resumeAnimation

    public this .resumeAnimation()

    This will resume animation of the current reel from its current state. +

    Back to top

    .resumeAnimation

    public this .resumeAnimation()

    This will resume animation of the current reel from its current state. If a reel is already playing, or there is no current reel, there will be no effect.

    diff --git a/api/Storage.html b/api/Storage.html index 2699761..fc9b0bd 100644 --- a/api/Storage.html +++ b/api/Storage.html @@ -55,16 +55,19 @@ -

    Storage

    Very simple way to get and set values, which will persist when the browser is closed also. Storage wraps around HTML5 Web Storage, which is well-supported across browsers and platforms, but limited to 5MB total storage per domain.

    -

    Methods and Properties

    Back to top

    .storage

    .storage(String key)
    key

    a key you would like to get from the storage. It will return null if the key does not exists.

    -
    .storage(String key, String value)
    key

    the key you would like to save the data under.

    +

    Storage

    Very simple way to get and set values, which will persist when the browser is closed also. +Storage wraps around HTML5 Web Storage, which is well-supported across browsers and platforms, but limited to 5MB total storage per domain. +Storage is also available for node, which is permanently persisted to the ./localStorage folder - take care of removing entries. Note that multiple Crafty instances use the same storage, so care has to be taken not to overwrite existing entries.

    +

    Methods and Properties

    Back to top

    Crafty.storage

    Crafty.storage(String key)
    key

    a key you would like to get from the storage.

    +
    [Returns]

    The stored value, or null if none saved under that key exists

    +
    Crafty.storage(String key, String value)
    key

    the key you would like to save the data under.

    value

    the value you would like to save.

    -
    .storage(String key, [Object value, Array value, Boolean value])
    key

    the key you would like to save the data under.

    +
    Crafty.storage(String key, [Object value, Array value, Boolean value])
    key

    the key you would like to save the data under.

    value

    the value you would like to save, can be an Object or an Array.

    -

    Storage function is very simple and can be used to either get or set values. -You can store both booleans, strings, objects and arrays.

    -

    Please note: You should not store data, while the game is playing, as it can cause the game to slow down. You should load data when you start the game, or when the user for an example click a "Save gameprocess" button.

    -

    Example

    Get an already stored value

    +

    Crafty.storage is used synchronously to either get or set values.

    +

    You can store booleans, strings, objects and arrays.

    +

    Note: Because the underlying method is synchronous, it can cause slowdowns if used frequently during gameplay. You should aim to load or save data at reasonable times such as on level load, or in response to specific user actions.

    +

    Example

    Get an already stored value

    var playername = Crafty.storage('playername');

    Example

    Save a value

    Crafty.storage('playername', 'Hero');

    Example

    Test to see if a value is already there.

    var heroname = Crafty.storage('name');
    @@ -72,7 +75,7 @@
       // Maybe ask the player what their name is here
       heroname = 'Guest';
     }
    -// Do something with heroname
    Back to top

    .storage.remove

    .storage.remove(String key)
    key

    a key where you will like to delete the value of.

    +// Do something with heroname
    Back to top

    Crafty.storage.remove

    Crafty.storage.remove(String key)
    key

    a key where you will like to delete the value of.

    Generally you do not need to remove values from localStorage, but if you do store large amount of text, or want to unset something you can do that with this function.

    diff --git a/api/Supportable.html b/api/Supportable.html new file mode 100644 index 0000000..5e8ce49 --- /dev/null +++ b/api/Supportable.html @@ -0,0 +1,103 @@ + + + + Crafty - Supportable + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Supportable

    Events

    LandedOnGround
    When entity has landed. This event is triggered with the object the entity landed on.
    LiftedOffGround
    When entity has lifted off. This event is triggered with the object the entity stood on before lift-off.
    CheckLanding
    When entity is about to land. This event is triggered with the object the entity is about to land on. Third parties can respond to this event and prevent the entity from being able to land.

    Component that detects if the entity collides with the ground. This component is automatically added and managed by the Gravity component. +The appropriate events are fired when the entity state changes (lands on ground / lifts off ground). The current ground entity can also be accessed with .ground.

    +

    Methods and Properties

    Back to top

    .canLand

    The canLand boolean determines if the entity is allowed to land or not (e.g. perhaps the entity should not land if it's not falling). +The Supportable component will trigger a "CheckLanding" event. +Interested parties can listen to this event and prevent the entity from landing by setting canLand to false.

    +

    Example

    var player = Crafty.e("2D, Gravity");
    +player.bind("CheckLanding", function(ground) {
    +    if (player.y + player.h > ground.y + player.dy) { // forbid landing, if player's feet are not above ground
    +        player.canLand = false;
    +    }
    +});
    Back to top

    .ground

    Access the ground entity (which may be the actual ground entity if it exists, or null if it doesn't exist) and thus whether this entity is currently on the ground or not. +The ground entity is also available through the events, when the ground entity changes.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/Text.html b/api/Text.html index 1e769a0..61617fc 100644 --- a/api/Text.html +++ b/api/Text.html @@ -55,31 +55,23 @@ -

    Text

    Events

    Invalidate
    when the text is changed

    Component to make a text entity.

    -

    By default, text will have the style "10px sans-serif".

    -

    Note 1: An entity with the text component is just text! If you want to write text -inside an image, you need one entity for the text and another entity for the image. -More tips for writing text inside an image: (1) Use the z-index (from 2D component) -to ensure that the text is on top of the image, not the other way around; (2) -use .attach() (from 2D component) to glue the text to the image so they move and -rotate together.

    -

    Note 2: For DOM (but not canvas) text entities, various font settings (like -text-decoration and text-align) can be set using .css() (see DOM component). But -you cannot use .css() to set the properties which are controlled by .textFont() -or .textColor() -- the settings will be ignored.

    -

    Note 3: If you use canvas text with glyphs that are taller than standard letters, portions of the glyphs might be cut off.

    -

    Methods and Properties

    Back to top

    .text

    public this .text(String text)
    public this .text(Function textgenerator)
    text

    String of text that will be inserted into the DOM or Canvas element.

    +

    Text

    Events

    Invalidate
    when the text is changed

    By default, text will have the style "10px sans-serif".

    +

    Note: An entity with the text component is just text! If you want to write text inside an image, you need one entity for the text and another entity for the image. More tips for writing text inside an image: (1) Use the z-index (from 2D component) to ensure that the text is on top of the image, not the other way around; (2) use .attach() (from 2D component) to glue the text to the image so they move and rotate together.

    +

    Note: For DOM (but not canvas) text entities, various font settings (like text-decoration and text-align) can be set using .css() (see DOM component). But you cannot use .css() to set the properties which are controlled by .textFont() or .textColor() -- the settings will be ignored.

    +

    Note: If you use canvas text with glyphs that are taller than standard letters, portions of the glyphs might be cut off.

    +

    Methods and Properties

    Back to top

    .text

    public this .text(String text)
    text

    String of text that will be inserted into the DOM or Canvas element.

    +
    public this .text(Function textGenerator)
    textGenerator

    A function that returns a string. It will be immediately invoked in the context of the entity, with the result used as the text to display.

    This method will update the text inside the entity.

    If you need to reference attributes on the entity itself you can pass a function instead of a string.

    Example

    Crafty.e("2D, DOM, Text").attr({ x: 100, y: 100 }).text("Look at me!!");
     
     Crafty.e("2D, DOM, Text").attr({ x: 100, y: 100 })
    -    .text(function () { return "My position is " + this._x });
    +    .text(function () { return "My position is " + this._x });
     
     Crafty.e("2D, Canvas, Text").attr({ x: 100, y: 100 }).text("Look at me!!");
     
     Crafty.e("2D, Canvas, Text").attr({ x: 100, y: 100 })
    -    .text(function () { return "My position is " + this._x });
    Back to top

    .textColor

    public this .textColor(String color)
    color

    The color in name, hex, rgb or rgba

    + .text(function () { return "My position is " + this._x });
    Back to top

    .textColor

    public this .textColor(String color)
    color

    The color in name, hex, rgb or rgba

    Change the color of the text. You can use HEX, rgb and rgba colors.

    If you want the text to be transparent, you should use rgba where you can define alphaChannel.

    Example

    Crafty.e("2D, DOM, Text").attr({ x: 100, y: 100 }).text("Look at me!!")
    @@ -89,16 +81,16 @@
       .textColor('rgba(0, 255, 0, 0.5)');
     
     Crafty.e("2D, Canvas, Text").attr({ x: 100, y: 100 }).text('Look at me!!')
    -  .textColor('white');
    Back to top

    .textFont

    Events

    Invalidate
    public this .textFont(String key, * value)
    key

    Property of the entity to modify

    + .textColor('white');
    Back to top

    .textFont

    Events

    Invalidate
    public this .textFont(String key, * value)
    key

    Property of the entity to modify

    value

    Value to set the property to

    -
    public this .textFont(Object map)
    map

    Object where the key is the property to modify and the value as the property value

    +
    public this .textFont(Object map)
    map

    Object where the key is the property to modify and the value as the property value

    Use this method to set font property of the text entity. Possible values are: type, weight, size, family, lineHeight, and variant.

    When rendered by the canvas, lineHeight and variant will be ignored.

    Example

    Crafty.e("2D, DOM, Text").textFont({ type: 'italic', family: 'Arial' });
     Crafty.e("2D, Canvas, Text").textFont({ size: '20px', weight: 'bold' });
     
     Crafty.e("2D, Canvas, Text").textFont("type", "italic");
    -Crafty.e("2D, Canvas, Text").textFont("type"); // italic
    Back to top

    .unselectable

    Events

    Invalidate
    public this .unselectable()

    This method sets the text so that it cannot be selected (highlighted) by dragging. +Crafty.e("2D, Canvas, Text").textFont("type"); // italic

    Back to top

    .unselectable

    Events

    Invalidate
    public this .unselectable()

    This method sets the text so that it cannot be selected (highlighted) by dragging. (Canvas text can never be highlighted, so this only matters for DOM text.) Works by changing the css property "user-select" and its variants.

    Likewise, this sets the mouseover cursor to be "default" (arrow), not "text" (I-beam)

    diff --git a/api/Touch.html b/api/Touch.html new file mode 100644 index 0000000..2986517 --- /dev/null +++ b/api/Touch.html @@ -0,0 +1,110 @@ + + + + Crafty - Touch + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    Touch

    Provides the entity with touch related events

    +

    Events

    TouchStart [Data = {TouchPoint}]
    when entity is touched
    TouchMove [Data = {TouchPoint}]
    when finger is moved over entity
    TouchCancel [Data = {TouchPoint}]
    when a touch event has been disrupted in some way
    TouchEnd [Data = {null}]
    when the finger is raised over the entity, or when finger leaves entity. (Passes no data)

    To be able to use multitouch, you must enable it with Crafty.multitouch(true).

    +

    If you don't need multitouch, you can probably use the Mouse component instead, since by default Crafty will trigger mouse events for touch input.

    +

    You can read more about the TouchEvent.

    + +

    Example

    Crafty.multitouch(true);
    +
    +var myEntity = Crafty.e('2D, Canvas, Color, Touch')
    +.attr({x: 10, y: 10, w: 40, h: 40})
    +.color('green')
    +.bind('TouchStart', function(TouchPoint){
    +  Crafty.log('myEntity has been touched', TouchPoint);
    +}).bind('TouchMove', function(TouchPoint) {
    +  Crafty.log('Finger moved over myEntity at the { x: ' + TouchPoint.realX + ', y: ' + TouchPoint.realY + ' } coordinates.');
    +}).bind('TouchEnd', function() {
    +  Crafty.log('Touch over myEntity has finished.');
    +});
    + +
    +
    +
    + +
    + + diff --git a/api/Tween.html b/api/Tween.html index 435ff09..a1895dd 100644 --- a/api/Tween.html +++ b/api/Tween.html @@ -55,13 +55,16 @@ -

    Tween

    Events

    TweenEnd [ property { String }]
    when a tween finishes

    Component to animate the change in 2D properties over time.

    -

    Methods and Properties

    Back to top

    .cancelTween

    public this .cancelTween(String target)
    target

    The property to cancel

    -
    public this .cancelTween(Object target)
    target

    An object containing the properties to cancel.

    +

    Tween

    Events

    TweenEnd [property = {String}]
    when a tween finishes

    Component to animate the change in 2D properties over time.

    +

    Methods and Properties

    Back to top

    .cancelTween

    public this .cancelTween(String target)
    target

    The property to cancel

    +
    public this .cancelTween(Object target)
    target

    An object containing the properties to cancel.

    Stops tweening the specified property or properties. Passing the object used to start the tween might be a typical use of the second signature.

    -
    Back to top

    .tween

    public this .tween(Object properties, Number|String duration)
    properties

    Object of numeric properties and what they should animate to

    +
    Back to top

    .pauseTweens

    public this .pauseTweens()

    Pauses all tweens associated with the entity

    +
    Back to top

    .resumeTWeens

    public this .resumeTweens()

    Resumes all paused tweens associated with the entity

    +
    Back to top

    .tween

    public this .tween(Object properties, Number duration[, String|function easingFn])
    properties

    Object of numeric properties and what they should animate to

    duration

    Duration to animate the properties over, in milliseconds.

    +
    easingFn

    A string or custom function specifying an easing. (Defaults to linear behavior.) See Crafty.easing for more information.

    This method will animate numeric properties over the specified duration. These include x, y, w, h, alpha and rotation.

    The object passed should have the properties as keys and the value should be the resulting @@ -69,10 +72,10 @@

    Example

    Move an object to 100,100 and fade out over 200 ms.

    Crafty.e("2D, Tween")
        .attr({alpha: 1.0, x: 0, y: 0})
    -   .tween({alpha: 0.0, x: 100, y: 100}, 200)

    Example

    Rotate an object over 2 seconds

    + .tween({alpha: 0.0, x: 100, y: 100}, 200)

    Example

    Rotate an object over 2 seconds, using the "smootherStep" easing function.

    Crafty.e("2D, Tween")
        .attr({rotation:0})
    -   .tween({rotation:180}, 2000)
    + .tween({rotation:180}, 2000, "smootherStep")
    diff --git a/api/Twoway.html b/api/Twoway.html index 89e4cf6..f37614a 100644 --- a/api/Twoway.html +++ b/api/Twoway.html @@ -55,16 +55,16 @@ -

    Twoway

    Events

    NewDirection
    When direction changes a NewDirection event is triggered with an object detailing the new direction: {x: x_movement, y: y_movement}. This is consistent with Fourway and Multiway components.
    Moved
    When entity has moved on x-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}

    Move an entity left or right using the arrow keys or D and A and jump using up arrow or W.

    -

    Methods and Properties

    Back to top

    .twoway

    public this .twoway(Number speed[, Number jump])
    speed

    Amount of pixels to move left or right

    -
    jump

    Vertical jump speed

    +

    Twoway

    Events

    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.
    CheckJumping
    When entity is about to jump. This event is triggered with the object the entity is about to jump from (if it exists). Third parties can respond to this event and enable the entity to jump.

    Move an entity left or right using the arrow keys or D and A and jump using up arrow or W.

    +

    Methods and Properties

    Back to top

    .twoway

    public this .twoway([Number speed[, Number jumpSpeed]])
    speed

    A speed in pixels per second

    +
    jumpSpeed

    Vertical jump speed in pixels per second

    Constructor to initialize the speed and power of jump. Component will listen for key events and move the entity appropriately. This includes Up Arrow, Right Arrow, Left Arrow as well as W, A, D. Used with the gravity component to simulate jumping.

    The key presses will move the entity in that direction by the speed passed in the argument. Pressing the Up Arrow or W will cause the entity to jump.

    -
    +
    diff --git a/api/VisibleMBR.html b/api/VisibleMBR.html index c1bb4d1..651914a 100644 --- a/api/VisibleMBR.html +++ b/api/VisibleMBR.html @@ -55,7 +55,7 @@ -

    VisibleMBR

    Adding this component to an entity will cause it's MBR to be drawn to the debug canvas.

    +

    VisibleMBR

    Adding this component to an entity will cause it's MBR to be drawn to the debug canvas.

    The methods of DebugCanvas can be used to control this component's appearance.

    diff --git a/api/WebGL.html b/api/WebGL.html new file mode 100644 index 0000000..c5db013 --- /dev/null +++ b/api/WebGL.html @@ -0,0 +1,105 @@ + + + + Crafty - WebGL + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    WebGL

    Events

    Draw [Data = {type: "canvas", pos, co, ctx}]
    when the entity is ready to be drawn to the stage
    NoCanvas
    if the browser does not support canvas

    When this component is added to an entity it will be drawn to the global webgl canvas element. Its canvas element (and hence any WebGL entity) is always rendered below any DOM entities.

    +

    Sprite, Image, SpriteAnimation, and Color all support WebGL rendering. Text entities will need to use DOM or Canvas for now.

    +

    If a webgl context does not yet exist, a WebGL entity will automatically create one by calling Crafty.webgl.init() before rendering.

    +

    Note: For better performance, minimize the number of spritesheets used, and try to arrange it so that entities with different spritesheets are on different z-levels. This is because entities are rendered in z order, and only entities sharing the same texture can be efficiently batched.

    +

    Create a webgl entity like this

    +
    var myEntity = Crafty.e("2D, WebGL, Color")
    +     .color(1, 1, 0, 0.5)
    +     .attr({x: 13, y: 37, w: 42, h: 42});

    Methods and Properties

    Back to top

    .context

    The webgl context this entity will be rendered to.

    +
    Back to top

    .draw

    public this .draw([[Context ctx, ]Number x, Number y, Number w, Number h])
    ctx

    Optionally supply a different r 2D context if drawing on another canvas is required

    +
    x

    X offset for drawing a segment

    +
    y

    Y offset for drawing a segment

    +
    w

    Width of the segment to draw

    +
    h

    Height of the segment to draw

    +

    An internal method to draw the entity on the webgl canvas element. Rather then rendering directly, it writes relevent information into a buffer to allow batch rendering.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/WiredAreaMap.html b/api/WiredAreaMap.html new file mode 100644 index 0000000..fb2a3b5 --- /dev/null +++ b/api/WiredAreaMap.html @@ -0,0 +1,94 @@ + + + + Crafty - WiredAreaMap + + + + + + + + + + +
    +
    + + + +
    +
    + + + + +

    WiredAreaMap

    Adding this component to an entity with an AreaMap component will cause its click polygon to be drawn to the debug canvas as an outline. +Following click areas exist for an entity (in decreasing order of priority): AreaMap, Hitbox, MBR. Use the appropriate debug components to display them.

    +

    The methods of DebugCanvas can be used to control this component's appearance.

    +
    + +
    +
    +
    + +
    + + diff --git a/api/WiredHitBox.html b/api/WiredHitBox.html index 602cfe7..9f2cdc9 100644 --- a/api/WiredHitBox.html +++ b/api/WiredHitBox.html @@ -55,7 +55,7 @@ -

    WiredHitBox

    Adding this component to an entity with a Collision component will cause its collision polygon to be drawn to the debug canvas as an outline

    +

    WiredHitBox

    Adding this component to an entity with a Collision component will cause its collision polygon to be drawn to the debug canvas as an outline

    The methods of DebugCanvas can be used to control this component's appearance.

    diff --git a/api/events.html b/api/events.html index 32e1c93..8b4c1bf 100644 --- a/api/events.html +++ b/api/events.html @@ -55,7 +55,7 @@ -

    2D

    Move [ Old position { { _x:Number, _y:Number, _w:Number, _h:Number } }]
    when the entity has moved
    Invalidate
    when the entity needs to be redrawn
    Rotate [ Data { { cos:Number, sin:Number, deg:Number, rad:Number, o: {x:Number, y:Number}} }]
    when the entity is rotated

    .offsetBoundary

    BoundaryOffset
    when the MBR offset changes

    .flip

    Invalidate
    when the entity has flipped

    .unflip

    Invalidate
    when the entity has unflipped

    Gravity

    Moved
    When entity has moved on y-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}

    .DOM

    Draw [ Data { { style:String, type:"DOM", co} }]
    when the entity is ready to be drawn to the stage

    DebugCanvas

    Draw
    when the entity is ready to be drawn to the stage
    NoCanvas
    if the browser does not support canvas

    Tween

    TweenEnd [ property { String }]
    when a tween finishes

    Canvas

    Draw [ Data { {type: "canvas", pos, co, ctx} }]
    when the entity is ready to be drawn to the stage
    NoCanvas
    if the browser does not support canvas

    Crafty.canvas.init

    NoCanvas
    triggered if `Crafty.support.canvas` is false

    Collision

    HitOn [ Data { { hitData } }]
    Triggered when collisions occur. Will not trigger again until collisions of this type cease, or an event is requested once more (using `resetHitChecks(component)`).
    HitOff [ Data { { componentName } }]
    Triggered when collision with a specific component type ceases

    .collision

    NewHitbox [ Data { Crafty.polygon }]
    when a new hitbox is assigned

    .color

    Invalidate
    when the color changes

    KeyboardEvent

    KeyDown
    is triggered for each entity when the DOM 'keydown' event is triggered.
    KeyUp
    is triggered for each entity when the DOM 'keyup' event is triggered.

    Mouse

    MouseOver [ Data { MouseEvent }]
    when the mouse enters
    MouseOut [ Data { MouseEvent }]
    when the mouse leaves
    MouseDown [ Data { MouseEvent }]
    when the mouse button is pressed on
    MouseUp [ Data { MouseEvent }]
    when the mouse button is released on
    Click [ Data { MouseEvent }]
    when the user clicks
    DoubleClick [ Data { MouseEvent }]
    when the user double clicks
    MouseMove [ Data { MouseEvent }]
    when the mouse is over and moves

    Draggable

    Dragging [ Data { MouseEvent }]
    is triggered each frame the entity is being dragged
    StartDrag [ Data { MouseEvent }]
    is triggered when dragging begins
    StopDrag [ Data { MouseEvent }]
    is triggered when dragging ends

    .stopDrag

    StopDrag
    Called right after the mouse listeners are removed

    Multiway

    NewDirection [ New direction { { x:Number, y:Number } }]
    triggered when direction changes
    Moved [ Old position { { x:Number, y:Number } }]
    triggered on movement on either x or y axis. If the entity has moved on both axes for diagonal movement the event is triggered twice

    Twoway

    NewDirection
    When direction changes a NewDirection event is triggered with an object detailing the new direction: {x: x_movement, y: y_movement}. This is consistent with Fourway and Multiway components.
    Moved
    When entity has moved on x-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}

    Crafty Core

    NewEntityName [ entity name { String }]
    After setting new name for entity
    NewComponent [ Component { String }]
    when a new component is added to the entity
    RemoveComponent [ Component { String }]
    when a component is removed from the entity
    Remove
    when the entity is removed by calling .destroy()

    .attr

    Change [ Data { {key: value} }]
    when properties change

    Crafty.init

    Load
    Just after the viewport is initialised. Before the EnterFrame loops is started

    Crafty.stop

    CraftyStop
    when the game is stopped

    Crafty.pause

    Pause
    when the game is paused
    Unpause
    when the game is unpaused

    Crafty.timer.step

    EnterFrame [ Data { { frame: Number, dt:Number } }]
    Triggered on each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)
    ExitFrame [ Data { { frame: Number, dt:Number } }]
    Triggered after each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)
    PreRender
    Triggered every time immediately before a scene should be rendered
    RenderScene
    Triggered every time a scene should be rendered
    PostRender
    Triggered every time immediately after a scene should be rendered
    MeasureWaitTime [ Data { Number }]
    Triggered at the beginning of each step after the first. Passes the time the game loop waited between steps.
    MeasureFrameTime [ Data { Number }]
    Triggered after each frame. Passes the time it took to advance one frame.
    MeasureRenderTime [ Data { Number }]
    Triggered after each render. Passes the time it took to render the scene

    Crafty.e

    NewEntity [ Data { { id:Number } }]
    When the entity is created and all components are added

    .image

    Invalidate
    when the image is loaded

    Crafty.asset

    NewAsset [ key and value of new added asset. { Object }]
    After setting new asset

    Model

    Change
    When any data on the model has changed.
    Change[key]
    When the specific key on the model has changed.
    Change[key.key]
    The nested key value has changed.

    Particles

    ParticleEnd
    when the particle animation has finished

    Crafty.scene

    SceneChange [ Data { { oldScene:String, newScene:String } }]
    just before a new scene is initialized
    SceneDestroy [ Data { { newScene:String } }]
    just before the current scene is destroyed

    SpriteAnimation

    StartAnimation [ Data { {Reel} }]
    When an animation starts playing, or is resumed from the paused state
    AnimationEnd [ Data { { Reel } }]
    When the animation finishes
    FrameChange [ Data { { Reel } }]
    Each time the frame of the current reel changes
    ReelChange [ Data { { Reel } }]
    When the reel changes

    Sprite

    Invalidate
    when the sprites change

    Text

    Invalidate
    when the text is changed

    .textFont

    Invalidate

    .unselectable

    Invalidate

    Crafty.viewport

    ViewportScroll
    when the viewport's x or y coordinates change
    ViewportScale
    when the viewport's scale changes
    ViewportResize
    when the viewport's dimension's change
    InvalidateViewport
    when the viewport changes
    StopCamera
    when any camera animations should stop, such as at the start of a new animation.
    CameraAnimationDone
    when a camera animation comes reaches completion

    Crafty.viewport.reset

    StopCamera
    called to cancel camera animations
    +

    Multiway

    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.

    Jumper

    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.
    CheckJumping
    When entity is about to jump. This event is triggered with the object the entity is about to jump from (if it exists). Third parties can respond to this event and enable the entity to jump.

    Fourway

    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.

    Twoway

    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.
    CheckJumping
    When entity is about to jump. This event is triggered with the object the entity is about to jump from (if it exists). Third parties can respond to this event and enable the entity to jump.

    Crafty.mouseWheelDispatch

    MouseWheelScroll [Scroll direction (up | down) = { direction: +1 | -1}]
    is triggered when mouse is scrolled on stage

    KeyboardEvent

    KeyDown
    is triggered for each entity when the DOM 'keydown' event is triggered.
    KeyUp
    is triggered for each entity when the DOM 'keyup' event is triggered.

    Mouse

    MouseOver [Data = {MouseEvent}]
    when the mouse enters
    MouseOut [Data = {MouseEvent}]
    when the mouse leaves
    MouseDown [Data = {MouseEvent}]
    when the mouse button is pressed on
    MouseUp [Data = {MouseEvent}]
    when the mouse button is released on
    Click [Data = {MouseEvent}]
    when the user clicks
    DoubleClick [Data = {MouseEvent}]
    when the user double clicks
    MouseMove [Data = {MouseEvent}]
    when the mouse is over and moves

    Touch

    TouchStart [Data = {TouchPoint}]
    when entity is touched
    TouchMove [Data = {TouchPoint}]
    when finger is moved over entity
    TouchCancel [Data = {TouchPoint}]
    when a touch event has been disrupted in some way
    TouchEnd [Data = {null}]
    when the finger is raised over the entity, or when finger leaves entity. (Passes no data)

    .areaMap

    NewAreaMap [Data = {Crafty.polygon}]
    when a new areaMap is assigned

    MouseDrag

    Dragging [Data = {MouseEvent}]
    is triggered each frame the entity is being dragged
    StartDrag [Data = {MouseEvent}]
    is triggered when dragging begins
    StopDrag [Data = {MouseEvent}]
    is triggered when dragging ends

    Crafty Core

    NewEntityName [entity name = {String}]
    After setting new name for entity
    NewComponent [Component = {String}]
    when a new component is added to the entity
    RemoveComponent [Component = {String}]
    when a component is removed from the entity
    Remove
    when the entity is removed by calling .destroy()

    .attr

    Change [Data = {key: value}]
    when properties change

    Crafty.init

    Load
    Just after the viewport is initialised. Before the EnterFrame loops is started

    Crafty.stop

    CraftyStop [Data = {bool clearState}]
    when the game is stopped

    Crafty.pause

    Pause
    when the game is paused
    Unpause
    when the game is unpaused

    Crafty.timer.step

    EnterFrame [Data = { frame: Number, dt:Number }]
    Triggered on each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)
    ExitFrame [Data = { frame: Number, dt:Number }]
    Triggered after each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)
    PreRender
    Triggered every time immediately before a scene should be rendered
    RenderScene
    Triggered every time a scene should be rendered
    PostRender
    Triggered every time immediately after a scene should be rendered
    MeasureWaitTime [Data = {Number}]
    Triggered at the beginning of each step after the first. Passes the time the game loop waited between steps.
    MeasureFrameTime [Data = {Number}]
    Triggered after each frame. Passes the time it took to advance one frame.
    MeasureRenderTime [Data = {Number}]
    Triggered after each render. Passes the time it took to render the scene

    Crafty.timer.FPS

    FPSChange [new target FPS = {Number}]
    Triggered when the target FPS is changed by user

    Crafty.e

    NewEntity [Data = { id:Number }]
    When the entity is created and all components are added

    Crafty.asset

    NewAsset [key and value of new added asset. = {Object}]
    After setting new asset

    Model

    Change
    When any data on the model has changed.
    Change[key]
    When the specific key on the model has changed.
    Change[key.key]
    The nested key value has changed.

    Crafty.scene

    SceneChange [Data = { oldScene:String, newScene:String }]
    just before a new scene is initialized
    SceneDestroy [Data = { newScene:String }]
    just before the current scene is destroyed

    Crafty.s

    SystemLoaded [system object = {obj}]
    When the system has initialized itself
    SystemDestroyed [system object = {obj}]
    Right before the system is destroyed

    Tween

    TweenEnd [property = {String}]
    when a tween finishes

    DebugCanvas

    Draw
    when the entity is ready to be drawn to the stage
    NoCanvas
    if the browser does not support canvas

    Crafty.canvasLayer.init

    NoCanvas
    triggered if `Crafty.support.canvas` is false

    Canvas

    Draw [Data = {type: "canvas", pos, co, ctx}]
    when the entity is ready to be drawn to the stage
    NoCanvas
    if the browser does not support canvas

    .color

    Invalidate
    when the color changes

    .DOM

    Draw [Data = { style:String, type:"DOM", co}]
    when the entity is ready to be drawn to the stage

    .image

    Invalidate
    when the image is loaded

    Particles

    ParticleEnd
    when the particle animation has finished

    SpriteAnimation

    StartAnimation [Data = {Reel}]
    When an animation starts playing, or is resumed from the paused state
    AnimationEnd [Data = { Reel }]
    When the animation finishes
    FrameChange [Data = { Reel }]
    Each time the frame of the current reel changes
    ReelChange [Data = { Reel }]
    When the reel changes

    Sprite

    Invalidate
    when the sprites change

    Text

    Invalidate
    when the text is changed

    .textFont

    Invalidate

    .unselectable

    Invalidate

    Crafty.viewport

    ViewportScroll
    when the viewport's x or y coordinates change
    ViewportScale
    when the viewport's scale changes
    ViewportResize
    when the viewport's dimension's change
    InvalidateViewport
    when the viewport changes
    StopCamera
    when any camera animations should stop, such as at the start of a new animation.
    CameraAnimationDone
    when a camera animation reaches completion

    Crafty.viewport.reset

    StopCamera
    called to cancel camera animations

    WebGL

    Draw [Data = {type: "canvas", pos, co, ctx}]
    when the entity is ready to be drawn to the stage
    NoCanvas
    if the browser does not support canvas

    Crafty.webgl.init

    NoWebGL
    triggered if `Crafty.support.webgl` is false

    2D

    Move [Old position = { _x:Number, _y:Number, _w:Number, _h:Number }]
    when the entity has moved
    Invalidate
    when the entity needs to be redrawn
    Rotate [Data = { cos:Number, sin:Number, deg:Number, rad:Number, o: {x:Number, y:Number}}]
    when the entity is rotated
    Reorder
    when the entity's z index has changed

    .offsetBoundary

    BoundaryOffset
    when the MBR offset changes

    .flip

    Invalidate
    when the entity has flipped

    .unflip

    Invalidate
    when the entity has unflipped

    Supportable

    LandedOnGround
    When entity has landed. This event is triggered with the object the entity landed on.
    LiftedOffGround
    When entity has lifted off. This event is triggered with the object the entity stood on before lift-off.
    CheckLanding
    When entity is about to land. This event is triggered with the object the entity is about to land on. Third parties can respond to this event and prevent the entity from being able to land.

    Gravity

    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.
    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.

    AngularMotion

    Rotated [Old rotation = {Number}]
    When entity has rotated due to angular velocity/acceleration a Rotated event is triggered.
    NewRotationDirection [New direction = {-1 | 0 | 1}]
    When entity has changed rotational direction due to rotational velocity a NewRotationDirection event is triggered. The event is triggered once, if direction is different from last frame.
    MotionChange [Motion property name and old value = { key: String, oldValue: Number }]
    When a motion property has changed a MotionChange event is triggered.

    Motion

    Moved [Old position = { axis: 'x' | 'y', oldValue: Number }]
    When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.
    NewDirection [New direction = { x: -1 | 0 | 1, y: -1 | 0 | 1 }]
    When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.
    MotionChange [Motion property name and old value = { key: String, oldValue: Number }]
    When a motion property has changed a MotionChange event is triggered.

    Collision

    HitOn [Data = { hitData }]
    Triggered when collisions occur. Will not trigger again until collisions of this type cease, or an event is requested once more (using `resetHitChecks(component)`).
    HitOff [componentName = {String}]
    Triggered when collision with a specific component type ceases

    .collision

    NewHitbox [Data = {Crafty.polygon}]
    when a new hitbox is assigned
    diff --git a/api/index.html b/api/index.html index cbf118b..fb8ad34 100644 --- a/api/index.html +++ b/api/index.html @@ -55,7 +55,7 @@ - +
    diff --git a/components/index.html b/components/index.html index af15138..c665505 100644 --- a/components/index.html +++ b/components/index.html @@ -56,8 +56,8 @@

    Components

    An overview over components made by the community.

    -

    If you would like your component listed here, create an issue or PR on Github.

    -

    Note that some components may be outdated and may no longer work with the most recent Crafty version.

    +

    If you would like your component listed here, create an issue or PR on Github. +

    diff --git a/cookbook/text-sprite.html b/cookbook/text-sprite.html index 481190b..83d265b 100644 --- a/cookbook/text-sprite.html +++ b/cookbook/text-sprite.html @@ -102,16 +102,16 @@

    Text Sprites

    }); Crafty.c("Char",{ - init:function(){ + init:function(){ this.addComponent("2D,DOM").attr({w:24,h:32}); } }); Crafty.c("SpriteText",{ - init:function(){ + init:function(){ this.addComponent("2D,DOM"); }, - text:function(text){ + text:function(text){ var c; for(var i = 0; i<text.length;i++){ c = Crafty.e("Char",text.charAt(i).toUpperCase()); diff --git a/craftyjs-site.css b/craftyjs-site.css index d26377a..65382cf 100644 --- a/craftyjs-site.css +++ b/craftyjs-site.css @@ -6597,13 +6597,17 @@ a img { padding-left: 1em; } /*Documentation styles*/ +/* Horizontal space between blocks*/ +.block-spacing { + margin-top: 1em; +} /* Blocks offset by a large colored margin */ /* Links to the source code */ .doc-source { color: grey; font-size: 10px; font-family: 'Menlo', 'Monaco', 'Consolas', 'Courier New', monospace; - margin-top: -10px; + margin-top: -1em; } .crafty-method, .triggered-events { @@ -6632,6 +6636,24 @@ h3 { padding-left: 1em; font-weight: bold; } +/* Warnings */ +.warning { + border-left: 20px solid #ffa500 !important; + /*box-shadow: 3px 2px 3px #555555;*/ + margin-top: 1em; + background-color: #ffdb99; + padding-left: 1em; + padding-top: 1px; + padding-bottom: 1px; +} +.warning-prefix { + font-variant: small-caps; + font-weight: bold; +} +/* Notes */ +.note { + margin-top: 1em; +} /* Event blocks */ .trigger dt { white-space: pre; @@ -6680,6 +6702,17 @@ code.signature { display: block; font-family: 'Menlo', 'Monaco', 'Consolas', 'Courier New', monospace; } +.signature .sig-noun { + font-weight: bold; +} +.signature .sig-qualifier { + font-size: normal; + font-weight: normal; + color: #36597d; +} +.signature .sig-seperator { + color: black; +} .parameter dt { font-weight: bold; } @@ -6705,6 +6738,9 @@ code { .markdown { display: block; } +.doclet > .markdown { + margin-top: 1em; +} .markdown pre, #quickstart pre, #docs pre, diff --git a/documentation/2d.html b/documentation/2d.html index 222bdac..5d95432 100644 --- a/documentation/2d.html +++ b/documentation/2d.html @@ -144,7 +144,7 @@

    2D Graphics

  • Finally we use the .attr() function to set several properties of the entity, in this case its position and dimensions. Like most functions, attr() returns the entity it was called on, so we can chain the color() method to set the color of the entity.
  • Easy enough! Now we have a red box showing up on the page, but how about setting it into motion? For instance, we might want to set the box spinning; if you look at the documentation for "2D", you'll see that it provides a rotation property, but how could we animate that? Simple enough: we can bind to the "EnterFrame" event to change the rotation once per frame:

    -
    square.bind('EnterFrame', function(){
    +
    square.bind('EnterFrame', function(){
       this.rotation = this.rotation + 1;
     });

    Now we have bound to "EnterFrame" event, this will be triggered each frame, so the square will rotate.

    @@ -163,7 +163,7 @@

    2D Graphics

    square.origin("center") -square.bind('EnterFrame', function(){ +square.bind('EnterFrame', function(){ this.rotation = this.rotation + 1; });

    And here's the code in action!

    diff --git a/documentation/components.html b/documentation/components.html index 8b8e7b3..464fdc0 100644 --- a/documentation/components.html +++ b/documentation/components.html @@ -140,7 +140,7 @@

    Custom Components

    Crafty.c("Square", {
         // This function will be called when the component is added to an entity
         // So it sets up the things that both our entities had in common
    -    init: function() {
    +    init: function() {
             this.addComponent("2D, Canvas, Color");
             this.w = 30;
             this.h = 30;
    @@ -148,7 +148,7 @@ 

    Custom Components

    // Our two entities had different positions, // so we define a method for setting the position - place: function(x, y) { + place: function(x, y) { this.x = x; this.y = y; @@ -187,7 +187,7 @@

    The shared object trap

    console.log(e2.sharedObject.a); // Logs 5!

    If you want a property to be an object, but don't want it shared between entities, the solution is to create a new object inside the init method:

    Crafty.c("MyComponent", {
    -    init: function() {
    +    init: function() {
             this.myObject = {a:1, b:2};
         }
     });
    diff --git a/documentation/entities.html b/documentation/entities.html
    index 11103b4..32112a1 100644
    --- a/documentation/entities.html
    +++ b/documentation/entities.html
    @@ -155,7 +155,7 @@ 

    Setting properties

    Events

    Crafty uses both global and local events for communication amongst entities and components. To create an event listener, you can use the .bind() method. Let's make our previous square switch colors in response to an event.

    // Bind a function to the event
    -square.bind("ChangeColor", function(eventData){
    +square.bind("ChangeColor", function(eventData){
             // `this` refers to the entity
             this.color(eventData.color);
         })
    @@ -181,7 +181,7 @@ 

    Selecting entities

    Crafty("*");

    Once you have a selection, you can call event-related methods directly:

    // Bind a function to *every* entity with the Keyboard component
    -Crafty("Keyboard").bind("KeyDown", function(){
    +Crafty("Keyboard").bind("KeyDown", function(){
         // Do something on keydown
     });
     
    @@ -189,7 +189,7 @@ 

    Selecting entities

    Crafty("*").trigger("Explode");

    You can run a function in the context of every entity:

    // Move every 2D entity 5 pixels to the right
    -Crafty("2D").each(function() {
    +Crafty("2D").each(function() {
         this.x += 5;
     });

    If you need to know how many entities are in the selection, you can check the length property.

    diff --git a/documentation/events.html b/documentation/events.html index 550f0ad..459ae26 100644 --- a/documentation/events.html +++ b/documentation/events.html @@ -136,7 +136,7 @@

    The Event System

    .color("blue"); // When a "Blush" event is triggered, turn pink -square.bind("Blush", function() { +square.bind("Blush", function() { // the function will be called in the context of the entity this.color("pink") }); @@ -147,14 +147,14 @@

    The Event System

    Every entity automatically gets several methods which relate to events; these are documented under Crafty Core. We'll explore aspects of this in more detail below.

    Passing data

    Many events pass data to the bound function. Let's make the above code a bit more generic by defining a "ChangeColor" event:

    -
    square.bind("ChangeColor", function(color) {
    +
    square.bind("ChangeColor", function(color) {
         this.color(color);
     });
     
     square.trigger("ChangeColor", "pink"); // Turn pink

    When you trigger the event, a single paramter can be passed as the second argument. This isn't too limiting, because you can always pass an object -- for instance, if we wanted "ChangeColor" to use rgb values instead of a single name:

    // Assume that color is an object
    -square.bind("ChangeColor", function(color) {
    +square.bind("ChangeColor", function(color) {
         this.color(color.r, color,g, color.b);
     })
     
    @@ -162,7 +162,7 @@ 

    Passing data

    square.trigger("ChangeColor", {r:255, g:192, b:203});

    Unbinding events

    To unbind an event, you need a reference to the bound function, so you typically can't use an anonymous one. Modifying our initial example:

    -
    var turnPink = function() { 
    +
    var turnPink = function() { 
         this.color("pink");
     }
     
    @@ -173,7 +173,7 @@ 

    Unbinding events

    square.unbind("Blush", turnPink);

    Very commonly, you might want a function to only be triggered once. In that case, you can bind it with .one() instead of .bind():

    // Use the .one() method instead of .bind()
    -square.one("JumpRight", function() {
    +square.one("JumpRight", function() {
         // Move 10 px to the right
         this.x += 100;
     });
    @@ -185,7 +185,7 @@ 

    Working with built-in events

    Many of Crafty's built-in components will trigger events, and the more useful ones will be documented in the API reference. For instance, the 2D component tells us that it will trigger a "Move" event any time the object's position changes, and that the event will pass along an object containing the entity's old position.

    // Bind a function to the "Move" event
     // It will log the initial and new x position anytime the entity moves
    -square.bind("Move", function(oldPosition) {
    +square.bind("Move", function(oldPosition) {
         console.log(oldPosition._x, this.x);
     });
     
    @@ -198,8 +198,8 @@ 

    Global events

    var xhuli = Crafty.e("2D").attr({x:10}); // Bind to an event called "Thing" -varrick.bind("Thing", function() { this.x += 20; }); -xhuli.bind("Thing", function() { this.x += 10; }); +varrick.bind("Thing", function() { this.x += 20; }); +xhuli.bind("Thing", function() { this.x += 10; }); // Do the thing! // varrick and xhuli will *both* move to the right @@ -208,7 +208,7 @@

    Global events

    // You can still trigger the same events directly on an entity xhuli.trigger("Thing");

    You can also bind to events directly on the Crafty object:

    -
    Crafty.bind("Thing", function() {
    +
    Crafty.bind("Thing", function() {
         console.log("Crafty does the thing.")
     });

    In such a globally bound function, the context will be the global Crafty object (this === Crafty).

    diff --git a/documentation/gameloop.html b/documentation/gameloop.html index c752f8c..768313c 100644 --- a/documentation/gameloop.html +++ b/documentation/gameloop.html @@ -146,7 +146,7 @@

    EnterFrame

    var square = Crafty.e('2D, Canvas, Color'); .attr({x: 10, y: 10, w: 100, h: 100}) .color('red') - .bind("EnterFrame", function(eventData) { + .bind("EnterFrame", function(eventData) { // Move to the right by 10 pixels per second this.x = this.x + 10 * (eventData.dt / 1000); };
    diff --git a/documentation/keyboard.html b/documentation/keyboard.html index acb4a91..b6dd1c3 100644 --- a/documentation/keyboard.html +++ b/documentation/keyboard.html @@ -128,7 +128,7 @@

    Keyboard

    -

    To have the keyboard control player movement, Crafty provides three simple componenets that will get you started very quickly:

    +

    To have the keyboard control player movement, Crafty provides three simple components that will get you started very quickly:

    • Twoway
    • Fourway
    • @@ -153,17 +153,17 @@

      Twoway

      The Keyboard component

      You might well need more control than the above components provide. To respond to specific keyboard events, give an entity the "Keyboard" component. In the example below, we create a red square that will turn blue when you press any key.

      Crafty.init();
      -Crafty.e('2D, Canvas, Keyboard')
      +Crafty.e('2D, Canvas, Color, Keyboard')
         .attr({x: 10, y: 10, h: 30, w: 30})
         .color('red')
      -  .bind("KeyDown", function() {
      +  .bind("KeyDown", function() {
           this.color("blue");
         })

      The various keyboard events will be passed information about the original DOM event, and Crafty provides a dictionary of key codes for convenience. In the following example, we create a square that can be moved by the arrow keys:

      -
      Crafty.e("2D, Canvas, Color")
      +
      Crafty.e("2D, Canvas, Color, Keyboard")
         .attr({x: 10, y: 10, w: 30, h: 30})
         .color("red")
      -  .bind('KeyDown', function(e) {
      +  .bind('KeyDown', function(e) {
           if(e.key == Crafty.keys.LEFT_ARROW) {
             this.x = this.x - 1;
           } else if (e.key == Crafty.keys.RIGHT_ARROW) {
      diff --git a/getting-started/index.html b/getting-started/index.html
      index 642d831..fc7a693 100644
      --- a/getting-started/index.html
      +++ b/getting-started/index.html
      @@ -76,7 +76,7 @@ 

      Setup

      <head></head> <body> <div id="game"></div> - <script type="text/javascript" src="https://rawgithub.com/craftyjs/Crafty/release/dist/crafty-min.js"></script> + <script type="text/javascript" src="https://rawgithub.com/craftyjs/Crafty/release/dist/crafty-min.js"></script> <script> Crafty.init(500,350, document.getElementById('game')); </script> @@ -95,7 +95,7 @@

      Setup

      <head></head> <body> <div id="game"></div> - <script type="text/javascript" src="https://rawgithub.com/craftyjs/Crafty/release/dist/crafty-min.js"></script> + <script type="text/javascript" src="https://rawgithub.com/craftyjs/Crafty/release/dist/crafty-min.js"></script> <script> Crafty.init(500,350, document.getElementById('game')); Crafty.e('2D, DOM, Color').attr({x: 0, y: 0, w: 100, h: 100}).color('#F00'); diff --git a/index.html b/index.html index 1fa641a..53995ca 100644 --- a/index.html +++ b/index.html @@ -102,7 +102,7 @@ Show Crafty.js some love:
    -
    October 4: Try the 0.7.0 beta — WebGL support and more!
    +
    diff --git a/source/api-gen/api.json b/source/api-gen/api.json index 66c52a7..dd6d329 100644 --- a/source/api-gen/api.json +++ b/source/api-gen/api.json @@ -1,1519 +1,1705 @@ [ { - "file": "src/2D.js", - "startLine": 47, - "endLine": 51, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 3, + "endLine": 9, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Functions related with querying entities." + "value": "Enable drag and drop of the entity. Listens to events from `MouseDrag` and moves entity accordingly.\n" }, { "type": "xref", "xrefs": [ - "Crafty.HashMap" + "MouseDrag" ] } ], - "name": "Crafty.map", + "name": "Draggable", "categories": [ - "2D" + "Controls" ] }, { - "file": "src/2D.js", - "startLine": 69, - "endLine": 75, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 28, + "endLine": 36, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "Component for any entity that has a position on the stage." + "type": "method", + "signature": "public this .enableDrag(void)", + "contents": [] }, - { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "Move", - "description": "when the entity has moved", - "objName": "Old position", - "objProp": "{ _x:Number, _y:Number, _w:Number, _h:Number }" - }, - { - "type": "trigger", - "event": "Invalidate", - "description": "when the entity needs to be redrawn", - "objName": "Data", - "objProp": null - }, - { - "type": "trigger", - "event": "Rotate", - "description": "when the entity is rotated", - "objName": "Data", - "objProp": "{ cos:Number, sin:Number, deg:Number, rad:Number, o: {x:Number, y:Number}}" - } - ] - } - ], - "name": "2D", - "categories": [ - "2D" - ] - }, - { - "file": "src/2D.js", - "startLine": 78, - "endLine": 84, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "raw", - "value": "The `x` position on the stage. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._x` property." + "value": "Reenable dragging of entity. Use if `.disableDrag` has been called.\n" }, { "type": "xref", "xrefs": [ - "._attr" + ".disableDrag" ] } ], - "name": ".x", - "comp": "2D" + "name": ".enableDrag", + "comp": "Draggable" }, { - "file": "src/2D.js", - "startLine": 87, - "endLine": 93, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 42, + "endLine": 50, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this .disableDrag(void)", + "contents": [] + }, { "type": "raw", - "value": "The `y` position on the stage. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._y` property." + "value": "Disables entity dragging. Reenable with `.enableDrag()`.\n" }, { "type": "xref", "xrefs": [ - "._attr" + ".enableDrag" ] } ], - "name": ".y", - "comp": "2D" + "name": ".disableDrag", + "comp": "Draggable" }, { - "file": "src/2D.js", - "startLine": 96, - "endLine": 104, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 56, + "endLine": 84, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "The width of the entity. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._w` property.\n\nChanging this value is not recommended as canvas has terrible resize quality and DOM will just clip the image." + "value": "Method used for modifying the drag direction.\nIf direction is set, the entity being dragged will only move along the specified direction.\nIf direction is not set, the entity being dragged will move along any direction.\n" }, { - "type": "xref", - "xrefs": [ - "._attr" + "type": "method", + "signature": "public this .dragDirection()", + "contents": [] + }, + { + "type": "raw", + "value": "Remove any previously specified direction.\n" + }, + { + "type": "method", + "signature": "public this .dragDirection(vector)", + "contents": [ + { + "type": "param", + "name": "vector", + "description": "Of the form of {x: valx, y: valy}, the vector (valx, valy) denotes the move direction." + } ] - } - ], - "name": ".w", - "comp": "2D" - }, - { - "file": "src/2D.js", - "startLine": 107, - "endLine": 115, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, + { + "type": "method", + "signature": "public this .dragDirection(degree)", + "contents": [ + { + "type": "param", + "name": "degree", + "description": "A number, the degree (clockwise) of the move direction with respect to the x axis." + } + ] + }, { "type": "raw", - "value": "The height of the entity. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._h` property.\n\nChanging this value is not recommended as canvas has terrible resize quality and DOM will just clip the image." + "value": "Specify the dragging direction.\n" }, { - "type": "xref", - "xrefs": [ - "._attr" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nthis.dragDirection()\nthis.dragDirection({x:1, y:0}) //Horizontal\nthis.dragDirection({x:0, y:1}) //Vertical\n// Note: because of the orientation of x and y axis,\n// this is 45 degree clockwise with respect to the x axis.\nthis.dragDirection({x:1, y:1}) //45 degree.\nthis.dragDirection(60) //60 degree.\n```" + } ] } ], - "name": ".h", - "comp": "2D" + "name": ".dragDirection", + "comp": "Draggable" }, { - "file": "src/2D.js", - "startLine": 118, - "endLine": 130, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 128, + "endLine": 137, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "NewDirection", + "description": "When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.", + "objName": "New direction", + "objProp": "{ x: -1 | 0 | 1, y: -1 | 0 | 1 }" + }, + { + "type": "trigger", + "event": "Moved", + "description": "When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.", + "objName": "Old position", + "objProp": "{ axis: 'x' | 'y', oldValue: Number }" + } + ] + }, { "type": "raw", - "value": "The `z` index on the stage. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._z` property.\n\nA higher `z` value will be closer to the front of the stage. A smaller `z` value will be closer to the back.\nA global Z index is produced based on its `z` value as well as the GID (which entity was created first).\nTherefore entities will naturally maintain order depending on when it was created if same z value.\n\n`z` is required to be an integer, e.g. `z=11.2` is not allowed." + "value": "Used to bind keys to directions and have the entity move accordingly.\n" }, { "type": "xref", "xrefs": [ - "._attr" + "Motion", + "Keyboard" ] } ], - "name": ".z", - "comp": "2D" + "name": "Multiway", + "categories": [ + "Controls" + ] }, { - "file": "src/2D.js", - "startLine": 133, - "endLine": 153, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 184, + "endLine": 206, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this .multiway([Number speed,] Object keyBindings)", + "contents": [ + { + "type": "param", + "name": "speed", + "description": "A speed in pixels per second" + }, + { + "type": "param", + "name": "keyBindings", + "description": "What keys should make the entity go in which direction. Direction is specified in degrees" + } + ] + }, { "type": "raw", - "value": "The rotation state of the entity, in clockwise degrees.\n`this.rotation = 0` sets it to its original orientation; `this.rotation = 10`\nsets it to 10 degrees clockwise from its original orientation;\n`this.rotation = -10` sets it to 10 degrees counterclockwise from its\noriginal orientation, etc.\n\nWhen modified, will automatically be redrawn. Is actually a getter/setter\nso when using this value for calculations and not modifying it,\nuse the `._rotation` property.\n\n`this.rotation = 0` does the same thing as `this.rotation = 360` or `720` or\n`-360` or `36000` etc. So you can keep increasing or decreasing the angle for continuous\nrotation. (Numerical errors do not occur until you get to millions of degrees.)\n\nThe default is to rotate the entity around its (initial) top-left corner; use\n`.origin()` to change that.\n" + "value": "Constructor to initialize the speed and keyBindings. Component will listen to key events and move the entity appropriately.\nCan be called while a key is pressed to change direction & speed on the fly.\n\nMultiway acts by adding a velocity on key press and removing the same velocity when the respective key is released.\nThis works well in most cases, but can cause undesired behavior if you manipulate velocities by yourself while this component is in effect.\nIf you need to resolve collisions, it's advised to correct the position directly rather than to manipulate the velocity. If you still need to reset the velocity once a collision happens, make sure to re-add the previous velocity once the collision is resolved.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nthis.multiway(150, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});\nthis.multiway({x:150,y:75}, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});\nthis.multiway({W: -90, S: 90, D: 0, A: 180});\n```\n" + } + ] }, { "type": "xref", "xrefs": [ - "._attr", - ".origin" + "Motion", + "Keyboard" ] } ], - "name": ".rotation", - "comp": "2D" + "name": ".multiway", + "comp": "Multiway" }, { - "file": "src/2D.js", - "startLine": 156, - "endLine": 159, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 235, + "endLine": 249, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this .speed(Object speed)", + "contents": [ + { + "type": "param", + "name": "speed", + "description": "New speed the entity has, for x and y axis." + } + ] + }, { "type": "raw", - "value": "Transparency of an entity. Must be a decimal value between 0.0 being fully transparent to 1.0 being fully opaque." + "value": "Change the speed that the entity moves with, in units of pixels per second.\n\nCan be called while a key is pressed to change speed on the fly.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nthis.speed({ x: 150, y: 50 });\n```" + } + ] } ], - "name": ".alpha", - "comp": "2D" + "name": ".speed", + "comp": "Multiway" }, { - "file": "src/2D.js", - "startLine": 162, - "endLine": 169, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 312, + "endLine": 323, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this .enableControl()", + "contents": [] + }, { "type": "raw", - "value": "If the entity is visible or not. Accepts a true or false value.\nCan be used for optimization by setting an entities visibility to false when not needed to be drawn.\n\nThe entity will still exist and can be collided with but just won't be drawn." + "value": "Enable the component to listen to key events.\n" }, { - "type": "xref", - "xrefs": [ - "Crafty.DrawManager.draw", - "Crafty.DrawManager.drawAll" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nthis.enableControl();\n```" + } ] } ], - "name": ".visible", - "comp": "2D" + "name": ".enableControl", + "comp": "Multiway" }, { - "file": "src/2D.js", - "startLine": 173, - "endLine": 177, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 333, + "endLine": 344, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this .disableControl()", + "contents": [] + }, { "type": "raw", - "value": "When two entities overlap, the one with the larger `_globalZ` will be on top of the other." + "value": "Disable the component to listen to key events.\n" }, { - "type": "xref", - "xrefs": [ - "Crafty.DrawManager.draw", - "Crafty.DrawManager.drawAll" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nthis.disableControl();\n```" + } ] } ], - "name": "._globalZ", - "comp": "2D" + "name": ".disableControl", + "comp": "Multiway" }, { - "file": "src/2D.js", - "startLine": 361, - "endLine": 376, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 356, + "endLine": 366, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "Extends the MBR of the entity by a specified amount.\n" - }, { "type": "triggers", "events": [ { "type": "trigger", - "event": "BoundaryOffset", - "description": "when the MBR offset changes", - "objName": "Data", - "objProp": null - } - ] - }, - { - "type": "method", - "signature": "public this .offsetBoundary(Number dx1, Number dy1, Number dx2, Number dy2)", - "contents": [ - { - "type": "param", - "name": "dx1", - "description": "Extends the MBR to the left by this amount" - }, - { - "type": "param", - "name": "dy1", - "description": "Extends the MBR upward by this amount" + "event": "NewDirection", + "description": "When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.", + "objName": "New direction", + "objProp": "{ x: -1 | 0 | 1, y: -1 | 0 | 1 }" }, { - "type": "param", - "name": "dx2", - "description": "Extends the MBR to the right by this amount" + "type": "trigger", + "event": "Moved", + "description": "When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.", + "objName": "Old position", + "objProp": "{ axis: 'x' | 'y', oldValue: Number }" }, { - "type": "param", - "name": "dy2", - "description": "Extends the MBR downward by this amount" + "type": "trigger", + "event": "CheckJumping", + "description": "When entity is about to jump. This event is triggered with the object the entity is about to jump from (if it exists). Third parties can respond to this event and enable the entity to jump.", + "objName": "Data", + "objProp": null } ] }, { "type": "raw", - "value": "" + "value": "Make an entity jump in response to key events.\n" }, { - "type": "method", - "signature": "public this .offsetBoundary(Number offset)", + "type": "xref", + "xrefs": [ + "Supportable", + "Motion", + "Keyboard", + "Gravity" + ] + } + ], + "name": "Jumper", + "categories": [ + "Controls" + ] + }, + { + "file": "src/controls/controls.js", + "startLine": 370, + "endLine": 392, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "The canJump function determines if the entity is allowed to jump or not (e.g. perhaps the entity should be able to double jump).\nThe Jumper component will trigger a \"CheckJumping\" event.\nInterested parties can listen to this event and enable the entity to jump by setting `canJump` to true.\n" + }, + { + "type": "example", "contents": [ { - "type": "param", - "name": "offset", - "description": "Extend the MBR in all directions by this amount" + "type": "raw", + "value": "```\nvar player = Crafty.e(\"2D, Jumper\");\nplayer.hasDoubleJumpPowerUp = true; // allow player to double jump by granting him a powerup\nplayer.bind(\"CheckJumping\", function(ground) {\n if (!ground && player.hasDoubleJumpPowerUp) { // allow player to double jump by using up his double jump powerup\n player.canJump = true;\n player.hasDoubleJumpPowerUp = false;\n }\n});\nplayer.bind(\"LandedOnGround\", function(ground) {\n player.hasDoubleJumpPowerUp = true; // give player new double jump powerup upon landing\n});\n```" } ] + } + ], + "name": ".canJump", + "comp": "Jumper" + }, + { + "file": "src/controls/controls.js", + "startLine": 395, + "endLine": 406, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .enableControl()", + "contents": [] }, { "type": "raw", - "value": "\nYou would most likely use this function to ensure that custom canvas rendering beyond the extent of the entity's normal bounds is not clipped." + "value": "Enable the component to listen to key events.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nthis.enableControl();\n```" + } + ] } ], - "name": ".offsetBoundary", - "comp": "2D" + "name": ".enableControl", + "comp": "Jumper" }, { - "file": "src/2D.js", - "startLine": 493, - "endLine": 497, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 408, + "endLine": 419, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Number .area(void)", + "signature": "public this .disableControl()", "contents": [] }, { "type": "raw", - "value": "Calculates the area of the entity" + "value": "Disable the component to listen to key events.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nthis.disableControl();\n```" + } + ] } ], - "name": ".area", - "comp": "2D" + "name": ".disableControl", + "comp": "Jumper" }, { - "file": "src/2D.js", - "startLine": 503, - "endLine": 513, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 445, + "endLine": 463, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Boolean .intersect(Number x, Number y, Number w, Number h)", + "signature": "public this .jumper([Number jumpSpeed,] Array jumpKeys)", "contents": [ { "type": "param", - "name": "x", - "description": "X position of the rect" - }, - { - "type": "param", - "name": "y", - "description": "Y position of the rect" - }, - { - "type": "param", - "name": "w", - "description": "Width of the rect" + "name": "jumpSpeed", + "description": "Vertical jump speed in pixels per second" }, { "type": "param", - "name": "h", - "description": "Height of the rect" + "name": "jumpKeys", + "description": "Keys to listen for and make entity jump in response" } ] }, { - "type": "method", - "signature": "public Boolean .intersect(Object rect)", + "type": "raw", + "value": "Constructor to initialize the power of jump and keys to listen to. Component will\nlisten for key events and move the entity appropriately. Used with the\n`gravity` component will simulate jumping.\n" + }, + { + "type": "example", "contents": [ { - "type": "param", - "name": "rect", - "description": "An object that must have the `x, y, w, h` values as properties" + "type": "raw", + "value": "```\nthis.jumper(300, ['UP_ARROW', 'W']);\nthis.jumper(['UP_ARROW', 'W']);\n```\n" } ] }, { - "type": "raw", - "value": "Determines if this entity intersects a rectangle. If the entity is rotated, its MBR is used for the test." + "type": "xref", + "xrefs": [ + "Supportable", + "Motion", + "Keyboard", + "Gravity" + ] } ], - "name": ".intersect", - "comp": "2D" + "name": ".jumper", + "comp": "Jumper" }, { - "file": "src/2D.js", - "startLine": 532, - "endLine": 542, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 483, + "endLine": 495, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Boolean .within(Number x, Number y, Number w, Number h)", + "signature": "public this .jumpSpeed(Number jumpSpeed)", "contents": [ { "type": "param", - "name": "x", - "description": "X position of the rect" - }, - { - "type": "param", - "name": "y", - "description": "Y position of the rect" - }, - { - "type": "param", - "name": "w", - "description": "Width of the rect" - }, - { - "type": "param", - "name": "h", - "description": "Height of the rect" + "name": "jumpSpeed", + "description": "new vertical jump speed" } ] }, { - "type": "method", - "signature": "public Boolean .within(Object rect)", + "type": "raw", + "value": "Change the vertical jump speed.\n" + }, + { + "type": "example", "contents": [ { - "type": "param", - "name": "rect", - "description": "An object that must have the `_x, _y, _w, _h` values as properties" + "type": "raw", + "value": "```\nthis.jumpSpeed(300);\n```" } ] - }, - { - "type": "raw", - "value": "Determines if this current entity is within another rectangle." } ], - "name": ".within", - "comp": "2D" + "name": ".jumpSpeed", + "comp": "Jumper" }, { - "file": "src/2D.js", - "startLine": 561, - "endLine": 571, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 502, + "endLine": 512, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Boolean .contains(Number x, Number y, Number w, Number h)", - "contents": [ - { - "type": "param", - "name": "x", - "description": "X position of the rect" - }, - { - "type": "param", - "name": "y", - "description": "Y position of the rect" - }, + "type": "triggers", + "events": [ { - "type": "param", - "name": "w", - "description": "Width of the rect" + "type": "trigger", + "event": "NewDirection", + "description": "When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.", + "objName": "New direction", + "objProp": "{ x: -1 | 0 | 1, y: -1 | 0 | 1 }" }, { - "type": "param", - "name": "h", - "description": "Height of the rect" + "type": "trigger", + "event": "Moved", + "description": "When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.", + "objName": "Old position", + "objProp": "{ axis: 'x' | 'y', oldValue: Number }" } ] }, { - "type": "method", - "signature": "public Boolean .contains(Object rect)", - "contents": [ - { - "type": "param", - "name": "rect", - "description": "An object that must have the `_x, _y, _w, _h` values as properties." - } - ] + "type": "raw", + "value": "Move an entity in four directions by using the\narrow keys or `W`, `A`, `S`, `D`.\n" }, { - "type": "raw", - "value": "Determines if the rectangle is within the current entity. If the entity is rotated, its MBR is used for the test." + "type": "xref", + "xrefs": [ + "Multiway" + ] } ], - "name": ".contains", - "comp": "2D" + "name": "Fourway", + "categories": [ + "Controls" + ] }, { - "file": "src/2D.js", - "startLine": 590, - "endLine": 598, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 519, + "endLine": 531, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Object .pos(void)", - "contents": [] + "signature": "public this .fourway([Number speed])", + "contents": [ + { + "type": "param", + "name": "speed", + "description": "The speed of motion in pixels per second." + } + ] }, { "type": "raw", - "value": "Returns the x, y, w, h properties as a rect object\n(a rect object is just an object with the keys _x, _y, _w, _h).\n\nThe keys have an underscore prefix. This is due to the x, y, w, h\nproperties being merely setters and getters that wrap the properties with an underscore (_x, _y, _w, _h)." + "value": "Constructor to initialize the speed. Component will listen for key events and move the entity appropriately.\nThis includes `Up Arrow`, `Right Arrow`, `Down Arrow`, `Left Arrow` as well as `W`, `A`, `S`, `D`.\n\nThe key presses will move the entity in that direction by the speed passed in the argument.\n" + }, + { + "type": "xref", + "xrefs": [ + "Multiway" + ] } ], - "name": ".pos", - "comp": "2D" + "name": ".fourway", + "comp": "Fourway" }, { - "file": "src/2D.js", - "startLine": 609, - "endLine": 614, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 550, + "endLine": 560, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Object .mbr()", - "contents": [] + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "NewDirection", + "description": "When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.", + "objName": "New direction", + "objProp": "{ x: -1 | 0 | 1, y: -1 | 0 | 1 }" + }, + { + "type": "trigger", + "event": "Moved", + "description": "When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.", + "objName": "Old position", + "objProp": "{ axis: 'x' | 'y', oldValue: Number }" + }, + { + "type": "trigger", + "event": "CheckJumping", + "description": "When entity is about to jump. This event is triggered with the object the entity is about to jump from (if it exists). Third parties can respond to this event and enable the entity to jump.", + "objName": "Data", + "objProp": null + } + ] }, { "type": "raw", - "value": "Returns the minimum bounding rectangle. If there is no rotation\non the entity it will return the rect." + "value": "Move an entity left or right using the arrow keys or `D` and `A` and jump using up arrow or `W`.\n" + }, + { + "type": "xref", + "xrefs": [ + "Multiway", + "Jumper" + ] } ], - "name": ".mbr", - "comp": "2D" + "name": "Twoway", + "categories": [ + "Controls" + ] }, { - "file": "src/2D.js", - "startLine": 626, - "endLine": 635, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/controls.js", + "startLine": 567, + "endLine": 583, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Boolean .isAt(Number x, Number y)", + "signature": "public this .twoway([Number speed[, Number jumpSpeed]])", "contents": [ { "type": "param", - "name": "x", - "description": "X position of the point" + "name": "speed", + "description": "A speed in pixels per second" }, { "type": "param", - "name": "y", - "description": "Y position of the point" + "name": "jumpSpeed", + "description": "Vertical jump speed in pixels per second" } ] }, { "type": "raw", - "value": "Determines whether a point is contained by the entity. Unlike other methods,\nan object can't be passed. The arguments require the x and y value.\n\nThe given point is tested against the first of the following that exists: a mapArea associated with \"Mouse\", the hitarea associated with \"Collision\", or the object's MBR." + "value": "Constructor to initialize the speed and power of jump. Component will\nlisten for key events and move the entity appropriately. This includes\n`Up Arrow`, `Right Arrow`, `Left Arrow` as well as `W`, `A`, `D`. Used with the\n`gravity` component to simulate jumping.\n\nThe key presses will move the entity in that direction by the speed passed in\nthe argument. Pressing the `Up Arrow` or `W` will cause the entity to jump.\n" + }, + { + "type": "xref", + "xrefs": [ + "Multiway", + "Jumper" + ] } ], - "name": ".isAt", - "comp": "2D" + "name": ".twoway", + "comp": "Twoway" }, { - "file": "src/2D.js", - "startLine": 648, - "endLine": 654, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/device.js", + "startLine": 5, + "endLine": 10, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this .move(String dir, Number by)", - "contents": [ - { - "type": "param", - "name": "dir", - "description": "Direction to move (n,s,e,w,ne,nw,se,sw)" - }, - { - "type": "param", - "name": "by", - "description": "Amount to move in the specified direction" - } - ] - }, { "type": "raw", - "value": "Quick method to move the entity in a direction (n, s, e, w, ne, nw, se, sw) by an amount of pixels." + "value": "Methods relating to devices such as tablets or phones" } ], - "name": ".move", - "comp": "2D" + "name": "Crafty.device", + "categories": [ + "Misc" + ] }, { - "file": "src/2D.js", - "startLine": 665, - "endLine": 674, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/device.js", + "startLine": 83, + "endLine": 108, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .shift(Number x, Number y, Number w, Number h)", + "signature": "public Crafty.device.deviceOrientation(Function callback)", "contents": [ { "type": "param", - "name": "x", - "description": "Amount to move X" - }, - { - "type": "param", - "name": "y", - "description": "Amount to move Y" - }, - { - "type": "param", - "name": "w", - "description": "Amount to widen" - }, - { - "type": "param", - "name": "h", - "description": "Amount to increase height" + "name": "callback", + "description": "Callback method executed once as soon as device orientation is change" } ] }, { "type": "raw", - "value": "Shift or move the entity by an amount. Use negative values\nfor an opposite direction." - } - ], - "name": ".shift", - "comp": "2D" - }, - { - "file": "src/2D.js", - "startLine": 685, - "endLine": 693, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "value": "Do something with normalized device orientation data:\n```\n{\n tiltLR : 'gamma -- the angle in degrees the device is tilted left-to-right.',\n tiltFB : 'beta -- the angle in degrees the device is tilted front-to-back',\n dir : 'alpha -- the direction the device is facing according to the compass',\n motUD : 'The angle's values increase as you tilt the device to the right or towards you.'\n}\n```\n" + }, { - "type": "method", - "signature": "public void ._cascade(e)", + "type": "example", "contents": [ { - "type": "param", - "name": "e", - "description": "An object describing the motion" + "type": "raw", + "value": "```\n// Get DeviceOrientation event normalized data.\nCrafty.device.deviceOrientation(function(data){\n Crafty.log('data.tiltLR : '+Math.round(data.tiltLR)+', data.tiltFB : '+Math.round(data.tiltFB)+', data.dir : '+Math.round(data.dir)+', data.motUD : '+data.motUD+'');\n});\n```\n\nSee browser support at http://caniuse.com/#search=device orientation." } ] - }, - { - "type": "raw", - "value": "Move or rotate the entity's children according to a certain motion.\nThis method is part of a function bound to \"Move\": It is used\ninternally for ensuring that when a parent moves, the child also\nmoves in the same way." } ], - "name": "._cascade", - "comp": "2D" + "name": "Crafty.device.deviceOrientation", + "comp": "Crafty.device" }, { - "file": "src/2D.js", - "startLine": 721, - "endLine": 736, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/device.js", + "startLine": 122, + "endLine": 148, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .attach(Entity obj[, .., Entity objN])", + "signature": "public Crafty.device.deviceMotion(Function callback)", "contents": [ { "type": "param", - "name": "obj", - "description": "Child entity(s) to attach" + "name": "callback", + "description": "Callback method executed once as soon as device motion is change" } ] }, { "type": "raw", - "value": "Sets one or more entities to be children, with the current entity (`this`)\nas the parent. When the parent moves or rotates, its children move or\nrotate by the same amount. (But not vice-versa: If you move a child, it\nwill not move the parent.) When the parent is destroyed, its children are\ndestroyed.\n\nFor any entity, `this._children` is the array of its children entity\nobjects (if any), and `this._parent` is its parent entity object (if any).\n\nAs many objects as wanted can be attached, and a hierarchy of objects is\npossible by attaching." + "value": "Do something with normalized device motion data:\n```\n{\n acceleration : 'Grab the acceleration including gravity from the results',\n rawAcceleration : 'Display the raw acceleration data',\n facingUp : 'Z is the acceleration in the Z axis, and if the device is facing up or down',\n tiltLR : 'Convert the value from acceleration to degrees. acceleration.x is the acceleration according to gravity, we'll assume we're on Earth and divide by 9.81 (earth gravity) to get a percentage value, and then multiply that by 90 to convert to degrees.',\n tiltFB : 'Convert the value from acceleration to degrees.'\n}\n```\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\n// Get DeviceMotion event normalized data.\nCrafty.device.deviceMotion(function(data){\n Crafty.log('data.moAccel : '+data.rawAcceleration+', data.moCalcTiltLR : '+Math.round(data.tiltLR)+', data.moCalcTiltFB : '+Math.round(data.tiltFB)+'');\n});\n```\n\nSee browser support at http://caniuse.com/#search=motion." + } + ] } ], - "name": ".attach", - "comp": "2D" + "name": "Crafty.device.deviceMotion", + "comp": "Crafty.device" }, { - "file": "src/2D.js", - "startLine": 755, - "endLine": 761, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 12, + "endLine": 29, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this .detach([Entity obj])", + "type": "raw", + "value": "Check which keys (referred by Unicode values) are currently down.\n" + }, + { + "type": "example", "contents": [ { - "type": "param", - "name": "obj", - "description": "The entity to detach. Left blank will remove all attached entities" + "type": "raw", + "value": "```\nCrafty.c(\"Keyboard\", {\n isDown: function (key) {\n if (typeof key === \"string\") {\n key = Crafty.keys[key];\n }\n return !!Crafty.keydown[key];\n }\n});\n```" } ] }, { - "type": "raw", - "value": "Stop an entity from following the current entity. Passing no arguments will stop\nevery entity attached." + "type": "xref", + "xrefs": [ + "Keyboard", + "Crafty.keys" + ] } ], - "name": ".detach", - "comp": "2D" + "name": "Crafty.keydown", + "categories": [ + "Input" + ] }, { - "file": "src/2D.js", - "startLine": 785, - "endLine": 803, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 47, + "endLine": 81, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .origin(Number x, Number y)", + "signature": "public this .multitouch(Boolean bool)", "contents": [ { "type": "param", - "name": "x", - "description": "Pixel value of origin offset on the X axis" - }, - { - "type": "param", - "name": "y", - "description": "Pixel value of origin offset on the Y axis" + "name": "bool", + "description": "Turns multitouch on and off. The initial state is off (false)." } ] }, { "type": "method", - "signature": "public this .origin(String offset)", + "signature": "public Boolean .multitouch()", "contents": [ { - "type": "param", - "name": "offset", - "description": "Combination of center, top, bottom, middle, left and right" + "type": "return", + "value": "Whether multitouch is currently enabled;" } ] }, { "type": "raw", - "value": "Set the origin point of an entity for it to rotate around.\n" + "value": "Enables/disables support for multitouch feature.\n\nIf this is set to true, it is expected that your entities have the Touch component instead of Mouse component.\nIf false (default), then only entities with the Mouse component will respond to touch.\n\nIf no boolean is passed to the function call, it will just return whether multitouch is on or not.\n" + }, + { + "type": "note", + "value": "The Touch component (and thus the multitouch feature) is currently incompatible with the Draggable component." }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nthis.origin(\"top left\")\nthis.origin(\"center\")\nthis.origin(\"bottom right\")\nthis.origin(\"middle right\")\n```\n" + "value": "```\nCrafty.multitouch(true);\n\nvar myEntity1 = Crafty.e('2D, Canvas, Color, Touch')\n .attr({x: 100, y: 100, w:200, h:200, z:1 })\n .color('black')\n .bind('TouchStart',function(e){ alert('big black box was touched', e); }),\n myEntity2 = Crafty.e('2D, Canvas, Color, Touch')\n .attr({x: 40, y: 150, w:90, h:300, z:2 })\n .color('green')\n .bind('TouchStart',function(e){ alert('big GREEN box was touched', e); });\n\nCrafty.log(\"multitouch is \"+Crafty.multitouch());\n```" } ] }, { "type": "xref", "xrefs": [ - ".rotation" + "Crafty.touchDispatch" ] } ], - "name": ".origin", - "comp": "2D" + "name": "Crafty.multitouch", + "categories": [ + "Input" + ] }, { - "file": "src/2D.js", - "startLine": 829, - "endLine": 841, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 100, + "endLine": 131, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "Invalidate", - "description": "when the entity has flipped", - "objName": "Data", - "objProp": null - } - ] + "type": "raw", + "value": "Internal method which dispatches mouse events received by Crafty (crafty.stage.elem).\nThe mouse events get dispatched to the closest entity to the source of the event (if available).\n\nYou can read more about the MouseEvent, which is the parameter passed to the callback.\nhttps://developer.mozilla.org/en-US/docs/Web/API/MouseEvent\n\nThis method also sets a global property Crafty.lastEvent, which holds the most recent event that\noccured (useful for determining mouse position in every frame).\n\n```" }, { - "type": "method", - "signature": "public this .flip(String dir)", + "type": "example", "contents": [ { - "type": "param", - "name": "dir", - "description": "Flip direction" + "type": "raw", + "value": "```\nvar newestX = Crafty.lastEvent.realX,\n newestY = Crafty.lastEvent.realY;\n```\n\nNotable properties of a MouseEvent e:\n```\n//(x,y) coordinates of mouse event in web browser screen space\ne.clientX, e.clientY\n//(x,y) coordinates of mouse event in world/viewport space\ne.realX, e.realY\n// Normalized mouse button according to Crafty.mouseButtons\ne.mouseButton\n```" } ] }, + { + "type": "xref", + "xrefs": [ + "Crafty.touchDispatch", + "Crafty.multitouch" + ] + } + ], + "name": "Crafty.mouseDispatch", + "categories": [ + "Input" + ] + }, + { + "file": "src/controls/inputs.js", + "startLine": 202, + "endLine": 227, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nFlip entity on passed direction\n" + "value": "Internal method which dispatches touch events received by Crafty (crafty.stage.elem).\nThe touch events get dispatched to the closest entity to the source of the event (if available).\n\nBy default, touch events are treated as mouse events. To change this behaviour (and enable multitouch)\nyou must use Crafty.multitouch.\n\nIf using multitouch feature, this method sets the array Crafty.touchHandler.fingers, which holds data\nof the most recent touches that occured (useful for determining positions of fingers in every frame)\nas well as last entity touched by each finger. Data is lost as soon as the finger is raised.\n\nYou can read about the MouseEvent, which is the parameter passed to the Mouse entity's callback.\nhttps://developer.mozilla.org/en-US/docs/Web/API/MouseEvent\n\nYou can also read about the TouchEvent.\nhttps://developer.mozilla.org/en-US/docs/Web/API/TouchEvent\n\nAnd about the touch point interface, which is the parameter passed to the Touch entity's callback.\nhttp://www.w3.org/TR/touch-events/#dfn-active-touch-point\n" }, { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nthis.flip(\"X\")\n```" - } + "type": "xref", + "xrefs": [ + "Crafty.multitouch", + "Crafty.mouseDispatch" ] } ], - "name": ".flip", - "comp": "2D" + "name": "Crafty.touchDispatch", + "categories": [ + "Input" + ] }, { - "file": "src/2D.js", - "startLine": 852, - "endLine": 864, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 395, + "endLine": 422, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "Invalidate", - "description": "when the entity has unflipped", - "objName": "Data", - "objProp": null - } - ] - }, { "type": "method", - "signature": "public this .unflip(String dir)", + "signature": "public this .findClosestEntityByComponent(String comp, Number x, Number y[, Object target])", "contents": [ + { + "type": "raw", + "value": "Finds closest entity with certain component at given coordinates." + }, { "type": "param", - "name": "dir", - "description": "Unflip direction" + "name": "comp", + "description": "Component name" + }, + { + "type": "param", + "name": "x", + "description": "`x` position where to look for entities" + }, + { + "type": "param", + "name": "y", + "description": "`y` position where to look for entities" + }, + { + "type": "param", + "name": "target", + "description": "Target element wherein to look for entities" } ] }, { "type": "raw", - "value": "\nUnflip entity on passed direction (if it's flipped)\n" + "value": "This method is used internally by the .mouseDispatch and .touchDispatch methods, but can be used otherwise for\nCanvas entities.\n\nFinds the top most entity (with the highest z) with a given component at a given point (x, y).\nFor having a detection area specified for the enity, add the AreaMap component to the entity expected to be found.\n\nThe 'target' argument is only meant to be used by .mouseDispatch and touchDispatch; defaults to Crafty.stage.elem,\nthus using this function directly is only worth anything for canvas entities.\n\nReturns the found entity, or undefined if no entity was found.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nthis.unflip(\"X\")\n```" + "value": "```\nvar coords = { x: 455, y: 267 },\n closestText = Crafty.findClosestEntityByComponent(\"Text\", coords.x, coords.y);\n```" } ] } ], - "name": ".unflip", - "comp": "2D" + "name": "Crafty.findClosestEntityByComponent", + "categories": [ + "Input" + ] }, { - "file": "src/2D.js", - "startLine": 887, - "endLine": 891, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 477, + "endLine": 501, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Setter method for all 2D properties including\nx, y, w, h, alpha, rotation and visible." - } - ], - "name": "._attr", - "comp": "2D" - }, - { - "file": "src/2D.js", - "startLine": 958, - "endLine": 963, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "value": "Mouse wheel event triggered by Crafty.\n" + }, { "type": "triggers", "events": [ { "type": "trigger", - "event": "Moved", - "description": "When entity has moved on y-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}", - "objName": "Data", - "objProp": null + "event": "MouseWheelScroll", + "description": "is triggered when mouse is scrolled on stage", + "objName": "Scroll direction (up | down)", + "objProp": "{ direction: +1 | -1}" } ] }, { "type": "raw", - "value": "\nAdds gravitational pull to the entity." - } - ], - "name": "Gravity", - "categories": [ - "2D" - ] - }, - { - "file": "src/2D.js", - "startLine": 975, - "endLine": 992, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "method", - "signature": "public this .gravity([comp])", - "contents": [ - { - "type": "param", - "name": "comp", - "description": "The name of a component that will stop this entity from falling" - } - ] - }, - { - "type": "raw", - "value": "\nEnable gravity for this entity no matter whether comp parameter is not specified,\nIf comp parameter is specified all entities with that component will stop this entity from falling.\nFor a player entity in a platform game this would be a component that is added to all entities\nthat the player should be able to walk on.\n" + "value": "Internal method which dispatches mouse wheel events received by Crafty (crafty.stage.elem).\nThe mouse wheel events get dispatched to Crafty, as well as all entities.\n\nThe native event parameter is passed to the callback.\nYou can read more about the native `mousewheel` event (all browsers except Firefox) https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel\nor the native `DOMMouseScroll` event (Firefox only) https://developer.mozilla.org/en-US/docs/Web/Events/DOMMouseScroll .\n\nNote that the wheel delta properties of the event vary in magnitude across browsers, thus it is recommended to check for `.direction` instead.\nThe `.direction` equals `+1` if wheel was scrolled up, `-1` if wheel was scrolled down.\nSee http://stackoverflow.com/questions/5527601/normalizing-mousewheel-speed-across-browsers .\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Color, Gravity\")\n .color(\"red\")\n .attr({ w: 100, h: 100 })\n .gravity(\"platform\");\n```" + "value": "```\nCrafty.bind(\"MouseWheelScroll\", function(evt) {\n Crafty.viewport.scale(Crafty.viewport._scale * (1 + evt.direction * 0.1));\n});\n```" } ] } ], - "name": ".gravity", - "comp": "Gravity" + "name": "Crafty.mouseWheelDispatch", + "categories": [ + "Input" + ] }, { - "file": "src/2D.js", - "startLine": 1003, - "endLine": 1018, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 507, + "endLine": 533, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this .gravityConst(g)", - "contents": [ + "type": "raw", + "value": "Keyboard Event triggered by Crafty Core" + }, + { + "type": "triggers", + "events": [ { - "type": "param", - "name": "g", - "description": "gravitational constant" + "type": "trigger", + "event": "KeyDown", + "description": "is triggered for each entity when the DOM 'keydown' event is triggered.", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "KeyUp", + "description": "is triggered for each entity when the DOM 'keyup' event is triggered.", + "objName": "Data", + "objProp": null } ] }, - { - "type": "raw", - "value": "\nSet the gravitational constant to g. The default is .2. The greater g, the faster the object falls.\n" - }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Color, Gravity\")\n .color(\"red\")\n .attr({ w: 100, h: 100 })\n .gravity(\"platform\")\n .gravityConst(2)\n```" + "value": "```\nCrafty.e(\"2D, DOM, Color\")\n .attr({x: 100, y: 100, w: 50, h: 50})\n .color(\"red\")\n .bind('KeyDown', function(e) {\n if(e.key == Crafty.keys.LEFT_ARROW) {\n this.x = this.x-1;\n } else if (e.key == Crafty.keys.RIGHT_ARROW) {\n this.x = this.x+1;\n } else if (e.key == Crafty.keys.UP_ARROW) {\n this.y = this.y-1;\n } else if (e.key == Crafty.keys.DOWN_ARROW) {\n this.y = this.y+1;\n }\n });\n```\n" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.keys" + ] } ], - "name": ".gravityConst", - "comp": "Gravity" + "name": "KeyboardEvent", + "categories": [ + "Input" + ] }, { - "file": "src/2D.js", - "startLine": 1079, - "endLine": 1083, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 535, + "endLine": 540, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this .antigravity()", - "contents": [] - }, { "type": "raw", - "value": "Disable gravity for this component. It can be reenabled by calling .gravity()" + "value": "Event Object used in Crafty for cross browser compatibility" } ], - "name": ".antigravity", - "comp": "Gravity" + "name": "Crafty.eventObject", + "categories": [ + "Input" + ] }, { - "file": "src/2D.js", - "startLine": 1090, - "endLine": 1109, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 542, + "endLine": 547, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nPolygon object used for hitboxes and click maps. Must pass an Array for each point as an\nargument where index 0 is the x position and index 1 is the y position.\n\nFor example one point of a polygon will look like this: `[0,5]` where the `x` is `0` and the `y` is `5`.\n\nCan pass an array of the points or simply put each point as an argument.\n\nWhen creating a polygon for an entity, each point should be offset or relative from the entities `x` and `y`\n(don't include the absolute values as it will automatically calculate this).\n\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nnew Crafty.polygon([50,0],[100,100],[0,100]);\nnew Crafty.polygon([[50,0],[100,100],[0,100]]);\n```" - } - ] + "value": "Unicode of the key pressed" } ], - "name": "Crafty.polygon", - "categories": [ - "2D" - ] + "name": ".key", + "comp": "Crafty.eventObject" }, { - "file": "src/2D.js", - "startLine": 1119, - "endLine": 1133, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 645, + "endLine": 692, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Boolean .containsPoint(Number x, Number y)", - "contents": [ + "type": "raw", + "value": "Provides the entity with mouse related events\n" + }, + { + "type": "triggers", + "events": [ { - "type": "param", - "name": "x", - "description": "X position of the point" + "type": "trigger", + "event": "MouseOver", + "description": "when the mouse enters", + "objName": "Data", + "objProp": "MouseEvent" }, { - "type": "param", - "name": "y", - "description": "Y position of the point" + "type": "trigger", + "event": "MouseOut", + "description": "when the mouse leaves", + "objName": "Data", + "objProp": "MouseEvent" + }, + { + "type": "trigger", + "event": "MouseDown", + "description": "when the mouse button is pressed on", + "objName": "Data", + "objProp": "MouseEvent" + }, + { + "type": "trigger", + "event": "MouseUp", + "description": "when the mouse button is released on", + "objName": "Data", + "objProp": "MouseEvent" + }, + { + "type": "trigger", + "event": "Click", + "description": "when the user clicks", + "objName": "Data", + "objProp": "MouseEvent" + }, + { + "type": "trigger", + "event": "DoubleClick", + "description": "when the user double clicks", + "objName": "Data", + "objProp": "MouseEvent" + }, + { + "type": "trigger", + "event": "MouseMove", + "description": "when the mouse is over and moves", + "objName": "Data", + "objProp": "MouseEvent" } ] }, { "type": "raw", - "value": "\nMethod is used to determine if a given point is contained by the polygon.\n" + "value": "If you do not add this component, mouse events will not be triggered on an entity.\n\nYou can read more about the MouseEvent, which is the parameter passed to the callback.\nhttps://developer.mozilla.org/en-US/docs/Web/API/MouseEvent\n\nCrafty will add the mouseButton property to MouseEvents that match one of\n\n- Crafty.mouseButtons.LEFT\n- Crafty.mouseButtons.RIGHT\n- Crafty.mouseButtons.MIDDLE\n" + }, + { + "type": "note", + "value": "If you're targeting mobile, you should know that by default Crafty turns touch events into mouse events, making mouse dependent components work with touch. However, if you need multitouch, you'll have to make use of the Touch component instead, which can break compatibility with things which directly interact with the Mouse component." }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar poly = new Crafty.polygon([50,0],[100,100],[0,100]);\npoly.containsPoint(50, 50); //TRUE\npoly.containsPoint(0, 0); //FALSE\n```" + "value": "```\nvar myEntity = Crafty.e('2D, Canvas, Color, Mouse')\n.attr({x: 10, y: 10, w: 40, h: 40})\n.color('red')\n.bind('Click', function(MouseEvent){\n alert('clicked', MouseEvent);\n});\n\nmyEntity.bind('MouseUp', function(e) {\n if( e.mouseButton == Crafty.mouseButtons.RIGHT )\n Crafty.log(\"Clicked right button\");\n})\n```" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.mouseDispatch", + "Crafty.multitouch", + "Crafty.touchDispatch", + "Crafty.mouseButtons" + ] } ], - "name": ".containsPoint", - "comp": "Crafty.polygon" + "name": "Mouse", + "categories": [ + "Input" + ] }, { - "file": "src/2D.js", - "startLine": 1148, - "endLine": 1162, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 703, + "endLine": 740, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public void .shift(Number x, Number y)", - "contents": [ + "type": "raw", + "value": "Provides the entity with touch related events" + }, + { + "type": "triggers", + "events": [ { - "type": "param", - "name": "x", - "description": "Amount to shift the `x` axis" + "type": "trigger", + "event": "TouchStart", + "description": "when entity is touched", + "objName": "Data", + "objProp": "TouchPoint" }, { - "type": "param", - "name": "y", - "description": "Amount to shift the `y` axis" + "type": "trigger", + "event": "TouchMove", + "description": "when finger is moved over entity", + "objName": "Data", + "objProp": "TouchPoint" + }, + { + "type": "trigger", + "event": "TouchCancel", + "description": "when a touch event has been disrupted in some way", + "objName": "Data", + "objProp": "TouchPoint" + }, + { + "type": "trigger", + "event": "TouchEnd", + "description": "when the finger is raised over the entity, or when finger leaves entity. (Passes no data)", + "objName": "Data", + "objProp": "null" } ] }, { "type": "raw", - "value": "\nShifts every single point in the polygon by the specified amount.\n" + "value": "To be able to use multitouch, you must enable it with `Crafty.multitouch(true)`.\n\nIf you don't need multitouch, you can probably use the Mouse component instead, since by default Crafty will trigger mouse events for touch input.\n\nYou can read more about the TouchEvent.\n- [TouchEvent.touches and TouchEvent.changedTouches](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent)\n- [TouchPoint](http://www.w3.org/TR/touch-events/#dfn-active-touch-point) is the parameter passed to the event callback in the related touch.\n\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar poly = new Crafty.polygon([50,0],[100,100],[0,100]);\npoly.shift(5,5);\n//[[55,5], [105,5], [5,105]];\n```" + "value": "```\nCrafty.multitouch(true);\n\nvar myEntity = Crafty.e('2D, Canvas, Color, Touch')\n.attr({x: 10, y: 10, w: 40, h: 40})\n.color('green')\n.bind('TouchStart', function(TouchPoint){\n Crafty.log('myEntity has been touched', TouchPoint);\n}).bind('TouchMove', function(TouchPoint) {\n Crafty.log('Finger moved over myEntity at the { x: ' + TouchPoint.realX + ', y: ' + TouchPoint.realY + ' } coordinates.');\n}).bind('TouchEnd', function() {\n Crafty.log('Touch over myEntity has finished.');\n});\n```" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.multitouch", + "Crafty.touchDispatch", + "Crafty.mouseDispatch", + "Crafty.mouseButtons" + ] } ], - "name": ".shift", - "comp": "Crafty.polygon" + "name": "Touch", + "categories": [ + "Input" + ] }, { - "file": "src/2D.js", - "startLine": 1192, - "endLine": 1207, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 751, + "endLine": 761, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Circle object used for hitboxes and click maps. Must pass a `x`, a `y` and a `radius` value.\n" + "value": "Component used by Mouse and Touch.\nCan be added to other entities for use with the Crafty.findClosestEntityByComponent method.\n" }, { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nvar centerX = 5,\n centerY = 10,\n radius = 25;\n\nnew Crafty.circle(centerX, centerY, radius);\n```\n\nWhen creating a circle for an entity, each point should be offset or relative from the entities `x` and `y`\n(don't include the absolute values as it will automatically calculate this)." - } + "type": "xref", + "xrefs": [ + "Crafty.mouseDispatch", + "Crafty.touchDispatch", + "Crafty.mouseButtons", + "Crafty.polygon" ] } ], - "name": "Crafty.circle", + "name": "AreaMap", "categories": [ - "2D" + "Input" ] }, { - "file": "src/2D.js", - "startLine": 1225, - "endLine": 1239, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 766, + "endLine": 801, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "NewAreaMap", + "description": "when a new areaMap is assigned", + "objName": "Data", + "objProp": "Crafty.polygon" + } + ] + }, { "type": "method", - "signature": "public Boolean .containsPoint(Number x, Number y)", + "signature": "public this .areaMap(Crafty.polygon polygon)", "contents": [ { "type": "param", - "name": "x", - "description": "X position of the point" - }, + "name": "polygon", + "description": "Instance of Crafty.polygon used to check if the mouse coordinates are inside this region" + } + ] + }, + { + "type": "method", + "signature": "public this .areaMap(Array coordinatePairs)", + "contents": [ { "type": "param", - "name": "y", - "description": "Y position of the point" + "name": "coordinatePairs", + "description": "Array of `x`, `y` coordinate pairs to generate a polygon" + } + ] + }, + { + "type": "method", + "signature": "public this .areaMap(x1, y1,.., xN, yN)", + "contents": [ + { + "type": "param", + "name": "point#", + "description": "List of `x`, `y` coordinate pairs to generate a polygon" } ] }, { "type": "raw", - "value": "\nMethod is used to determine if a given point is contained by the circle.\n" + "value": "Assign a polygon to the entity so that pointer (mouse or touch) events will only be triggered if\nthe coordinates are inside the given polygon.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar circle = new Crafty.circle(0, 0, 10);\ncircle.containsPoint(0, 0); //TRUE\ncircle.containsPoint(50, 50); //FALSE\n```" + "value": "```\nCrafty.e(\"2D, DOM, Color, Mouse\")\n .color(\"red\")\n .attr({ w: 100, h: 100 })\n .bind('MouseOver', function() {Crafty.log(\"over\")})\n .areaMap(0, 0, 50, 0, 50, 50, 0, 50);\n\nCrafty.e(\"2D, Mouse\")\n .areaMap([0, 0, 50, 0, 50, 50, 0, 50]);\n\nCrafty.e(\"2D, Mouse\").areaMap(\n new Crafty.polygon([0, 0, 50, 0, 50, 50, 0, 50])\n);\n```\n" } ] - } - ], - "name": ".containsPoint", - "comp": "Crafty.circle" - }, - { - "file": "src/2D.js", - "startLine": 1250, - "endLine": 1264, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "method", - "signature": "public void .shift(Number x, Number y)", - "contents": [ - { - "type": "param", - "name": "x", - "description": "Amount to shift the `x` axis" - }, - { - "type": "param", - "name": "y", - "description": "Amount to shift the `y` axis" - } - ] - }, - { - "type": "raw", - "value": "\nShifts the circle by the specified amount.\n" }, { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nvar circle = new Crafty.circle(0, 0, 10);\ncircle.shift(5,5);\n//{x: 5, y: 5, radius: 10};\n```" - } + "type": "xref", + "xrefs": [ + "Crafty.polygon" ] } ], - "name": ".shift", - "comp": "Crafty.circle" + "name": ".areaMap", + "comp": "AreaMap" }, { - "file": "src/DOM.js", - "startLine": 4, - "endLine": 7, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 822, + "endLine": 829, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Draws entities as DOM nodes, specifically `
    `s." + "value": "Provides the entity with touch or mouse functionality, depending on whether this is a pc\nor mobile device, and also on multitouch configuration.\n" + }, + { + "type": "xref", + "xrefs": [ + "Crafty.multitouch" + ] } ], - "name": "DOM", + "name": "Button", "categories": [ - "Graphics" + "Input" ] }, { - "file": "src/DOM.js", - "startLine": 10, - "endLine": 13, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "The DOM element used to represent the entity." - } - ], - "name": "._element", - "comp": "DOM" - }, - { - "file": "src/DOM.js", - "startLine": 19, - "endLine": 22, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 837, + "endLine": 846, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Avoids using of CSS 3D Transform for positioning when true. Default value is false." - } - ], - "name": ".avoidCss3dTransforms", - "comp": "DOM" - }, - { - "file": "src/DOM.js", - "startLine": 58, - "endLine": 63, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "method", - "signature": "public this .getId()", - "contents": [] + "value": "Provides the entity with drag and drop mouse events." }, - { - "type": "raw", - "value": "\nGet the Id of the DOM element used to represent the entity." - } - ], - "name": ".getDomId", - "comp": "DOM" - }, - { - "file": "src/DOM.js", - "startLine": 102, - "endLine": 109, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "triggers", "events": [ { "type": "trigger", - "event": "Draw", - "description": "when the entity is ready to be drawn to the stage", + "event": "Dragging", + "description": "is triggered each frame the entity is being dragged", "objName": "Data", - "objProp": "{ style:String, type:\"DOM\", co}" - } - ] - }, - { - "type": "method", - "signature": "public this .DOM(HTMLElement elem)", - "contents": [ + "objProp": "MouseEvent" + }, { - "type": "param", - "name": "elem", - "description": "HTML element that will replace the dynamically created one" + "type": "trigger", + "event": "StartDrag", + "description": "is triggered when dragging begins", + "objName": "Data", + "objProp": "MouseEvent" + }, + { + "type": "trigger", + "event": "StopDrag", + "description": "is triggered when dragging ends", + "objName": "Data", + "objProp": "MouseEvent" } ] }, { - "type": "raw", - "value": "\nPass a DOM element to use rather than one created. Will set `._element` to this value. Removes the old element." + "type": "xref", + "xrefs": [ + "Mouse" + ] } ], - "name": ".DOM", - "comp": "DOM" + "name": "MouseDrag", + "categories": [ + "Input" + ] }, { - "file": "src/DOM.js", - "startLine": 120, - "endLine": 125, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 879, + "endLine": 887, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .draw(void)", + "signature": "public this .startDrag(void)", "contents": [] }, { "type": "raw", - "value": "\nUpdates the CSS properties of the node to draw on the stage." + "value": "Make the entity produce drag events, essentially making the entity follow the mouse positions.\n" + }, + { + "type": "xref", + "xrefs": [ + ".stopDrag" + ] } ], - "name": ".draw", - "comp": "DOM" + "name": ".startDrag", + "comp": "MouseDrag" }, { - "file": "src/DOM.js", - "startLine": 212, - "endLine": 217, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 900, + "endLine": 908, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .undraw(void)", + "signature": "public this .stopDrag(void)", "contents": [] }, { "type": "raw", - "value": "\nRemoves the element from the stage." + "value": "Stop the entity from producing drag events, essentially reproducing the drop.\n" + }, + { + "type": "xref", + "xrefs": [ + ".startDrag" + ] } ], - "name": ".undraw", - "comp": "DOM" + "name": ".stopDrag", + "comp": "MouseDrag" + }, + { + "file": "src/controls/inputs.js", + "startLine": 922, + "endLine": 936, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Give entities keyboard events (`Keydown` and `Keyup`).\n\nIn particular, changes to the key state are broadcasted by `KeyboardEvent`s; interested entities can bind to these events.\n\nThe current state (pressed/released) of a key can also be queried using the `.isDown` method.\n\nAll available key codes are described in `Crafty.keys`.\n" + }, + { + "type": "xref", + "xrefs": [ + "KeyboardEvent", + "Crafty.keys" + ] + } + ], + "name": "Keyboard", + "categories": [ + "Input" + ] }, { - "file": "src/DOM.js", - "startLine": 227, - "endLine": 255, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/inputs.js", + "startLine": 938, + "endLine": 954, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public css(String property, String value)", + "signature": "public Boolean isDown(String keyName)", "contents": [ { "type": "param", - "name": "property", - "description": "CSS property to modify" - }, - { - "type": "param", - "name": "value", - "description": "Value to give the CSS property" + "name": "keyName", + "description": "Name of the key to check. See `Crafty.keys`." } ] }, - { - "type": "raw", - "value": "" - }, { "type": "method", - "signature": "public css(Object map)", + "signature": "public Boolean isDown(Number keyCode)", "contents": [ { "type": "param", - "name": "map", - "description": "Object where the key is the CSS property and the value is CSS value" + "name": "keyCode", + "description": "Key code in `Crafty.keys`." } ] }, { "type": "raw", - "value": "\nApply CSS styles to the element.\n\nCan pass an object where the key is the style property and the value is style value.\n\nFor setting one style, simply pass the style as the first argument and the value as the second.\n\nThe notation can be CSS or JS (e.g. `text-align` or `textAlign`).\n\nTo return a value, pass the property.\n\nNote: For entities with \"Text\" component, some css properties are controlled by separate functions\n`.textFont()` and `.textColor()`, and ignore `.css()` settings. See Text component for details.\n" + "value": "Determine if a certain key is currently down.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nthis.css({'text-align': 'center', 'text-decoration': 'line-through'});\nthis.css(\"textAlign\", \"center\");\nthis.css(\"text-align\"); //returns center\n```" + "value": "```\nentity.requires('Keyboard').bind('KeyDown', function () { if (this.isDown('SPACE')) jump(); });\n```\n" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.keys" + ] } ], - "name": ".css", - "comp": "DOM" + "name": ".isDown", + "comp": "Keyboard" }, { - "file": "src/DOM.js", - "startLine": 290, - "endLine": 294, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/keycodes.js", + "startLine": 5, + "endLine": 103, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nCollection of utilities for using the DOM." + "value": "Object of key names and the corresponding key code.\n\n```\nBACKSPACE: 8,\nTAB: 9,\nENTER: 13,\nPAUSE: 19,\nCAPS: 20,\nESC: 27,\nSPACE: 32,\nPAGE_UP: 33,\nPAGE_DOWN: 34,\nEND: 35,\nHOME: 36,\nLEFT_ARROW: 37,\nUP_ARROW: 38,\nRIGHT_ARROW: 39,\nDOWN_ARROW: 40,\nINSERT: 45,\nDELETE: 46,\n0: 48,\n1: 49,\n2: 50,\n3: 51,\n4: 52,\n5: 53,\n6: 54,\n7: 55,\n8: 56,\n9: 57,\nA: 65,\nB: 66,\nC: 67,\nD: 68,\nE: 69,\nF: 70,\nG: 71,\nH: 72,\nI: 73,\nJ: 74,\nK: 75,\nL: 76,\nM: 77,\nN: 78,\nO: 79,\nP: 80,\nQ: 81,\nR: 82,\nS: 83,\nT: 84,\nU: 85,\nV: 86,\nW: 87,\nX: 88,\nY: 89,\nZ: 90,\nNUMPAD_0: 96,\nNUMPAD_1: 97,\nNUMPAD_2: 98,\nNUMPAD_3: 99,\nNUMPAD_4: 100,\nNUMPAD_5: 101,\nNUMPAD_6: 102,\nNUMPAD_7: 103,\nNUMPAD_8: 104,\nNUMPAD_9: 105,\nMULTIPLY: 106,\nADD: 107,\nSUBSTRACT: 109,\nDECIMAL: 110,\nDIVIDE: 111,\nF1: 112,\nF2: 113,\nF3: 114,\nF4: 115,\nF5: 116,\nF6: 117,\nF7: 118,\nF8: 119,\nF9: 120,\nF10: 121,\nF11: 122,\nF12: 123,\nSHIFT: 16,\nCTRL: 17,\nALT: 18,\nPLUS: 187,\nCOMMA: 188,\nMINUS: 189,\nPERIOD: 190,\nPULT_UP: 29460,\nPULT_DOWN: 29461,\nPULT_LEFT: 4,\nPULT_RIGHT': 5\n```" } ], - "name": "Crafty.DOM", + "name": "Crafty.keys", "categories": [ - "Graphics" + "Input" ] }, { - "file": "src/DOM.js", - "startLine": 297, - "endLine": 302, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/controls/keycodes.js", + "startLine": 199, + "endLine": 210, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nObject with `width` and `height` values representing the width\nand height of the `window`." + "value": "An object mapping mouseButton names to the corresponding button ID.\nIn all mouseEvents, we add the `e.mouseButton` property with a value normalized to match e.button of modern webkit browsers:\n\n```\nLEFT: 0,\nMIDDLE: 1,\nRIGHT: 2\n```" } ], - "name": "Crafty.DOM.window", - "comp": "Crafty.DOM" + "name": "Crafty.mouseButtons", + "categories": [ + "Input" + ] }, { - "file": "src/DOM.js", - "startLine": 347, - "endLine": 355, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/animation.js", + "startLine": 1, + "endLine": 24, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Object Crafty.DOM.inner(HTMLElement obj)", + "type": "raw", + "value": "An object for tracking transitions. Typically used indirectly through \"SpriteAnimation\", \"Tween\", or viewport animations.\n\nIf a method allows you to specify the type of easing, you can do so by providing a custom function or a string corresponding to the name of a built-in method.\n\nBuilt-in easing functions are \"linear\", \"smoothStep\", \"smootherStep\", \"easeInQuad\", \"easeOutQuad\", and \"easeInOutQuad\".\n\nA custom function will be passed a parameter `t` which will vary between 0 and 1, and should return the progress of the animation between 0 and 1." + }, + { + "type": "example", "contents": [ { - "type": "param", - "name": "obj", - "description": "HTML element to calculate the position" - }, - { - "type": "return", - "value": "Object with `x` key being the `x` position, `y` being the `y` position" + "type": "raw", + "value": "Here is how you might use easing functions with the \"Tween\" component.\n```~\nvar e = Crafty.e(\"2D, Tween\");\n// Use built-in easing functions\ne.tween({x:100}, 1000, \"smoothStep\");\ne.tween({y:100}, 1000, \"easeInQuad\");\n// Define a custom easing function: 2t^2 - t\ne.tween({w:0}, 1000, function(t){return 2*t*t - t;});\n```" } ] }, { - "type": "raw", - "value": "\nFind a DOM elements position including\npadding and border." + "type": "xref", + "xrefs": [ + "Tween", + "SpriteAnimation" + ] } ], - "name": "Crafty.DOM.inner", - "comp": "Crafty.DOM" + "name": "Crafty.easing", + "categories": [ + "Animation" + ] }, { - "file": "src/DOM.js", - "startLine": 375, - "endLine": 383, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 3, + "endLine": 51, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "`Crafty` is both an object, and a function for selecting entities.\nIts many methods and properties are discussed individually.\nBelow is the documentation for use as a selector.\n" + }, { "type": "method", - "signature": "public Object Crafty.DOM.getStyle(HTMLElement obj, String property)", + "signature": "public EntitySelection Crafty( String selector)", "contents": [ { "type": "param", - "name": "obj", - "description": "HTML element to find the style" - }, - { - "type": "param", - "name": "property", - "description": "Style to return" + "name": "selector", + "description": "A string representing which entities to select" } ] }, - { - "type": "raw", - "value": "\nDetermine the value of a style on an HTML element. Notation can be\nin either CSS or JS." - } - ], - "name": "Crafty.DOM.getStyle", - "comp": "Crafty.DOM" - }, - { - "file": "src/DOM.js", - "startLine": 414, - "endLine": 425, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public Object Crafty.DOM.translate(Number clientX, Number clientY)", + "signature": "public Entity Crafty( Number selector )", "contents": [ { "type": "param", - "name": "clientX", - "description": "clientX position in the browser screen" - }, - { - "type": "param", - "name": "clientY", - "description": "clientY position in the browser screen" - }, - { - "type": "return", - "value": "Object `{x: ..., y: ...}` with Crafty coordinates." + "name": "selector", + "description": "An entity's id" } ] }, { "type": "raw", - "value": "\nThe parameters clientX and clientY are pixel coordinates within the visible\nbrowser window. This function translates those to Crafty coordinates (i.e.,\nthe coordinates that you might apply to an entity), by taking into account\nwhere the stage is within the screen, what the current viewport is, etc." + "value": "Select a set of or single entities by components or an entity's ID.\n\nCrafty uses syntax similar to jQuery by having a selector engine to select entities by their components.\n\nIf there is more than one match, the return value is an Array-like object listing the ID numbers of each matching entity. If there is exactly one match, the entity itself is returned. If you're not sure how many matches to expect, check the number of matches via Crafty(...).length. Alternatively, use Crafty(...).each(...), which works in all cases.\n" + }, + { + "type": "note", + "value": "You can treat an entity as if it was a selection of length 1 -- it implements all the same methods." + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\n Crafty(\"MyComponent\")\n Crafty(\"Hello 2D Component\")\n Crafty(\"Hello, 2D, Component\")\n```\n\nThe first selector will return all entities that have the component `MyComponent`. The second will return all entities that have `Hello` and `2D` and `Component` whereas the last will return all entities that have at least one of those components (or).\n\n```\n Crafty(\"*\")\n```\nPassing `*` will select all entities.\n\n```\n Crafty(1)\n```\nPassing an integer will select the entity with that `ID`.\n\nTo work directly with an array of entities, use the `get()` method on a selection.\nTo call a function in the context of each entity, use the `.each()` method.\n\nThe event related methods such as `bind` and `trigger` will work on selections of entities.\n" + } + ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty Core#.get", + "Crafty Core#.each" + ] } ], - "name": "Crafty.DOM.translate", - "comp": "Crafty.DOM" + "name": "Crafty", + "categories": [ + "Core" + ] }, { - "file": "src/DebugLayer.js", - "startLine": 4, - "endLine": 15, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 77, + "endLine": 86, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "triggers", "events": [ { "type": "trigger", - "event": "Draw", - "description": "when the entity is ready to be drawn to the stage", - "objName": "Data", - "objProp": null + "event": "NewEntityName", + "description": "After setting new name for entity", + "objName": "entity name", + "objProp": "String" }, { "type": "trigger", - "event": "NoCanvas", - "description": "if the browser does not support canvas", + "event": "NewComponent", + "description": "when a new component is added to the entity", + "objName": "Component", + "objProp": "String" + }, + { + "type": "trigger", + "event": "RemoveComponent", + "description": "when a component is removed from the entity", + "objName": "Component", + "objProp": "String" + }, + { + "type": "trigger", + "event": "Remove", + "description": "when the entity is removed by calling .destroy()", "objName": "Data", "objProp": null } @@ -1521,9895 +1707,11506 @@ }, { "type": "raw", - "value": "\nWhen this component is added to an entity it will be drawn by the DebugCanvas layer.\n\nCrafty.debugCanvas.init() will be automatically called if it is not called already to initialize the canvas element.\n\nTo visualise an object's MBR, use \"VisibleMBR\". To visualise a \"Collision\" object's hitbox, use \"WiredHitBox\" or \"SolidHitBox\"." - }, - { - "type": "xref", - "xrefs": [ - "DebugPolygon", - "DebugRectangle" - ] + "value": "A set of methods added to every single entity." } ], - "name": "DebugCanvas", + "name": "Crafty Core", "categories": [ - "Debug" + "Core" ] }, { - "file": "src/DebugLayer.js", - "startLine": 43, - "endLine": 47, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 190, + "endLine": 200, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public .debugAlpha(Number alpha)", + "signature": "public this .setName(String name)", "contents": [ { "type": "param", - "name": "alpha", - "description": "The alpha level the component will be drawn with" + "name": "name", + "description": "A human readable name for debugging purposes." + } + ] + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nthis.setName(\"Player\");\n```" } ] } ], - "name": ".debugAlpha", - "comp": "DebugCanvas" + "name": ".setName", + "comp": "Crafty Core" }, { - "file": "src/DebugLayer.js", - "startLine": 54, - "endLine": 62, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 210, + "endLine": 237, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public .debugFill([String fillStyle])", + "signature": "public this .addComponent(String componentList)", "contents": [ { "type": "param", - "name": "fillStyle", - "description": "The color the component will be filled with. Defaults to \"red\". Pass the boolean false to turn off filling." + "name": "componentList", + "description": "A string of components to add separated by a comma `,`" + } + ] + }, + { + "type": "method", + "signature": "public this .addComponent(String Component1[, .., String ComponentN])", + "contents": [ + { + "type": "param", + "name": "Component#", + "description": "Component ID to add." } ] }, + { + "type": "raw", + "value": "Adds a component to the selected entities or entity.\n\nComponents are used to extend the functionality of entities.\nThis means it will copy properties and assign methods to\naugment the functionality of the entity.\n\nFor adding multiple components, you can either pass a string with\nall the component names (separated by commas), or pass each component name as\nan argument.\n\nIf the component has a function named `init` it will be called.\n\nIf the entity already has the component, the component is skipped (nothing happens).\n" + }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar myEntity = Crafty.e(\"2D, Collision, SolidHitBox \").debugFill(\"purple\")\n```" + "value": "```\nthis.addComponent(\"2D, Canvas\");\nthis.addComponent(\"2D\", \"Canvas\");\n```" } ] } ], - "name": ".debugFill", - "comp": "DebugCanvas" + "name": ".addComponent", + "comp": "Crafty Core" }, { - "file": "src/DebugLayer.js", - "startLine": 71, - "endLine": 79, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 281, + "endLine": 304, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public .debugStroke([String strokeStyle])", + "signature": "public this .toggleComponent(String ComponentList)", "contents": [ { "type": "param", - "name": "strokeStyle", - "description": "The color the component will be outlined with. Defaults to \"red\". Pass the boolean false to turn this off." + "name": "ComponentList", + "description": "A string of components to add or remove separated by a comma `,`" + } + ] + }, + { + "type": "method", + "signature": "public this .toggleComponent(String Component1[, .., String componentN])", + "contents": [ + { + "type": "param", + "name": "Component#", + "description": "Component ID to add or remove." } ] }, + { + "type": "raw", + "value": "Add or Remove Components from an entity.\n" + }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar myEntity = Crafty.e(\"2D, Collision, WiredHitBox \").debugStroke(\"white\")\n```" + "value": "```\nvar e = Crafty.e(\"2D,DOM,Test\");\ne.toggleComponent(\"Test,Test2\"); //Remove Test, add Test2\ne.toggleComponent(\"Test,Test2\"); //Add Test, remove Test2\n```\n\n```\nvar e = Crafty.e(\"2D,DOM,Test\");\ne.toggleComponent(\"Test\",\"Test2\"); //Remove Test, add Test2\ne.toggleComponent(\"Test\",\"Test2\"); //Add Test, remove Test2\ne.toggleComponent(\"Test\"); //Remove Test\n```" } ] } ], - "name": ".debugStroke", - "comp": "DebugCanvas" + "name": ".toggleComponent", + "comp": "Crafty Core" }, { - "file": "src/DebugLayer.js", - "startLine": 115, - "endLine": 128, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 342, + "endLine": 358, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this .requires(String componentList)", + "contents": [ + { + "type": "param", + "name": "componentList", + "description": "List of components that must be added" + } + ] + }, { "type": "raw", - "value": "\nA component for rendering an object with a position and dimensions to the debug canvas.\n\n\n```\nvar myEntity = Crafty.e(\"2D, DebugRectangle\")\n .attr({x: 13, y: 37, w: 42, h: 42})\n .debugStroke(\"green\");\nmyEntity.debugRectangle(myEntity)\n```" + "value": "Makes sure the entity has the components listed. If the entity does not\nhave the component, it will add it.\n\n(In the current version of Crafty, this function behaves exactly the same\nas `addComponent`. By convention, developers have used `requires` for\ncomponent dependencies -- i.e. to indicate specifically that one component\nwill only work properly if another component is present -- and used\n`addComponent` in all other situations.)\n" }, { "type": "xref", "xrefs": [ - "DebugCanvas" + ".addComponent" ] } ], - "name": "DebugRectangle", - "categories": [ - "Debug" - ] + "name": ".requires", + "comp": "Crafty Core" }, { - "file": "src/DebugLayer.js", - "startLine": 135, - "endLine": 141, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 363, + "endLine": 380, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public .debugRectangle(Object rect)", + "signature": "public this .removeComponent(String Component[, soft])", "contents": [ { "type": "param", - "name": "rect", - "description": "an object with _x, _y, _w, and _h to draw" + "name": "component", + "description": "Component to remove" + }, + { + "type": "param", + "name": "soft", + "description": "Whether to soft remove it (defaults to `true`)" } ] }, { "type": "raw", - "value": "Sets the rectangle that this component draws to the debug canvas.\n" - } - ], - "name": ".debugRectangle", - "comp": "DebugRectangle" - }, - { - "file": "src/DebugLayer.js", - "startLine": 172, - "endLine": 179, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nAdding this component to an entity will cause it's MBR to be drawn to the debug canvas.\n\nThe methods of DebugCanvas can be used to control this component's appearance." + "value": "Removes a component from an entity. A soft remove (the default) will only\nrefrain `.has()` from returning true. Hard will remove all\nassociated properties and methods.\n" }, { - "type": "xref", - "xrefs": [ - "2D", - "DebugRectangle", - "DebugCanvas" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar e = Crafty.e(\"2D,DOM,Test\");\ne.removeComponent(\"Test\"); //Soft remove Test component\ne.removeComponent(\"Test\", false); //Hard remove Test component\n```" + } ] } ], - "name": "VisibleMBR", - "categories": [ - "Debug" - ] + "name": ".removeComponent", + "comp": "Crafty Core" }, { - "file": "src/DebugLayer.js", - "startLine": 201, - "endLine": 211, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 405, + "endLine": 420, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public Number .getId(void)", + "contents": [ + { + "type": "return", + "value": "the ID of this entity." + } + ] + }, { "type": "raw", - "value": "\nFor drawing a polygon to the debug canvas\n\nThe methods of DebugCanvas can be used to control this component's appearance -- by default it is neither filled nor outlined\n\nFor debugging hitboxes, use WiredHitBox or SolidHitBox. For debugging MBR, use VisibleMBR\n" + "value": "For better performance, simply use the this[0] property.\n" }, { - "type": "xref", - "xrefs": [ - "DebugCanvas" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Finding out the `ID` of an entity can be done by returning the property `0`.\n```\n var ent = Crafty.e(\"2D\");\n ent[0]; //ID\n ent.getId(); //also ID\n```" + } ] } ], - "name": "DebugPolygon", - "categories": [ - "Debug" - ] + "name": ".getId", + "comp": "Crafty Core" }, { - "file": "src/DebugLayer.js", - "startLine": 219, - "endLine": 225, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 425, + "endLine": 436, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public .debugPolygon(Polygon poly)", + "signature": "public Boolean .has(String component)", "contents": [ { "type": "param", - "name": "poly", - "description": "a polygon to render" + "name": "component", + "description": "The name of the component to check" + }, + { + "type": "return", + "value": "`true` or `false` depending on if the entity has the given component." } ] }, { "type": "raw", - "value": "Sets the polygon that this component renders to the debug canvas.\n" + "value": "For better performance, simply use the `.__c` object\nwhich will be `true` if the entity has the component or\nwill not exist (or be `false`)." } ], - "name": ".debugPolygon", - "comp": "DebugPolygon" + "name": ".has", + "comp": "Crafty Core" }, { - "file": "src/DebugLayer.js", - "startLine": 253, - "endLine": 260, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 441, + "endLine": 488, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "\nAdding this component to an entity with a Collision component will cause its collision polygon to be drawn to the debug canvas as an outline\n\nThe methods of DebugCanvas can be used to control this component's appearance." + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Change", + "description": "when properties change", + "objName": "Data", + "objProp": "{key: value}" + } + ] }, - { - "type": "xref", - "xrefs": [ - "DebugPolygon", - "DebugCanvas" - ] - } - ], - "name": "WiredHitBox", - "categories": [ - "Debug" - ] - }, - { - "file": "src/DebugLayer.js", - "startLine": 274, - "endLine": 281, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nAdding this component to an entity with a Collision component will cause its collision polygon to be drawn to the debug canvas, with a default alpha level of 0.7.\n\nThe methods of DebugCanvas can be used to control this component's appearance." - }, - { - "type": "xref", - "xrefs": [ - "DebugPolygon", - "DebugCanvas" - ] - } - ], - "name": "SolidHitBox", - "categories": [ - "Debug" - ] - }, - { - "file": "src/HashMap.js", - "startLine": 10, - "endLine": 17, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public void Crafty.HashMap([cellsize])", + "signature": "public this .attr(String property, Any value[, Boolean silent[, Boolean recursive]])", "contents": [ { "type": "param", - "name": "cellsize", - "description": "the cell size. If omitted, `cellsize` is 64." - } - ] - }, - { - "type": "raw", - "value": "\nSet `cellsize`.\nAnd create `this.map`." - } - ], - "name": "Crafty.HashMap.constructor", - "comp": "Crafty.HashMap" - }, - { - "file": "src/HashMap.js", - "startLine": 30, - "endLine": 41, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "method", - "signature": "public Object Crafty.map.insert(Object obj)", - "contents": [ + "name": "property", + "description": "Property of the entity to modify" + }, { "type": "param", - "name": "obj", - "description": "An entity to be inserted." - } - ] - }, - { - "type": "raw", - "value": "\n`obj` is inserted in '.map' of the corresponding broad phase cells. An object of the following fields is returned.\n```\n- the object that keep track of cells (keys)\n- `obj`\n- the HashMap object\n```" - } - ], - "name": "Crafty.map.insert", - "comp": "Crafty.map" - }, - { - "file": "src/HashMap.js", - "startLine": 63, - "endLine": 72, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "method", - "signature": "public Object Crafty.map.search(Object rect[, Boolean filter])", - "contents": [ + "name": "value", + "description": "Value to set the property to" + }, { "type": "param", - "name": "rect", - "description": "the rectangular region to search for entities." + "name": "silent", + "description": "If you would like to supress events" }, { "type": "param", - "name": "filter", - "description": "Default value is true. Otherwise, must be false." + "name": "recursive", + "description": "If you would like merge recursively" } ] }, { "type": "raw", - "value": "\n- If `filter` is `false`, just search for all the entries in the give `rect` region by broad phase collision. Entity may be returned duplicated.\n- If `filter` is `true`, filter the above results by checking that they actually overlap `rect`.\nThe easier usage is with `filter`=`true`. For performance reason, you may use `filter`=`false`, and filter the result yourself. See examples in drawing.js and collision.js" - } - ], - "name": "Crafty.map.search", - "comp": "Crafty.map" - }, - { - "file": "src/HashMap.js", - "startLine": 118, - "endLine": 131, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "value": "Use this method to set any property of the entity.\n" + }, { "type": "method", - "signature": "public void Crafty.map.remove([Object keys, ]Object obj)", + "signature": "public this .attr(Object map[, Boolean silent[, Boolean recursive]])", "contents": [ { "type": "param", - "name": "keys", - "description": "key region. If omitted, it will be derived from obj by `Crafty.HashMap.key`." + "name": "map", + "description": "Object where each key is the property to modify and the value as the property value" }, { "type": "param", - "name": "obj", - "description": "need more document." + "name": "silent", + "description": "If you would like to supress events" + }, + { + "type": "param", + "name": "recursive", + "description": "If you would like merge recursively" } ] }, { "type": "raw", - "value": "\nRemove an entity in a broad phase map.\n- The second form is only used in Crafty.HashMap to save time for computing keys again, where keys were computed previously from obj. End users should not call this form directly.\n" + "value": "Use this method to set multiple properties of the entity.\n\nSetter options:\n- `silent`: If you want to prevent it from firing events.\n- `recursive`: If you pass in an object you could overwrite sibling keys, this recursively merges instead of just merging it. This is `false` by default, unless you are using dot notation `name.first`.\n" }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.map.remove(e);\n```" - } - ] - } - ], - "name": "Crafty.map.remove", - "comp": "Crafty.map" - }, - { - "file": "src/HashMap.js", - "startLine": 160, - "endLine": 171, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public void Crafty.map.remove(Entry entry)", + "signature": "public Any .attr(String property)", "contents": [ { "type": "param", - "name": "entry", - "description": "An entry to update" + "name": "property", + "description": "Property of the entity to modify" + }, + { + "type": "return", + "value": "Value - the value of the property" } ] }, { "type": "raw", - "value": "\nRefresh an entry's keys, and its position in the broad phrase map.\n" + "value": "Use this method to get any property of the entity. You can also retrieve the property using `this.property`.\n\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.map.refresh(e);\n```" + "value": "```\nthis.attr({key: \"value\", prop: 5});\nthis.attr(\"key\"); // returns \"value\"\nthis.attr(\"prop\"); // returns 5\nthis.key; // \"value\"\nthis.prop; // 5\n\nthis.attr(\"key\", \"newvalue\");\nthis.attr(\"key\"); // returns \"newvalue\"\nthis.key; // \"newvalue\"\n\nthis.attr(\"parent.child\", \"newvalue\");\nthis.parent; // {child: \"newvalue\"};\nthis.attr('parent.child'); // \"newvalue\"\n```" } ] } ], - "name": "Crafty.map.refresh", - "comp": "Crafty.map" + "name": ".attr", + "comp": "Crafty Core" }, { - "file": "src/HashMap.js", - "startLine": 210, - "endLine": 227, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 600, + "endLine": 607, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Object Crafty.map.boundaries()", + "signature": "public this .toArray(void)", "contents": [] }, { "type": "raw", - "value": "\nThe return `Object` is of the following format.\n```\n{\n min: {\n x: val_x,\n y: val_y\n },\n max: {\n x: val_x,\n y: val_y\n }\n}\n```" - } - ], - "name": "Crafty.map.boundaries", - "comp": "Crafty.map" - }, - { - "file": "src/HashMap.js", - "startLine": 305, - "endLine": 312, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "Broad-phase collision detection engine. See background information at\n\n- [N Tutorial B - Broad-Phase Collision](http://www.metanetsoftware.com/technique/tutorialB.html)\n- [Broad-Phase Collision Detection with CUDA](http.developer.nvidia.com/GPUGems3/gpugems3_ch32.html)" + "value": "This method will simply return the found entities as an array of ids. To get an array of the actual entities, use `get()`." }, { "type": "xref", "xrefs": [ - "Crafty.map" + ".get" ] } ], - "name": "Crafty.HashMap", - "categories": [ - "2D" - ] + "name": ".toArray", + "comp": "Crafty Core" }, { - "file": "src/HashMap.js", - "startLine": 315, - "endLine": 323, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 612, + "endLine": 630, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Object Crafty.HashMap.key(Object obj)", + "signature": "public this .timeout(Function callback, Number delay)", "contents": [ { "type": "param", - "name": "obj", - "description": "an Object that has .mbr() or _x, _y, _w and _h." + "name": "callback", + "description": "Method to execute after given amount of milliseconds" + }, + { + "type": "param", + "name": "delay", + "description": "Amount of milliseconds to execute the method" } ] }, { "type": "raw", - "value": "Get the rectangular region (in terms of the grid, with grid size `cellsize`), where the object may fall in. This region is determined by the object's bounding box.\nThe `cellsize` is 64 by default.\n" + "value": "The delay method will execute a function after a given amount of time in milliseconds.\n\nEssentially a wrapper for `setTimeout`.\n" }, { - "type": "xref", - "xrefs": [ - "Crafty.HashMap.constructor" - ] - } - ], - "name": "Crafty.HashMap.key", - "comp": "Crafty.HashMap" - }, - { - "file": "src/animation.js", - "startLine": 81, - "endLine": 86, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "triggers", - "events": [ + "type": "example", + "contents": [ { - "type": "trigger", - "event": "TweenEnd", - "description": "when a tween finishes", - "objName": "property", - "objProp": "String" + "type": "raw", + "value": "Destroy itself after 100 milliseconds\n```\nthis.timeout(function() {\nthis.destroy();\n}, 100);\n```" } ] - }, - { - "type": "raw", - "value": "\nComponent to animate the change in 2D properties over time." } ], - "name": "Tween", - "categories": [ - "Animation" - ] + "name": ".timeout", + "comp": "Crafty Core" }, { - "file": "src/animation.js", - "startLine": 120, - "endLine": 147, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 641, + "endLine": 675, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .tween(Object properties, Number|String duration)", + "signature": "public this .bind(String eventName, Function callback)", "contents": [ { "type": "param", - "name": "properties", - "description": "Object of numeric properties and what they should animate to" + "name": "eventName", + "description": "Name of the event to bind to" }, { "type": "param", - "name": "duration", - "description": "Duration to animate the properties over, in milliseconds." + "name": "callback", + "description": "Method to execute when the event is triggered" } ] }, { "type": "raw", - "value": "\nThis method will animate numeric properties over the specified duration.\nThese include `x`, `y`, `w`, `h`, `alpha` and `rotation`.\n\nThe object passed should have the properties as keys and the value should be the resulting\nvalues of the properties. The passed object might be modified if later calls to tween animate the same properties.\n" + "value": "Attach the current entity (or entities) to listen for an event.\n\nCallback will be invoked when an event with the event name passed\nis triggered. Depending on the event, some data may be passed\nvia an argument to the callback function.\n\nThe first argument is the event name (can be anything) whilst the\nsecond argument is the callback. If the event has data, the\ncallback should have an argument.\n\nEvents are arbitrary and provide communication between components.\nYou can trigger or bind an event even if it doesn't exist yet.\n\nUnlike DOM events, Crafty events are executed synchronously.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "Move an object to 100,100 and fade out over 200 ms.\n```\nCrafty.e(\"2D, Tween\")\n .attr({alpha: 1.0, x: 0, y: 0})\n .tween({alpha: 0.0, x: 100, y: 100}, 200)\n```" + "value": "```\nthis.attr(\"triggers\", 0); //set a trigger count\nthis.bind(\"myevent\", function() {\n this.triggers++; //whenever myevent is triggered, increment\n});\nthis.bind(\"EnterFrame\", function() {\n this.trigger(\"myevent\"); //trigger myevent on every frame\n});\n```\n" } ] }, { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "Rotate an object over 2 seconds\n```\nCrafty.e(\"2D, Tween\")\n .attr({rotation:0})\n .tween({rotation:180}, 2000)\n```\n" - } + "type": "xref", + "xrefs": [ + ".trigger", + ".unbind" ] } ], - "name": ".tween", - "comp": "Tween" + "name": ".bind", + "comp": "Crafty Core" }, { - "file": "src/animation.js", - "startLine": 172, - "endLine": 182, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 692, + "endLine": 703, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .cancelTween(String target)", + "signature": "public Number .uniqueBind(String eventName, Function callback)", "contents": [ { "type": "param", - "name": "target", - "description": "The property to cancel" + "name": "eventName", + "description": "Name of the event to bind to" + }, + { + "type": "param", + "name": "callback", + "description": "Method to execute upon event triggered" + }, + { + "type": "return", + "value": "ID of the current callback used to unbind" } ] }, { "type": "raw", - "value": "" + "value": "Works like Crafty.bind, but prevents a callback from being bound multiple times.\n" }, { - "type": "method", - "signature": "public this .cancelTween(Object target)", - "contents": [ - { - "type": "param", - "name": "target", - "description": "An object containing the properties to cancel." - } + "type": "xref", + "xrefs": [ + ".bind" ] - }, - { - "type": "raw", - "value": "\nStops tweening the specified property or properties.\nPassing the object used to start the tween might be a typical use of the second signature." } ], - "name": ".cancelTween", - "comp": "Tween" + "name": ".uniqueBind", + "comp": "Crafty Core" }, { - "file": "src/canvas.js", - "startLine": 4, - "endLine": 19, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 710, + "endLine": 721, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ + "type": "method", + "signature": "public Number one(String eventName, Function callback)", + "contents": [ { - "type": "trigger", - "event": "Draw", - "description": "when the entity is ready to be drawn to the stage", - "objName": "Data", - "objProp": "{type: \"canvas\", pos, co, ctx}" + "type": "param", + "name": "eventName", + "description": "Name of the event to bind to" }, { - "type": "trigger", - "event": "NoCanvas", - "description": "if the browser does not support canvas", - "objName": "Data", - "objProp": null + "type": "param", + "name": "callback", + "description": "Method to execute upon event triggered" + }, + { + "type": "return", + "value": "ID of the current callback used to unbind" } ] }, { "type": "raw", - "value": "\nWhen this component is added to an entity it will be drawn to the global canvas element. The canvas element (and hence all Canvas entities) is always rendered below any DOM entities.\n\nCrafty.canvas.init() will be automatically called if it is not called already to initialize the canvas element.\n\nCreate a canvas entity like this\n```\nvar myEntity = Crafty.e(\"2D, Canvas, Color\")\n .color(\"green\")\n .attr({x: 13, y: 37, w: 42, h: 42});\n```" + "value": "Works like Crafty.bind, but will be unbound once the event triggers.\n" + }, + { + "type": "xref", + "xrefs": [ + ".bind" + ] } ], - "name": "Canvas", - "categories": [ - "Graphics" - ] + "name": ".one", + "comp": "Crafty Core" }, { - "file": "src/canvas.js", - "startLine": 52, - "endLine": 62, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 732, + "endLine": 745, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .draw([[Context ctx, ]Number x, Number y, Number w, Number h])", + "signature": "public this .unbind(String eventName[, Function callback])", "contents": [ { "type": "param", - "name": "ctx", - "description": "Canvas 2D context if drawing on another canvas is required" - }, - { - "type": "param", - "name": "x", - "description": "X offset for drawing a segment" - }, - { - "type": "param", - "name": "y", - "description": "Y offset for drawing a segment" - }, - { - "type": "param", - "name": "w", - "description": "Width of the segment to draw" + "name": "eventName", + "description": "Name of the event to unbind" }, { "type": "param", - "name": "h", - "description": "Height of the segment to draw" + "name": "callback", + "description": "Function to unbind" } ] }, { "type": "raw", - "value": "\nMethod to draw the entity on the canvas element. Can pass rect values for redrawing a segment of the entity." - } - ], - "name": ".draw", - "comp": "Canvas" - }, - { - "file": "src/canvas.js", - "startLine": 148, - "endLine": 152, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nCollection of methods to draw on canvas." - } - ], - "name": "Crafty.canvas", - "categories": [ - "Graphics" - ] - }, - { - "file": "src/canvas.js", - "startLine": 156, - "endLine": 161, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nThis will return the 2D context of the main canvas element.\nThe value returned from `Crafty.canvas._canvas.getContext('2d')`." - } - ], - "name": "Crafty.canvas.context", - "comp": "Crafty.canvas" - }, - { - "file": "src/canvas.js", - "startLine": 164, - "endLine": 168, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "value": "Removes binding with an event from current entity.\n\nPassing an event name will remove all events bound to\nthat event. Passing a reference to the callback will\nunbind only that callback." + }, { - "type": "raw", - "value": "\nMain Canvas element" + "type": "xref", + "xrefs": [ + ".bind", + ".trigger" + ] } ], - "name": "Crafty.canvas._canvas", - "comp": "Crafty.canvas" + "name": ".unbind", + "comp": "Crafty Core" }, { - "file": "src/canvas.js", - "startLine": 171, - "endLine": 181, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 758, + "endLine": 774, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.canvas.init(void)", - "contents": [] - }, - { - "type": "triggers", - "events": [ + "signature": "public this .trigger(String eventName[, Object data])", + "contents": [ { - "type": "trigger", - "event": "NoCanvas", - "description": "triggered if `Crafty.support.canvas` is false", - "objName": "Data", - "objProp": null + "type": "param", + "name": "eventName", + "description": "Event to trigger" + }, + { + "type": "param", + "name": "data", + "description": "Arbitrary data that will be passed into every callback as an argument" } ] }, { "type": "raw", - "value": "\nCreates a `canvas` element inside `Crafty.stage.elem`. Must be called\nbefore any entities with the Canvas component can be drawn.\n\nThis method will automatically be called if no `Crafty.canvas.context` is\nfound." + "value": "Trigger an event with arbitrary data. Will invoke all callbacks with\nthe context (value of `this`) of the current entity object.\n\n*Note: This will only execute callbacks within the current entity, no other entity.*\n\nThe first argument is the event name to trigger and the optional\nsecond argument is the arbitrary event data. This can be absolutely anything.\n\nUnlike DOM events, Crafty events are exectued synchronously." } ], - "name": "Crafty.canvas.init", - "comp": "Crafty.canvas" + "name": ".trigger", + "comp": "Crafty Core" }, { - "file": "src/collision.js", - "startLine": 5, - "endLine": 23, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 791, + "endLine": 812, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "HitOn", - "description": "Triggered when collisions occur. Will not trigger again until collisions of this type cease, or an event is requested once more (using `resetHitChecks(component)`).", - "objName": "Data", - "objProp": "{ hitData }" - }, + "type": "method", + "signature": "public this .each(Function method)", + "contents": [ { - "type": "trigger", - "event": "HitOff", - "description": "Triggered when collision with a specific component type ceases", - "objName": "Data", - "objProp": "{ componentName }" + "type": "param", + "name": "method", + "description": "Method to call on each iteration" } ] }, { "type": "raw", - "value": "\nComponent to detect collision between any two convex polygons.\n\nIf collision checks are registered for multiple component and collisions with\nmultiple types occur simultaniously, each collision will cause an individual\nevent to fire.\n\n**Note:** All data received from events is only valid for the duration of the event's callback.\nIf you wish to preserve the data, make a copy of it.\n\nFor a description of collision event data (hitData above), see the documentation for\n`.hit()`.\n" + "value": "Iterates over found entities, calling a function for every entity.\n\nThe function will be called for every entity and will pass the index\nin the iteration as an argument. The context (value of `this`) of the\nfunction will be the current entity in the iteration.\n" }, { - "type": "xref", - "xrefs": [ - ".hit", - ".checkHits", - ".onHit" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Destroy every second 2D entity\n```\nCrafty(\"2D\").each(function(i) {\n if(i % 2 === 0) {\n this.destroy();\n }\n});\n```" + } ] } ], - "name": "Collision", - "categories": [ - "2D" - ] - }, - { - "file": "src/collision.js", - "startLine": 26, - "endLine": 34, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "Set up collision handling.\n\nBy default, the collision hitbox will match the dimensions (x, y, w, h) and rotation of the object.\n\n**Note:** If the entity this component is applied to does not have its\ndimensions set the default hit area will not be set properly." - } - ], - "name": ".init", - "comp": "Collision" + "name": ".each", + "comp": "Crafty Core" }, { - "file": "src/collision.js", - "startLine": 51, - "endLine": 81, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 824, + "endLine": 850, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "" - }, - { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "NewHitbox", - "description": "when a new hitbox is assigned", - "objName": "Data", - "objProp": "Crafty.polygon" - } - ] - }, - { - "type": "raw", - "value": "" - }, { "type": "method", - "signature": "public this .collision([Crafty.polygon polygon])", + "signature": "public Array .get()", "contents": [ { - "type": "param", - "name": "polygon", - "description": "Crafty.polygon object that will act as the hit area." + "type": "return", + "value": "An array of entities corresponding to the active selector" } ] }, - { - "type": "raw", - "value": "" - }, { "type": "method", - "signature": "public this .collision(Array point1, .., Array pointN)", + "signature": "public Entity .get(Number index)", "contents": [ + { + "type": "return", + "value": "an entity belonging to the current selection" + }, { "type": "param", - "name": "point#", - "description": "Array of [x, y] coordinate pairs to generate a hit area polygon." + "name": "index", + "description": "The index of the entity to return. If negative, counts back from the end of the array." } ] }, - { - "type": "raw", - "value": "\nConstructor that takes a polygon or array of points to use as the hit area,\nwith points being relative to the object's position in its unrotated state.\n\nThe hit area must be a convex shape and not concave for collision detection to work properly.\n\nIf no parameter is passed, the x, y, w, h properties of the entity will be used, and the hitbox will be resized when the entity is.\n\nIf a hitbox is set that is outside of the bounds of the entity itself, there will be a small performance penalty as it is tracked separately.\n" - }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.e(\"2D, Collision\").collision(\n new Crafty.polygon([50,0], [100,100], [0,100])\n);\n\nCrafty.e(\"2D, Collision\").collision([50,0], [100,100], [0,100]);\n```\n" + "value": "Get an array containing every \"2D\" entity\n```\nvar arr = Crafty(\"2D\").get()\n```\nGet the first entity matching the selector\n```\n// equivalent to Crafty(\"2D\").get()[0], but doesn't create a new array\nvar e = Crafty(\"2D\").get(0)\n```\nGet the last \"2D\" entity matching the selector\n```\nvar e = Crafty(\"2D\").get(-1)\n```\n" } ] - }, - { - "type": "xref", - "xrefs": [ - "Crafty.polygon" - ] } ], - "name": ".collision", - "comp": "Collision" + "name": ".get", + "comp": "Crafty Core" }, { - "file": "src/collision.js", - "startLine": 226, - "endLine": 257, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 871, + "endLine": 879, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Boolean/Array hit(String component)", + "signature": "public Entity .clone(void)", "contents": [ - { - "type": "param", - "name": "component", - "description": "Check collision with entities that have this component" - }, - { - "type": "raw", - "value": "applied to them." - }, { "type": "return", - "value": "`false` if there is no collision. If a collision is detected," + "value": "Cloned entity of the current entity" } ] }, { "type": "raw", - "value": "returns an Array of collision data objects (see below).\n\nTests for collisions with entities that have the specified component\napplied to them.\nIf a collision is detected, data regarding the collision will be present in\nthe array returned by this method.\nIf no collisions occur, this method returns false.\n\nFollowing is a description of a collision data object that this method may\nreturn: The returned collision data will be an Array of Objects with the\ntype of collision used, the object collided and if the type used was SAT (a polygon was used as the hitbox) then an amount of overlap.\n```\n[{\n obj: [entity],\n type: [\"MBR\" or \"SAT\"],\n overlap: [number]\n}]\n```\n**obj:** The entity with which the collision occured.\n**type:** Collision detection method used. One of:\n+ *MBR:* Standard axis aligned rectangle intersection (`.intersect` in the 2D component).\n+ *SAT:* Collision between any two convex polygons. Used when both colliding entities have the `Collision` component applied to them.\n**overlap:** If SAT collision was used, this will signify the overlap percentage between the colliding entities.\n" - }, - { - "type": "xref", - "xrefs": [ - "2D" - ] + "value": "Method will create another entity with the exact same\nproperties, components and methods as the current entity." } ], - "name": ".hit", - "comp": "Collision" + "name": ".clone", + "comp": "Crafty Core" }, { - "file": "src/collision.js", - "startLine": 310, - "endLine": 323, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 899, + "endLine": 911, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .onHit(String component, Function hit[, Function noHit])", + "signature": "public this .setter(String property, Function callback)", "contents": [ { "type": "param", - "name": "component", - "description": "Component to check collisions for." - }, - { - "type": "param", - "name": "hit", - "description": "Callback method to execute upon collision with component. Will be passed the results of the collision check in the same format documented for hit()." + "name": "property", + "description": "Property to watch for modification" }, { "type": "param", - "name": "noHit", - "description": "Callback method executed once as soon as collision stops." + "name": "callback", + "description": "Method to execute if the property is modified" } ] }, { "type": "raw", - "value": "\nCreates an EnterFrame event calling .hit() each frame. When a collision is detected the callback will be invoked.\nNote that the `hit` callback will be invoked every frame the collision is active, not just the first time the collision occurs.\nIf you want more fine-grained control consider using `.checkHits` or `.hit`.\n" + "value": "Will watch a property waiting for modification and will then invoke the\ngiven callback when attempting to modify.\n\nThis feature is deprecated; use .defineField() instead." }, { "type": "xref", "xrefs": [ - ".checkHits", - ".hit" + ".defineField" ] } ], - "name": ".onHit", - "comp": "Collision" + "name": ".setter", + "comp": "Crafty Core" }, { - "file": "src/collision.js", - "startLine": 343, - "endLine": 355, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 916, + "endLine": 942, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void .checkHits(String component, Object collisionData)", + "signature": "public this .defineField(String property, Function getCallback, Function setCallback)", "contents": [ { "type": "param", - "name": "component", - "description": "The name of the component for which this handler" + "name": "property", + "description": "Property name to assign getter & setter to" }, { - "type": "raw", - "value": "checks for collisions." + "type": "param", + "name": "getCallback", + "description": "Method to execute if the property is accessed" }, { "type": "param", - "name": "collisionData", - "description": "Collision data object used to track collisions with" + "name": "setCallback", + "description": "Method to execute if the property is mutated" } ] }, { "type": "raw", - "value": "the specified component.\n\nThis is a helper method for creating collisions handlers set up by\n`.checkHits(...)`. Do not call this directly.\n" + "value": "Assigns getters and setters to the property.\nA getter will watch a property waiting for access and will then invoke the\ngiven getCallback when attempting to retrieve.\nA setter will watch a property waiting for mutation and will then invoke the\ngiven setCallback when attempting to modify.\n" }, { - "type": "xref", - "xrefs": [ - ".checkHits" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D\");\nent.defineField(\"customData\", function() {\n return this._customData;\n}, function(newValue) {\n this._customData = newValue;\n});\n\nent.customData = \"2\" // set customData to 2\nCrafty.log(ent.customData) // prints 2\n```" + } ] } ], - "name": "._createCollisionHandler", - "comp": "Collision" + "name": ".defineField", + "comp": "Crafty Core" }, { - "file": "src/collision.js", - "startLine": 377, - "endLine": 415, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 948, + "endLine": 953, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .checkHits(String componentList)", - "contents": [ - { - "type": "param", - "name": "componentList", - "description": "A comma seperated list of components to check for collisions with." - } - ] + "signature": "public this .destroy(void)", + "contents": [] }, + { + "type": "raw", + "value": "Will remove all event listeners and delete all properties as well as removing from the stage" + } + ], + "name": ".destroy", + "comp": "Crafty Core" + }, + { + "file": "src/core/core.js", + "startLine": 974, + "endLine": 993, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public this .checkHits(String component1[, .., String componentN])", + "signature": "public this Crafty.extend(Object obj)", "contents": [ { "type": "param", - "name": "component#", - "description": "A component to check for collisions with." + "name": "obj", + "description": "An object whose fields will be copied onto Crafty. This is a shallow copy." } ] }, { "type": "raw", - "value": "\nPerforms collision checks against all entities that have at least one of\nthe components specified when calling this method. If collisions occur,\na \"HitOn\" event containing the collision information will be fired for the\nentity on which this method was invoked. See the documentation for `.hit()`\nfor a description of collision data contained in the event.\nWhen a collision that was reported ends, a corresponding \"HitOff\" event\nwill be fired.\n\nCalling this method more than once for the same component type will not\ncause redundant hit checks.\n\n**Note:** Hit checks are performed upon entering each new frame (using\nthe *EnterFrame* event). It is entirely possible for object to move in\nsaid frame after the checks were performed (even if the more is the\nresult of *EnterFrame*, as handlers run in no particular order). In such\na case, the hit events will not fire until the next check is performed in\nthe following frame.\n" + "value": "Used to extend the Crafty namespace by passing in an object of properties and methods to add.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.e(\"2D, Collision\")\n .checkHits('Solid') // check for collisions with entities that have the Solid component in each frame\n .bind(\"HitOn\", function(hitData) {\n console.log(\"Collision with Solid entity occurred for the first time.\");\n })\n .bind(\"HitOff\", function(comp) {\n console.log(\"Collision with Solid entity ended.\");\n });\n```\n" + "value": "``` *\nCrafty.extend({\n isArray: function(arg){\n return Object.prototype.toString.call(arg) === '[object Array]'\n }\n});\n\nCrafty.isArray([4, 5, 6]); // returns true\nCrafty.isArray('hi'); // returns false\n```" } ] - }, - { - "type": "xref", - "xrefs": [ - ".hit" - ] } ], - "name": ".checkHits", - "comp": "Collision" + "name": "Crafty.extend", + "categories": [ + "Core" + ] }, { - "file": "src/collision.js", - "startLine": 443, - "endLine": 468, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1133, + "endLine": 1153, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Load", + "description": "Just after the viewport is initialised. Before the EnterFrame loops is started", + "objName": "Data", + "objProp": null + } + ] + }, { "type": "method", - "signature": "public this .ignoreHits()", + "signature": "public this Crafty.init([Number width, Number height, String stage_elem])", "contents": [] }, { "type": "method", - "signature": "public this .ignoreHits(String componentList)", + "signature": "public this Crafty.init([Number width, Number height, HTMLElement stage_elem])", "contents": [ { "type": "param", - "name": "componentList", - "description": "A comma seperated list of components to stop checking" + "name": "Number width", + "description": "Width of the stage" + }, + { + "type": "param", + "name": "Number height", + "description": "Height of the stage" + }, + { + "type": "param", + "name": "String or HTMLElement stage_elem", + "description": "the element to use for the stage" } ] }, { "type": "raw", - "value": "for collisions with." + "value": "Sets the element to use as the stage, creating it if necessary. By default a div with id 'cr-stage' is used, but if the 'stage_elem' argument is provided that will be used instead. (see `Crafty.viewport.init`)\n\nStarts the `EnterFrame` interval. This will call the `EnterFrame` event for every frame.\n\nCan pass width and height values for the stage otherwise will default to window size.\n\nAll `Load` events will be executed.\n\nUses `requestAnimationFrame` to sync the drawing with the browser but will default to `setInterval` if the browser does not support it." }, + { + "type": "xref", + "xrefs": [ + "Crafty.stop", + "Crafty.viewport" + ] + } + ], + "name": "Crafty.init", + "categories": [ + "Core" + ] + }, + { + "file": "src/core/core.js", + "startLine": 1185, + "endLine": 1197, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public this .ignoreHits(String component1[, .., String componentN])", + "signature": "public String Crafty.getVersion()", "contents": [ { - "type": "param", - "name": "component#", - "description": "A component to stop checking for collisions with." + "type": "return", + "value": "Current version of Crafty as a string" } ] }, { "type": "raw", - "value": "\nStops checking for collisions with all, or certain, components. If called\nwithout arguments, this method will cause all collision checks on the\nentity to cease. To disable checks for collisions with specific\ncomponents, specify the components as a comma separated string or as\na set of arguments.\n\nCalling this method with component names for which there are no collision\nchecks has no effect.\n" + "value": "Return current version of crafty\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.e(\"2D, Collision\")\n .checkHits('Solid')\n ...\n .ignoreHits('Solid'); // stop checking for collisions with entities that have the Solid component\n```" + "value": "```\nCrafty.getVersion(); //'0.5.2'\n```" } ] } ], - "name": ".ignoreHits", - "comp": "Collision" + "name": "Crafty.getVersion", + "categories": [ + "Core" + ] }, { - "file": "src/collision.js", - "startLine": 502, - "endLine": 532, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1202, + "endLine": 1213, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this .resetHitChecks()", - "contents": [] + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "CraftyStop", + "description": "when the game is stopped", + "objName": "Data", + "objProp": "{bool clearState}" + } + ] }, { "type": "method", - "signature": "public this .resetHitChecks(String componentList)", + "signature": "public this Crafty.stop([bool clearState])", "contents": [ { "type": "param", - "name": "componentList", - "description": "A comma seperated list of components to re-check" + "name": "clearState", + "description": "if true the stage and all game state is cleared." } ] }, { "type": "raw", - "value": "for collisions with." + "value": "Stops the EnterFrame interval and removes the stage element.\n\nTo restart, use `Crafty.init()`." }, { - "type": "method", - "signature": "public this .resetHitChecks(String component1[, .., String componentN])", - "contents": [ + "type": "xref", + "xrefs": [ + "Crafty.init" + ] + } + ], + "name": "Crafty.stop", + "categories": [ + "Core" + ] + }, + { + "file": "src/core/core.js", + "startLine": 1244, + "endLine": 1263, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ { - "type": "param", - "name": "component#", - "description": "A component to re-check for collisions with." + "type": "trigger", + "event": "Pause", + "description": "when the game is paused", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "Unpause", + "description": "when the game is unpaused", + "objName": "Data", + "objProp": null } ] }, + { + "type": "method", + "signature": "public this Crafty.pause(void)", + "contents": [] + }, { "type": "raw", - "value": "\nCauses collision events to be received for collisions that are already\ntaking place (normally, an additional event would not fire before said\ncollisions cease and happen another time).\nIf called without arguments, this method will cause all collision checks on the\nentity to fire events once more. To re-check for collisions with specific\ncomponents, specify the components as a comma separated string or as\na set of arguments.\n\nCalling this method with component names for which there are no collision\nchecks has no effect.\n" + "value": "Pauses the game by stopping the EnterFrame event from firing. If the game is already paused it is unpaused.\nYou can pass a boolean parameter if you want to pause or unpause no matter what the current state is.\nModern browsers pauses the game when the page is not visible to the user. If you want the Pause event\nto be triggered when that happens you can enable autoPause in `Crafty.settings`.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\n// this example fires the HitOn event each frame the collision with the Solid entity is active, instead of just the first time the collision occurs.\nCrafty.e(\"2D, Collision\")\n .checkHits('Solid')\n .bind(\"HitOn\", function(hitData) {\n console.log(\"Collision with Solid entity was reported in this frame again!\");\n this.resetHitChecks('Solid'); // fire the HitOn event in the next frame also, if the collision is still active.\n })\n```" + "value": "Have an entity pause the game when it is clicked.\n```\nbutton.bind(\"click\", function() {\n Crafty.pause();\n});\n```" } ] } ], - "name": ".resetHitChecks", - "comp": "Collision" + "name": "Crafty.pause", + "categories": [ + "Core" + ] }, { - "file": "src/color.js", - "startLine": 7, - "endLine": 15, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1282, + "endLine": 1292, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "Crafty.assignColor(color[, assignee])", + "signature": "public Boolean Crafty.isPaused()", "contents": [ - { - "type": "param", - "name": "color", - "description": "a string represenation of the color to assign, in any valid HTML format" - }, - { - "type": "param", - "name": "assignee", - "description": "an object to use instead of creating one from scratch" - }, { "type": "return", - "value": "An object with `_red`, `_green`, and `_blue` properties assigned." + "value": "Whether the game is currently paused." } ] }, { - "type": "raw", - "value": " Potentially with `_strength` representing the alpha channel.\n If the assignee parameter is passed, that object will be assigned those values and returned." + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.isPaused();\n```" + } + ] } ], - "name": "Crafty.assignColor", + "name": "Crafty.isPaused", "categories": [ - "Graphics" + "Core" ] }, { - "file": "src/color.js", - "startLine": 137, - "endLine": 140, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1297, + "endLine": 1301, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Draw a colored rectangle." + "value": "Handles game ticks" } ], - "name": "Color", + "name": "Crafty.timer", "categories": [ - "Graphics" + "Game Loop" ] }, { - "file": "src/color.js", - "startLine": 175, - "endLine": 208, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1379, + "endLine": 1391, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "Invalidate", - "description": "when the color changes", - "objName": "Data", - "objProp": null - } - ] - }, - { - "type": "raw", - "value": "\nWill assign the color and opacity, either through a string shorthand, or through explicit rgb values." - }, { "type": "method", - "signature": "public this .color(String color[, Float strength])", + "signature": "public void Crafty.timer.steptype(mode [, maxTimeStep])", "contents": [ + { + "type": "raw", + "value": "Can be called to set the type of timestep the game loop uses" + }, { "type": "param", - "name": "color", - "description": "Color of the rectangle" + "name": "mode", + "description": "the type of time loop. Allowed values are \"fixed\", \"semifixed\", and \"variable\". Crafty defaults to \"fixed\"." }, { "type": "param", - "name": "strength", - "description": "the opacity of the rectangle" + "name": "maxTimeStep", + "description": "For \"fixed\", sets the max number of frames per step. For \"variable\" and \"semifixed\", sets the maximum time step allowed." } ] }, { "type": "raw", - "value": "" - }, + "value": "* In \"fixed\" mode, each frame is sent the same value of `dt`, and to achieve the target game speed, mulitiple frame events are triggered before each render.\n* In \"variable\" mode, there is only one frame triggered per render. This recieves a value of `dt` equal to the actual elapsed time since the last frame.\n* In \"semifixed\" mode, multiple frames per render are processed, and the total time since the last frame is divided evenly between them.\n" + } + ], + "name": "Crafty.timer.steptype", + "comp": "Crafty.timer" + }, + { + "file": "src/core/core.js", + "startLine": 1410, + "endLine": 1427, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public this .color(r, g, b[, strength])", - "contents": [ + "signature": "public void Crafty.timer.step()", + "contents": [] + }, + { + "type": "triggers", + "events": [ { - "type": "param", - "name": "r", - "description": "value for the red channel" + "type": "trigger", + "event": "EnterFrame", + "description": "Triggered on each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)", + "objName": "Data", + "objProp": "{ frame: Number, dt:Number }" }, { - "type": "param", - "name": "g", - "description": "value for the green channel" + "type": "trigger", + "event": "ExitFrame", + "description": "Triggered after each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)", + "objName": "Data", + "objProp": "{ frame: Number, dt:Number }" }, { - "type": "param", - "name": "b", - "description": "value for the blue channel" + "type": "trigger", + "event": "PreRender", + "description": "Triggered every time immediately before a scene should be rendered", + "objName": "Data", + "objProp": null }, { - "type": "param", - "name": "strength", - "description": "the opacity of the rectangle" + "type": "trigger", + "event": "RenderScene", + "description": "Triggered every time a scene should be rendered", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "PostRender", + "description": "Triggered every time immediately after a scene should be rendered", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "MeasureWaitTime", + "description": "Triggered at the beginning of each step after the first. Passes the time the game loop waited between steps.", + "objName": "Data", + "objProp": "Number" + }, + { + "type": "trigger", + "event": "MeasureFrameTime", + "description": "Triggered after each frame. Passes the time it took to advance one frame.", + "objName": "Data", + "objProp": "Number" + }, + { + "type": "trigger", + "event": "MeasureRenderTime", + "description": "Triggered after each render. Passes the time it took to render the scene", + "objName": "Data", + "objProp": "Number" } ] }, { "type": "raw", - "value": "" + "value": "Advances the game by performing a step. A step consists of one/multiple frames followed by a render. The amount of frames depends on the timer's steptype.\nSpecifically it triggers `EnterFrame` & `ExitFrame` events for each frame and `PreRender`, `RenderScene` & `PostRender` events for each render.\n" }, + { + "type": "xref", + "xrefs": [ + "Crafty.timer.steptype" + ] + } + ], + "name": "Crafty.timer.step", + "comp": "Crafty.timer" + }, + { + "file": "src/core/core.js", + "startLine": 1498, + "endLine": 1509, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public String .color()", + "signature": "public void Crafty.timer.FPS()", + "contents": [] + }, + { + "type": "raw", + "value": "Returns the target frames per second. This is not an actual frame rate." + }, + { + "type": "method", + "signature": "public void Crafty.timer.FPS(Number value)", "contents": [ { - "type": "return", - "value": "A string representing the current color as a CSS property." + "type": "param", + "name": "value", + "description": "the target rate" } ] }, { - "type": "raw", - "value": "" + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "FPSChange", + "description": "Triggered when the target FPS is changed by user", + "objName": "new target FPS", + "objProp": "Number" + } + ] }, { - "type": "example", + "type": "raw", + "value": "Sets the target frames per second. This is not an actual frame rate.\nThe default rate is 50." + } + ], + "name": "Crafty.timer.FPS", + "comp": "Crafty.timer" + }, + { + "file": "src/core/core.js", + "startLine": 1520, + "endLine": 1527, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this Crafty.timer.simulateFrames(Number frames[, Number timestep])", "contents": [ { "type": "raw", - "value": "```\nvar c = Crafty.e(\"2D, DOM, Color\");\nc.color(\"#FF0000\");\nc.color(\"red\");\nc.color(255, 0, 0);\nc.color(\"rgb(255, 0, 0\")\n```\nThree different ways of assign the color red.\n```\nvar c = Crafty.e(\"2D, DOM, Color\");\nc.color(\"#00FF00\", 0.5);\nc.color(\"rgba(0, 255, 0, 0.5)\");\n```\nTwo ways of assigning a transparent green color." + "value": "Advances the game state by a number of frames and draws the resulting stage at the end. Useful for tests and debugging." + }, + { + "type": "param", + "name": "frames", + "description": "number of frames to simulate" + }, + { + "type": "param", + "name": "timestep", + "description": "the duration to pass each frame. Defaults to milliSecPerFrame (20 ms) if not specified." } ] } ], - "name": ".color", - "comp": "Color" + "name": "Crafty.timer.simulateFrames", + "comp": "Crafty.timer" }, { - "file": "src/controls.js", - "startLine": 12, - "endLine": 28, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1547, + "endLine": 1568, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "Remembering what keys (referred by Unicode) are down.\n" + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "NewEntity", + "description": "When the entity is created and all components are added", + "objName": "Data", + "objProp": "{ id:Number }" + } + ] }, { - "type": "example", + "type": "method", + "signature": "public Entity Crafty.e(String componentList)", "contents": [ { - "type": "raw", - "value": "```\nCrafty.c(\"Keyboard\", {\n isDown: function (key) {\n if (typeof key === \"string\") {\n key = Crafty.keys[key];\n }\n return !!Crafty.keydown[key];\n }\n});\n```" + "type": "param", + "name": "componentList", + "description": "List of components to assign to new entity" } ] }, { - "type": "xref", - "xrefs": [ - "Keyboard", - "Crafty.keys" + "type": "method", + "signature": "public Entity Crafty.e(String component1[, .., String componentN])", + "contents": [ + { + "type": "param", + "name": "component#", + "description": "Component to add" + } ] - } - ], - "name": "Crafty.keydown", - "categories": [ - "Input" - ] - }, - { - "file": "src/controls.js", - "startLine": 58, - "endLine": 84, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "raw", - "value": "\nInternal method which dispatches mouse events received by Crafty (crafty.stage.elem).\nThe mouse events get dispatched to the closest entity to the source of the event (if available).\n\nYou can read more about the MouseEvent, which is the parameter passed to the callback.\nhttps://developer.mozilla.org/en-US/docs/Web/API/MouseEvent\n\nThis method also sets a global property Crafty.lastEvent, which holds the most recent event that\noccured (useful for determining mouse position in every frame).\n```\nvar newestX = Crafty.lastEvent.realX,\n newestY = Crafty.lastEvent.realY;\n```\n\nNotable properties of a MouseEvent e:\n```\n//(x,y) coordinates of mouse event in web browser screen space\ne.clientX, e.clientY\n//(x,y) coordinates of mouse event in world/viewport space\ne.realX, e.realY\n// Normalized mouse button according to Crafty.mouseButtons\ne.mouseButton\n```" + "value": "Creates an entity. Any arguments will be applied in the same\nway `.addComponent()` is applied as a quick way to add components.\n\nAny component added will augment the functionality of\nthe created entity by assigning the properties and methods from the component to the entity.\n" }, { - "type": "xref", - "xrefs": [ - "Crafty.touchDispatch" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar myEntity = Crafty.e(\"2D, DOM, Color\");\n```\n" + } ] - } - ], - "name": "Crafty.mouseDispatch", - "categories": [ - "Input" - ] - }, - { - "file": "src/controls.js", - "startLine": 200, - "endLine": 208, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nTouchEvents have a different structure then MouseEvents.\nThe relevant data lives in e.changedTouches[0].\nTo normalize TouchEvents we catch them and dispatch a mock MouseEvent instead.\n" }, { "type": "xref", "xrefs": [ - "Crafty.mouseDispatch" + "Crafty.c" ] } ], - "name": "Crafty.touchDispatch", + "name": "Crafty.e", "categories": [ - "Input" + "Core" ] }, { - "file": "src/controls.js", - "startLine": 264, - "endLine": 289, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1587, + "endLine": 1658, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "Keyboard Event triggered by Crafty Core" - }, - { - "type": "triggers", - "events": [ + "type": "method", + "signature": "public void Crafty.c(String name, Object component)", + "contents": [ { - "type": "trigger", - "event": "KeyDown", - "description": "is triggered for each entity when the DOM 'keydown' event is triggered.", - "objName": "Data", - "objProp": null + "type": "param", + "name": "name", + "description": "Name of the component" }, { - "type": "trigger", - "event": "KeyUp", - "description": "is triggered for each entity when the DOM 'keyup' event is triggered.", - "objName": "Data", - "objProp": null + "type": "param", + "name": "component", + "description": "Object with the component's properties and methods" } ] }, { "type": "raw", - "value": "" + "value": "Creates a component where the first argument is the ID and the second\nis the object that will be inherited by entities.\n\nSpecifically, each time a component is added to an entity, the component properties are copied over to the entity.\n* In the case of primitive datatypes (booleans, numbers, strings) the property is copied by value.\n* In the case of complex datatypes (objects, arrays, functions) the property is copied by reference and will thus reference the components' original property.\n* (See the two examples below for further explanation)\nNote that when a component method gets called, the `this` keyword will refer to the current entity the component was added to.\n\nA handful of methods or properties are treated specially. They are invoked in partiular contexts, and (in those contexts) cannot be overridden by other components.\n\n- `required`: A string listing required components, which will be added to the component before `init()` runs.\n- `init`: A function to be called when the component is added to an entity\n- `remove`: A function which will be called just before a component is removed, or before an entity is destroyed. It is passed a single boolean parameter that is `true` if the entity is being destroyed.\n- `events`: An object whose properties represent functions bound to events equivalent to the property names. (See the example below.) The binding occurs directly after the call to `init`, and will be removed directly before `remove` is called.\n\nIn addition to these hardcoded special methods, there are some conventions for writing components.\n\n- Properties or methods that start with an underscore are considered private.\n- A method with the same name as the component is considered to be a constructor\nand is generally used when you need to pass configuration data to the component on a per entity basis.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Color\")\n .attr({x: 100, y: 100, w: 50, h: 50})\n .color(\"red\")\n .bind('KeyDown', function(e) {\n if(e.key == Crafty.keys.LEFT_ARROW) {\n this.x = this.x-1;\n } else if (e.key == Crafty.keys.RIGHT_ARROW) {\n this.x = this.x+1;\n } else if (e.key == Crafty.keys.UP_ARROW) {\n this.y = this.y-1;\n } else if (e.key == Crafty.keys.DOWN_ARROW) {\n this.y = this.y+1;\n }\n });\n```\n" + "value": "```\nCrafty.c(\"Annoying\", {\n _message: \"HiHi\",\n init: function() {\n this.bind(\"EnterFrame\", function() { alert(this.message); });\n },\n annoying: function(message) { this.message = message; }\n});\n\nCrafty.e(\"Annoying\").annoying(\"I'm an orange...\");\n```\nTo attach to the \"EnterFrame\" event using the `events` property instead:\n```\nCrafty.c(\"Annoying\", {\n _message: \"HiHi\",\n events: {\n \"EnterFrame\": function(){alert(this.message);}\n }\n annoying: function(message) { this.message = message; }\n});\n```\n\n" } ] }, + { + "type": "warning", + "value": "In the examples above the field _message is local to the entity. That is, if you create many entities with the Annoying component, they can all have different values for _message. That is because it is a simple value, and simple values are copied by value. If however the field had been an object or array, the value would have been shared by all entities with the component, because complex types are copied by reference in javascript. This is probably not what you want and the following example demonstrates how to work around it." + }, + { + "type": "raw", + "value": "```\nCrafty.c(\"MyComponent\", {\n _iAmShared: { a: 3, b: 4 },\n init: function() {\n this._iAmNotShared = { a: 3, b: 4 };\n },\n});\n```\n" + }, { "type": "xref", "xrefs": [ - "Crafty.keys" + "Crafty.e" ] } ], - "name": "KeyboardEvent", + "name": "Crafty.c", "categories": [ - "Input" + "Core" ] }, { - "file": "src/controls.js", - "startLine": 292, - "endLine": 296, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1663, + "endLine": 1674, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "\nEvent Object used in Crafty for cross browser compatibility" - } - ], - "name": "Crafty.eventObject", - "categories": [ - "Input" - ] - }, - { - "file": "src/controls.js", - "startLine": 299, - "endLine": 303, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "type": "method", + "signature": "public void Crafty.trigger(String eventName, * data)", + "contents": [ + { + "type": "param", + "name": "eventName", + "description": "Name of the event to trigger" + }, + { + "type": "param", + "name": "data", + "description": "Arbitrary data to pass into the callback as an argument" + } + ] + }, { "type": "raw", - "value": "\nUnicode of the key pressed" + "value": "This method will trigger every single callback attached to the event name. This means\nevery global event and every entity that has a callback.\n" + }, + { + "type": "xref", + "xrefs": [ + "Crafty.bind" + ] } ], - "name": ".key", - "comp": "Crafty.eventObject" + "name": "Crafty.trigger", + "categories": [ + "Core", + "Events" + ] }, { - "file": "src/controls.js", - "startLine": 392, - "endLine": 430, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1691, + "endLine": 1703, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "Provides the entity with mouse related events" - }, - { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "MouseOver", - "description": "when the mouse enters", - "objName": "Data", - "objProp": "MouseEvent" - }, - { - "type": "trigger", - "event": "MouseOut", - "description": "when the mouse leaves", - "objName": "Data", - "objProp": "MouseEvent" - }, - { - "type": "trigger", - "event": "MouseDown", - "description": "when the mouse button is pressed on", - "objName": "Data", - "objProp": "MouseEvent" - }, - { - "type": "trigger", - "event": "MouseUp", - "description": "when the mouse button is released on", - "objName": "Data", - "objProp": "MouseEvent" - }, + "type": "method", + "signature": "public Function bind(String eventName, Function callback)", + "contents": [ { - "type": "trigger", - "event": "Click", - "description": "when the user clicks", - "objName": "Data", - "objProp": "MouseEvent" + "type": "param", + "name": "eventName", + "description": "Name of the event to bind to" }, { - "type": "trigger", - "event": "DoubleClick", - "description": "when the user double clicks", - "objName": "Data", - "objProp": "MouseEvent" + "type": "param", + "name": "callback", + "description": "Method to execute upon event triggered" }, { - "type": "trigger", - "event": "MouseMove", - "description": "when the mouse is over and moves", - "objName": "Data", - "objProp": "MouseEvent" + "type": "return", + "value": "callback function which can be used for unbind" } ] }, { "type": "raw", - "value": "\nTo be able to use the events on a entity, you have to remember to include the Mouse component, else the events will not get triggered.\n\nYou can read more about the MouseEvent, which is the parameter passed to the callback.\nhttps://developer.mozilla.org/en-US/docs/Web/API/MouseEvent\n\nCrafty adds the mouseButton property to MouseEvents that match one of\n\n- Crafty.mouseButtons.LEFT\n- Crafty.mouseButtons.RIGHT\n- Crafty.mouseButtons.MIDDLE\n\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nvar myEntity = Crafty.e('2D, Canvas, Color, Mouse')\n.attr({x: 10, y: 10, w: 40, h: 40})\n.color('red')\n.bind('Click', function(MouseEvent){\n alert('clicked', MouseEvent);\n});\n\nmyEntity.bind('MouseUp', function(e) {\n if( e.mouseButton == Crafty.mouseButtons.RIGHT )\n console.log(\"Clicked right button\");\n})\n```" - } - ] + "value": "Binds to a global event. Method will be executed when `Crafty.trigger` is used\nwith the event name.\n" }, { "type": "xref", "xrefs": [ - "Crafty.mouseDispatch" + "Crafty.trigger", + "Crafty.unbind" ] } ], - "name": "Mouse", + "name": "Crafty.bind", "categories": [ - "Input" + "Core", + "Events" ] }, { - "file": "src/controls.js", - "startLine": 440, - "endLine": 460, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1712, + "endLine": 1723, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .areaMap(Crafty.polygon polygon)", + "signature": "public Function uniqueBind(String eventName, Function callback)", "contents": [ { "type": "param", - "name": "polygon", - "description": "Instance of Crafty.polygon used to check if the mouse coordinates are inside this region" - } - ] - }, - { - "type": "method", - "signature": "public this .areaMap(Array point1, .., Array pointN)", - "contents": [ + "name": "eventName", + "description": "Name of the event to bind to" + }, { "type": "param", - "name": "point#", - "description": "Array with an `x` and `y` position to generate a polygon" + "name": "callback", + "description": "Method to execute upon event triggered" + }, + { + "type": "return", + "value": "callback function which can be used for unbind" } ] }, { "type": "raw", - "value": "\nAssign a polygon to the entity so that mouse events will only be triggered if\nthe coordinates are inside the given polygon.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Color, Mouse\")\n .color(\"red\")\n .attr({ w: 100, h: 100 })\n .bind('MouseOver', function() {console.log(\"over\")})\n .areaMap([0,0], [50,0], [50,50], [0,50])\n```\n" - } - ] + "value": "Works like Crafty.bind, but prevents a callback from being bound multiple times.\n" }, { "type": "xref", "xrefs": [ - "Crafty.polygon" + "Crafty.bind" ] } ], - "name": ".areaMap", - "comp": "Mouse" + "name": "Crafty.uniqueBind", + "categories": [ + "Core", + "Events" + ] }, { - "file": "src/controls.js", - "startLine": 479, - "endLine": 485, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1729, + "endLine": 1740, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "Enable drag and drop of the entity." - }, - { - "type": "triggers", - "events": [ + "type": "method", + "signature": "public Function one(String eventName, Function callback)", + "contents": [ { - "type": "trigger", - "event": "Dragging", - "description": "is triggered each frame the entity is being dragged", - "objName": "Data", - "objProp": "MouseEvent" + "type": "param", + "name": "eventName", + "description": "Name of the event to bind to" }, { - "type": "trigger", - "event": "StartDrag", - "description": "is triggered when dragging begins", - "objName": "Data", - "objProp": "MouseEvent" + "type": "param", + "name": "callback", + "description": "Method to execute upon event triggered" }, { - "type": "trigger", - "event": "StopDrag", - "description": "is triggered when dragging ends", - "objName": "Data", - "objProp": "MouseEvent" + "type": "return", + "value": "callback function which can be used for unbind" } ] + }, + { + "type": "raw", + "value": "Works like Crafty.bind, but will be unbound once the event triggers.\n" + }, + { + "type": "xref", + "xrefs": [ + "Crafty.bind" + ] } ], - "name": "Draggable", + "name": "Crafty.one", "categories": [ - "Input" + "Core", + "Events" ] }, { - "file": "src/controls.js", - "startLine": 537, - "endLine": 559, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1750, + "endLine": 1775, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .dragDirection()", - "contents": [] - }, - { - "type": "raw", - "value": "Remove any previously specified direction.\n" - }, - { - "type": "method", - "signature": "public this .dragDirection(vector)", + "signature": "public Boolean Crafty.unbind(String eventName, Function callback)", "contents": [ { "type": "param", - "name": "vector", - "description": "Of the form of {x: valx, y: valy}, the vector (valx, valy) denotes the move direction." + "name": "eventName", + "description": "Name of the event to unbind" + }, + { + "type": "param", + "name": "callback", + "description": "Function to unbind" } ] }, { - "type": "raw", - "value": "" - }, - { - "type": "method", - "signature": "public this .dragDirection(degree)", + "type": "example", "contents": [ { - "type": "param", - "name": "degree", - "description": "A number, the degree (clockwise) of the move direction with respect to the x axis." + "type": "raw", + "value": "```\n var play_gameover_sound = function () {...};\n Crafty.bind('GameOver', play_gameover_sound);\n ...\n Crafty.unbind('GameOver', play_gameover_sound);\n```\n\nThe first line defines a callback function. The second line binds that\nfunction so that `Crafty.trigger('GameOver')` causes that function to\nrun. The third line unbinds that function.\n\n```\n Crafty.unbind('GameOver');\n```\n\nThis unbinds ALL global callbacks for the event 'GameOver'. That\nincludes all callbacks attached by `Crafty.bind('GameOver', ...)`, but\nnone of the callbacks attached by `some_entity.bind('GameOver', ...)`." } ] - }, - { - "type": "raw", - "value": "Specify the dragging direction.\n" - }, + } + ], + "name": "Crafty.unbind", + "categories": [ + "Core", + "Events" + ] + }, + { + "file": "src/core/core.js", + "startLine": 1781, + "endLine": 1786, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { - "type": "example", + "type": "method", + "signature": "public Number Crafty.frame(void)", "contents": [ { - "type": "raw", - "value": "```\nthis.dragDirection()\nthis.dragDirection({x:1, y:0}) //Horizontal\nthis.dragDirection({x:0, y:1}) //Vertical\n// Note: because of the orientation of x and y axis,\n// this is 45 degree clockwise with respect to the x axis.\nthis.dragDirection({x:1, y:1}) //45 degree.\nthis.dragDirection(60) //60 degree.\n```" + "type": "return", + "value": "the current frame number" } ] } ], - "name": ".dragDirection", - "comp": "Draggable" + "name": "Crafty.frame", + "categories": [ + "Core" + ] }, { - "file": "src/controls.js", - "startLine": 579, - "endLine": 584, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1807, + "endLine": 1811, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Internal method for starting a drag of an entity either programatically or via Mouse click\n" - }, - { - "type": "param", - "name": "e", - "description": "a mouse event" + "value": "Modify the inner workings of Crafty through the settings." } ], - "name": "._startDrag", - "comp": "Draggable" + "name": "Crafty.settings", + "categories": [ + "Core" + ] }, { - "file": "src/controls.js", - "startLine": 597, - "endLine": 605, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1817, + "endLine": 1827, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .stopDrag(void)", - "contents": [] - }, - { - "type": "triggers", - "events": [ + "signature": "public void Crafty.settings.register(String settingName, Function callback)", + "contents": [ { - "type": "trigger", - "event": "StopDrag", - "description": "Called right after the mouse listeners are removed", - "objName": "Data", - "objProp": null + "type": "param", + "name": "settingName", + "description": "Name of the setting" + }, + { + "type": "param", + "name": "callback", + "description": "Function to execute when use modifies setting" } ] }, { "type": "raw", - "value": "\nStop the entity from dragging. Essentially reproducing the drop.\n" + "value": "Use this to register custom settings. Callback will be executed when `Crafty.settings.modify` is used.\n" }, { "type": "xref", "xrefs": [ - ".startDrag" + "Crafty.settings.modify" ] } ], - "name": ".stopDrag", - "comp": "Draggable" + "name": "Crafty.settings.register", + "comp": "Crafty.settings" }, { - "file": "src/controls.js", - "startLine": 616, - "endLine": 623, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1832, + "endLine": 1842, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .startDrag(void)", - "contents": [] - }, - { - "type": "raw", - "value": "\nMake the entity follow the mouse positions.\n" - }, - { - "type": "xref", - "xrefs": [ - ".stopDrag" + "signature": "public void Crafty.settings.modify(String settingName, * value)", + "contents": [ + { + "type": "param", + "name": "settingName", + "description": "Name of the setting" + }, + { + "type": "param", + "name": "value", + "description": "Value to set the setting to" + } ] - } - ], - "name": ".startDrag", - "comp": "Draggable" - }, - { - "file": "src/controls.js", - "startLine": 633, - "endLine": 640, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "method", - "signature": "public this .enableDrag(void)", - "contents": [] }, { "type": "raw", - "value": "\nRebind the mouse events. Use if `.disableDrag` has been called.\n" + "value": "Modify settings through this method.\n" }, { "type": "xref", "xrefs": [ - ".disableDrag" + "Crafty.settings.register", + "Crafty.settings.get" ] } ], - "name": ".enableDrag", - "comp": "Draggable" + "name": "Crafty.settings.modify", + "comp": "Crafty.settings" }, { - "file": "src/controls.js", - "startLine": 649, - "endLine": 656, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1849, + "endLine": 1859, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .disableDrag(void)", - "contents": [] + "signature": "public * Crafty.settings.get(String settingName)", + "contents": [ + { + "type": "param", + "name": "settingName", + "description": "Name of the setting" + }, + { + "type": "return", + "value": "Current value of the setting" + } + ] }, { "type": "raw", - "value": "\nStops entity from being draggable. Reenable with `.enableDrag()`.\n" + "value": "Returns the current value of the setting.\n" }, { "type": "xref", "xrefs": [ - ".enableDrag" + "Crafty.settings.register", + "Crafty.settings.get" ] } ], - "name": ".disableDrag", - "comp": "Draggable" - }, - { - "file": "src/controls.js", - "startLine": 667, - "endLine": 670, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "Give entities keyboard events (`keydown` and `keyup`)." - } - ], - "name": "Keyboard", - "categories": [ - "Input" - ] + "name": "Crafty.settings.get", + "comp": "Crafty.settings" }, { - "file": "src/controls.js", - "startLine": 673, - "endLine": 688, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1866, + "endLine": 1894, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Boolean isDown(String keyName)", + "signature": "public void Crafty.defineField(Object object, String property, Function getCallback, Function setCallback)", "contents": [ { "type": "param", - "name": "keyName", - "description": "Name of the key to check. See `Crafty.keys`." - } - ] - }, - { - "type": "method", - "signature": "public Boolean isDown(Number keyCode)", - "contents": [ + "name": "object", + "description": "Object to define property on" + }, { "type": "param", - "name": "keyCode", - "description": "Key code in `Crafty.keys`." + "name": "property", + "description": "Property name to assign getter & setter to" + }, + { + "type": "param", + "name": "getCallback", + "description": "Method to execute if the property is accessed" + }, + { + "type": "param", + "name": "setCallback", + "description": "Method to execute if the property is mutated" } ] }, { "type": "raw", - "value": "\nDetermine if a certain key is currently down.\n" + "value": "Assigns getters and setters to the property in the given object.\nA getter will watch a property waiting for access and will then invoke the\ngiven getCallback when attempting to retrieve.\nA setter will watch a property waiting for mutation and will then invoke the\ngiven setCallback when attempting to modify.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nentity.requires('Keyboard').bind('KeyDown', function () { if (this.isDown('SPACE')) jump(); });\n```\n" + "value": "```\nvar ent = Crafty.e(\"2D\");\nCrafty.defineField(ent, \"customData\", function() {\n return this._customData;\n}, function(newValue) {\n this._customData = newValue;\n});\n\nent.customData = \"2\" // set customData to 2\nCrafty.log(ent.customData) // prints 2\n```" } ] }, { "type": "xref", "xrefs": [ - "Crafty.keys" - ] - } - ], - "name": ".isDown", - "comp": "Keyboard" - }, - { - "file": "src/controls.js", - "startLine": 698, - "endLine": 703, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "Used to bind keys to directions and have the entity move accordingly" - }, - { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "NewDirection", - "description": "triggered when direction changes", - "objName": "New direction", - "objProp": "{ x:Number, y:Number }" - }, - { - "type": "trigger", - "event": "Moved", - "description": "triggered on movement on either x or y axis. If the entity has moved on both axes for diagonal movement the event is triggered twice", - "objName": "Old position", - "objProp": "{ x:Number, y:Number }" - } + "Crafty Core#.defineField" ] } ], - "name": "Multiway", + "name": "Crafty.defineField", "categories": [ - "Input" + "Core" ] }, { - "file": "src/controls.js", - "startLine": 752, - "endLine": 768, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/core.js", + "startLine": 1920, + "endLine": 1957, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .multiway([Number speed,] Object keyBindings )", + "signature": "public Object .clone(Object obj)", "contents": [ { "type": "param", - "name": "speed", - "description": "Amount of pixels to move the entity whilst a key is down" - }, - { - "type": "param", - "name": "keyBindings", - "description": "What keys should make the entity go in which direction. Direction is specified in degrees" + "name": "obj", + "description": "an object" } ] }, { "type": "raw", - "value": "Constructor to initialize the speed and keyBindings. Component will listen to key events and move the entity appropriately.\n\nWhen direction changes a NewDirection event is triggered with an object detailing the new direction: {x: x_movement, y: y_movement}\nWhen entity has moved on either x- or y-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}\n" + "value": "Deep copy (a.k.a clone) of an object.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nthis.multiway(3, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});\nthis.multiway({x:3,y:1.5}, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});\nthis.multiway({W: -90, S: 90, D: 0, A: 180});\n```" + "value": "```\n// Null or Primitive types\nCrafty.clone(null); // returns null\nCrafty.clone(4); // returns 4\n\n// Objects\nvar globalCount = 0;\nvar obj1 = {\n count: 0,\n inc: function(){\n this.count++;\n globalCount++;\n },\n log: function(){\n console.log(this.count + '/' + globalCount);\n }\n};\n\nobj1.inc();\nobj1.log(); // prints \"1/1\" to the log\n\nvar obj2 = Crafty.clone(obj1);\nobj2.log(); // prints \"1/1\" to the log\n\nobj1.inc();\nobj1.log(); // prints \"2/2\" to the log\nobj2.log(); // prints \"1/2\" to the log\n```" } ] } ], - "name": ".multiway", - "comp": "Multiway" + "name": "Crafty.clone", + "categories": [ + "Core" + ] }, { - "file": "src/controls.js", - "startLine": 811, - "endLine": 821, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/extensions.js", + "startLine": 4, + "endLine": 8, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this .enableControl()", - "contents": [] - }, { "type": "raw", - "value": "\nEnable the component to listen to key events.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nthis.enableControl();\n```" - } - ] + "value": "Determines feature support for what Crafty can do." } ], - "name": ".enableControl", - "comp": "Multiway" + "name": "Crafty.support", + "categories": [ + "Misc", + "Core" + ] }, { - "file": "src/controls.js", - "startLine": 828, - "endLine": 838, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/extensions.js", + "startLine": 19, + "endLine": 33, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this .disableControl()", - "contents": [] - }, { "type": "raw", - "value": "\nDisable the component to listen to key events.\n" + "value": "Determines if Crafty is running on mobile device.\n\nIf Crafty.mobile is equal true Crafty does some things under hood:\n```\n- set viewport on max device width and height\n- set Crafty.stage.fullscreen on true\n- hide window scrollbars\n```\n" }, { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nthis.disableControl();\n```" - } + "type": "xref", + "xrefs": [ + "Crafty.viewport" ] } ], - "name": ".disableControl", - "comp": "Multiway" + "name": "Crafty.mobile", + "comp": "Crafty.device" }, { - "file": "src/controls.js", - "startLine": 846, - "endLine": 857, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/extensions.js", + "startLine": 36, + "endLine": 40, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this .speed(Number speed)", - "contents": [ - { - "type": "param", - "name": "speed", - "description": "The speed the entity has." - } - ] - }, { "type": "raw", - "value": "\nChange the speed that the entity moves with.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nthis.speed(2);\n```" - } - ] + "value": "Is `Object.defineProperty` supported?" } ], - "name": ".speed", - "comp": "Multiway" + "name": "Crafty.support.defineProperty", + "comp": "Crafty.support" }, { - "file": "src/controls.js", - "startLine": 871, - "endLine": 875, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/extensions.js", + "startLine": 51, + "endLine": 55, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Move an entity in four directions by using the\narrow keys or `W`, `A`, `S`, `D`." + "value": "Is HTML5 `Audio` supported?" } ], - "name": "Fourway", - "categories": [ - "Input" - ] + "name": "Crafty.support.audio", + "comp": "Crafty.support" }, { - "file": "src/controls.js", - "startLine": 883, - "endLine": 896, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/extensions.js", + "startLine": 58, + "endLine": 62, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this .fourway(Number speed)", - "contents": [ - { - "type": "param", - "name": "speed", - "description": "Amount of pixels to move the entity whilst a key is down" - } - ] - }, { "type": "raw", - "value": "Constructor to initialize the speed. Component will listen for key events and move the entity appropriately.\nThis includes `Up Arrow`, `Right Arrow`, `Down Arrow`, `Left Arrow` as well as `W`, `A`, `S`, `D`.\n\nWhen direction changes a NewDirection event is triggered with an object detailing the new direction: {x: x_movement, y: y_movement}\nWhen entity has moved on either x- or y-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}\n\nThe key presses will move the entity in that direction by the speed passed in the argument.\n" - }, - { - "type": "xref", - "xrefs": [ - "Multiway" - ] + "value": "Returns the browser specific prefix (`Moz`, `O`, `ms`, `webkit`, `node`)." } ], - "name": ".fourway", - "comp": "Fourway" + "name": "Crafty.support.prefix", + "comp": "Crafty.support" }, { - "file": "src/controls.js", - "startLine": 916, - "endLine": 922, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/extensions.js", + "startLine": 71, + "endLine": 75, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "NewDirection", - "description": "When direction changes a NewDirection event is triggered with an object detailing the new direction: {x: x_movement, y: y_movement}. This is consistent with Fourway and Multiway components.", - "objName": "Data", - "objProp": null - }, - { - "type": "trigger", - "event": "Moved", - "description": "When entity has moved on x-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}", - "objName": "Data", - "objProp": null - } - ] - }, + "type": "raw", + "value": "Version of the browser" + } + ], + "name": "Crafty.support.versionName", + "comp": "Crafty.support" + }, + { + "file": "src/core/extensions.js", + "startLine": 78, + "endLine": 82, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nMove an entity left or right using the arrow keys or `D` and `A` and jump using up arrow or `W`." + "value": "Version number of the browser as an Integer (first number)" } ], - "name": "Twoway", - "categories": [ - "Input" - ] + "name": "Crafty.support.version", + "comp": "Crafty.support" + }, + { + "file": "src/core/extensions.js", + "startLine": 86, + "endLine": 90, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Is the `canvas` element supported?" + } + ], + "name": "Crafty.support.canvas", + "comp": "Crafty.support" + }, + { + "file": "src/core/extensions.js", + "startLine": 93, + "endLine": 97, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Is WebGL supported on the canvas element?" + } + ], + "name": "Crafty.support.webgl", + "comp": "Crafty.support" + }, + { + "file": "src/core/extensions.js", + "startLine": 111, + "endLine": 115, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Is css3Dtransform supported by browser." + } + ], + "name": "Crafty.support.css3dtransform", + "comp": "Crafty.support" + }, + { + "file": "src/core/extensions.js", + "startLine": 118, + "endLine": 122, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Is deviceorientation event supported by browser." + } + ], + "name": "Crafty.support.deviceorientation", + "comp": "Crafty.support" + }, + { + "file": "src/core/extensions.js", + "startLine": 125, + "endLine": 129, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Is devicemotion event supported by browser." + } + ], + "name": "Crafty.support.devicemotion", + "comp": "Crafty.support" }, { - "file": "src/controls.js", - "startLine": 932, - "endLine": 947, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/extensions.js", + "startLine": 137, + "endLine": 170, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .twoway(Number speed[, Number jump])", + "signature": "public this Crafty.addEvent(Object ctx, HTMLElement obj, String event, Function callback)", "contents": [ { "type": "param", - "name": "speed", - "description": "Amount of pixels to move left or right" + "name": "ctx", + "description": "Context of the callback or the value of `this`" + }, + { + "type": "param", + "name": "obj", + "description": "Element to add the DOM event to" }, { "type": "param", - "name": "jump", - "description": "Vertical jump speed" + "name": "event", + "description": "Event name to bind to" + }, + { + "type": "param", + "name": "callback", + "description": "Method to execute when triggered" } ] }, { "type": "raw", - "value": "\nConstructor to initialize the speed and power of jump. Component will\nlisten for key events and move the entity appropriately. This includes\n`Up Arrow`, `Right Arrow`, `Left Arrow` as well as `W`, `A`, `D`. Used with the\n`gravity` component to simulate jumping.\n\nThe key presses will move the entity in that direction by the speed passed in\nthe argument. Pressing the `Up Arrow` or `W` will cause the entity to jump.\n" + "value": "Adds DOM level 3 events to elements. The arguments it accepts are the call\ncontext (the value of `this`), the DOM element to attach the event to,\nthe event name (without `on` (`click` rather than `onclick`)) and\nfinally the callback method.\n\nIf no element is passed, the default element will be `window.document`.\n\nCallbacks are passed with event data.\n" }, { - "type": "xref", - "xrefs": [ - "Gravity", - "Fourway" - ] - } - ], - "name": ".twoway", - "comp": "Twoway" - }, - { - "file": "src/core.js", - "startLine": 3, - "endLine": 37, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "Select a set of or single entities by components or an entity's ID.\n\nCrafty uses syntax similar to jQuery by having a selector engine to select entities by their components.\n\nIf there is more than one match, the return value is an Array-like object listing the ID numbers of each matching entity. If there is exactly one match, the entity itself is returned. If you're not sure how many matches to expect, check the number of matches via Crafty(...).length. Alternatively, use Crafty(...).each(...), which works in all cases.\n" + "type": "note", + "value": "This is related to DOM events only, not Crafty's own event system. Of course, you can trigger Crafty events in the callback function!" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\n Crafty(\"MyComponent\")\n Crafty(\"Hello 2D Component\")\n Crafty(\"Hello, 2D, Component\")\n```\n\nThe first selector will return all entities that have the component `MyComponent`. The second will return all entities that have `Hello` and `2D` and `Component` whereas the last will return all entities that have at least one of those components (or).\n\n```\n Crafty(\"*\")\n```\nPassing `*` will select all entities.\n\n```\n Crafty(1)\n```\nPassing an integer will select the entity with that `ID`.\n\nTo work directly with an array of entities, use the `get()` method on a selection.\nTo call a function in the context of each entity, use the `.each()` method.\n\nThe event related methods such as `bind` and `trigger` will work on selections of entities.\n" + "value": "Normally you'd use Crafty's built-in mouse component, but for the sake of an example let's pretend that doesn't exist.\nThe following code will add a stage-wide MouseDown event listener to the player, and log both which button was pressed\nand the (x,y) coordinates in viewport/world/game space.\n```\nvar player = Crafty.e(\"2D\");\n player.onMouseDown = function(e) {\n Crafty.log(e.mouseButton, e.realX, e.realY);\n };\nCrafty.addEvent(player, Crafty.stage.elem, \"mousedown\", player.onMouseDown);\n```" } ] }, { "type": "xref", "xrefs": [ - ".get", - ".each" + "Crafty.removeEvent" ] } ], - "name": "Crafty", + "name": "Crafty.addEvent", "categories": [ - "Core" + "Events", + "Misc" ] }, { - "file": "src/core.js", - "startLine": 64, - "endLine": 72, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/extensions.js", + "startLine": 194, + "endLine": 208, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ + "type": "method", + "signature": "public this Crafty.removeEvent(Object ctx, HTMLElement obj, String event, Function callback)", + "contents": [ { - "type": "trigger", - "event": "NewEntityName", - "description": "After setting new name for entity", - "objName": "entity name", - "objProp": "String" + "type": "param", + "name": "ctx", + "description": "Context of the callback or the value of `this`" }, { - "type": "trigger", - "event": "NewComponent", - "description": "when a new component is added to the entity", - "objName": "Component", - "objProp": "String" + "type": "param", + "name": "obj", + "description": "Element the event is on" }, { - "type": "trigger", - "event": "RemoveComponent", - "description": "when a component is removed from the entity", - "objName": "Component", - "objProp": "String" + "type": "param", + "name": "event", + "description": "Name of the event" }, { - "type": "trigger", - "event": "Remove", - "description": "when the entity is removed by calling .destroy()", - "objName": "Data", - "objProp": null + "type": "param", + "name": "callback", + "description": "Method executed when triggered" } ] }, { "type": "raw", - "value": "\nSet of methods added to every single entity." + "value": "Removes events attached by `Crafty.addEvent()`. All parameters must\nbe the same that were used to attach the event including a reference\nto the callback method.\n" + }, + { + "type": "xref", + "xrefs": [ + "Crafty.addEvent" + ] } ], - "name": "Crafty Core", + "name": "Crafty.removeEvent", "categories": [ - "Core" + "Events", + "Misc" ] }, { - "file": "src/core.js", - "startLine": 175, - "endLine": 184, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/extensions.js", + "startLine": 226, + "endLine": 242, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .setName(String name)", + "signature": "public void Crafty.background(String style)", "contents": [ { "type": "param", - "name": "name", - "description": "A human readable name for debugging purposes." + "name": "style", + "description": "Modify the background with a color or image" } ] }, { "type": "raw", - "value": "" + "value": "This method is a shortcut for adding a background\nstyle to the stage element, i.e.\n`Crafty.stage.elem.style.background = ...`\n\nFor example, if you want the background to be white,\nwith an image in the center, you might use:\n```\nCrafty.background('#FFFFFF url(landscape.png) no-repeat center center');\n```\n" + } + ], + "name": "Crafty.background", + "categories": [ + "Graphics", + "Stage" + ] + }, + { + "file": "src/core/loader.js", + "startLine": 4, + "endLine": 17, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "An object containing every asset used in the current Crafty game.\nThe key is the URL and the value is the `Audio` or `Image` object.\n\nIf loading an asset, check that it is in this object first to avoid loading twice.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nthis.setName(\"Player\");\n```" + "value": "```\nvar isLoaded = !!Crafty.assets[\"images/sprite.png\"];\n```" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.load" + ] } ], - "name": ".setName", - "comp": "Crafty Core" + "name": "Crafty.assets", + "categories": [ + "Assets" + ] }, { - "file": "src/core.js", - "startLine": 195, - "endLine": 220, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/loader.js", + "startLine": 20, + "endLine": 52, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .addComponent(String componentList)", - "contents": [ - { - "type": "param", - "name": "componentList", - "description": "A string of components to add separated by a comma `,`" - } - ] - }, - { - "type": "method", - "signature": "public this .addComponent(String Component1[, .., String ComponentN])", + "signature": "public void Crafty.paths([Object paths])", "contents": [ { "type": "param", - "name": "Component#", - "description": "Component ID to add." + "name": "paths", + "description": "Object containing paths for audio and images folders" } ] }, { "type": "raw", - "value": "Adds a component to the selected entities or entity.\n\nComponents are used to extend the functionality of entities.\nThis means it will copy properties and assign methods to\naugment the functionality of the entity.\n\nFor adding multiple components, you can either pass a string with\nall the component names (separated by commas), or pass each component name as\nan argument.\n\nIf the component has a function named `init` it will be called.\n\nIf the entity already has the component, the component is skipped (nothing happens).\n" + "value": "Function to define custom folder for audio and images. You should use\nthis function to avoid typing the same paths again and again when\nloading assets with the Crafty.load() function.\n\nIf you do not give a object you get the current paths for both audio\nand images back.\n\nYou do not have to define paths.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nthis.addComponent(\"2D, Canvas\");\nthis.addComponent(\"2D\", \"Canvas\");\n```" + "value": "Setting folders:\n```\nCrafty.paths({ audio: \"custom/audio/path/\", images: \"custom/images/path/\" });\n\nCrafty.load({\n \"audio\": {\n \"ray\": ['ray.mp3'] // This loads ray.mp3 from custom/audio/path/ray.mp3\n }\n}, function() {\n Crafty.log('loaded');\n});\n```\n" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.load" + ] } ], - "name": ".addComponent", - "comp": "Crafty Core" + "name": "Crafty.paths", + "categories": [ + "Assets" + ] }, { - "file": "src/core.js", - "startLine": 255, - "endLine": 276, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/loader.js", + "startLine": 64, + "endLine": 87, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this .toggleComponent(String ComponentList)", + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "NewAsset", + "description": "After setting new asset", + "objName": "key and value of new added asset.", + "objProp": "Object" + } + ] + }, + { + "type": "method", + "signature": "public void Crafty.asset(String key, Object asset)", "contents": [ { "type": "param", - "name": "ComponentList", - "description": "A string of components to add or remove separated by a comma `,`" + "name": "key", + "description": "asset url." + }, + { + "type": "param", + "name": "asset", + "description": "`Audio` or `Image` object." } ] }, + { + "type": "raw", + "value": "Add new asset to assets object.\n" + }, { "type": "method", - "signature": "public this .toggleComponent(String Component1[, .., String componentN])", + "signature": "public void Crafty.asset(String key)", "contents": [ { "type": "param", - "name": "Component#", - "description": "Component ID to add or remove." + "name": "key", + "description": "asset url." } ] }, { "type": "raw", - "value": "Add or Remove Components from an entity.\n" + "value": "Get asset from assets object.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar e = Crafty.e(\"2D,DOM,Test\");\ne.toggleComponent(\"Test,Test2\"); //Remove Test, add Test2\ne.toggleComponent(\"Test,Test2\"); //Add Test, remove Test2\n```\n\n```\nvar e = Crafty.e(\"2D,DOM,Test\");\ne.toggleComponent(\"Test\",\"Test2\"); //Remove Test, add Test2\ne.toggleComponent(\"Test\",\"Test2\"); //Add Test, remove Test2\ne.toggleComponent(\"Test\"); //Remove Test\n```" + "value": "```\nCrafty.asset(key, value);\nvar asset = Crafty.asset(key); //object with key and value fields\n```\n" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.assets" + ] } ], - "name": ".toggleComponent", - "comp": "Crafty Core" + "name": "Crafty.asset", + "categories": [ + "Assets" + ] }, { - "file": "src/core.js", - "startLine": 315, - "endLine": 330, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/loader.js", + "startLine": 102, + "endLine": 142, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this .requires(String componentList)", + "type": "raw", + "value": "A list of file extensions that can be loaded as images by Crafty.load\n" + }, + { + "type": "example", "contents": [ { - "type": "param", - "name": "componentList", - "description": "List of components that must be added" + "type": "raw", + "value": "```\n// add tif extension to list of supported image files\nCrafty.image_whitelist.push(\"tif\");\n\nvar assets = {\n \"sprites\": {\n \"sprite.tif\": { //set a tif sprite\n \"tile\": 64,\n \"tileh\": 32,\n \"map\": { \"sprite_car\": [0, 0] }\n }\n },\n \"audio\": {\n \"jump\": \"jump.mp3\";\n }\n};\n\nCrafty.load( assets, // preload the assets\n function() { //when loaded\n Crafty.audio.play(\"jump\"); //Play the audio file\n Crafty.e('2D, DOM, sprite_car'); // create entity with sprite\n },\n\n function(e) { //progress\n },\n\n function(e) { //uh oh, error loading\n }\n);\n```\n" } ] }, - { - "type": "raw", - "value": "\nMakes sure the entity has the components listed. If the entity does not\nhave the component, it will add it.\n\n(In the current version of Crafty, this function behaves exactly the same\nas `addComponent`. By convention, developers have used `requires` for\ncomponent dependencies -- i.e. to indicate specifically that one component\nwill only work properly if another component is present -- and used\n`addComponent` in all other situations.)\n" - }, { "type": "xref", "xrefs": [ - ".addComponent" + "Crafty.asset", + "Crafty.load" ] } ], - "name": ".requires", - "comp": "Crafty Core" + "name": "Crafty.image_whitelist", + "categories": [ + "Assets" + ] }, { - "file": "src/core.js", - "startLine": 336, - "endLine": 352, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/loader.js", + "startLine": 144, + "endLine": 228, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .removeComponent(String Component[, soft])", + "signature": "public void Crafty.load(Object assets, Function onLoad[, Function onProgress[, Function onError]])", "contents": [ { "type": "param", - "name": "component", - "description": "Component to remove" + "name": "assets", + "description": "Object JSON formatted (or JSON string), with assets to load (accepts sounds, images and sprites)" }, { "type": "param", - "name": "soft", - "description": "Whether to soft remove it (defaults to `true`)" + "name": "onLoad", + "description": "Callback when the assets are loaded" + }, + { + "type": "param", + "name": "onProgress", + "description": "Callback when an asset is loaded. Contains information about assets loaded" + }, + { + "type": "param", + "name": "onError", + "description": "Callback when an asset fails to load" } ] }, { "type": "raw", - "value": "\nRemoves a component from an entity. A soft remove (the default) will only\nrefrain `.has()` from returning true. Hard will remove all\nassociated properties and methods.\n" + "value": "Preloader for all assets. Takes a JSON formatted object (or JSON string) of files and adds them to the\n`Crafty.assets` object, as well as setting sprites accordingly.\n\nFormat must follow the pattern shown in the example below, but it's not required to pass all \"audio\",\n\"images\" and \"sprites\" properties, only those you'll need. For example, if you don't need to preload\nsprites, you can omit that property.\n\nBy default, Crafty will assume all files are in the current path. For changing these,\nuse the function `Crafty.paths`.\n\nFiles with suffixes in `image_whitelist` (case insensitive) will be loaded.\n\nIt's possible to pass the full file path(including protocol), instead of just the filename.ext, in case\nyou want some asset to be loaded from another domain.\n\nIf `Crafty.support.audio` is `true`, files with the following suffixes `mp3`, `wav`, `ogg` and\n`mp4` (case insensitive) can be loaded.\n\nThe `onProgress` function will be passed on object with information about\nthe progress including how many assets loaded, total of all the assets to\nload and a percentage of the progress.\n```\n{ loaded: j, total: total, percent: (j / total * 100), src:src }\n```\n\n`onError` will be passed with the asset that couldn't load.\n\nWhen `onError` is not provided, the onLoad is loaded even when some assets are not successfully loaded.\nOtherwise, onLoad will be called no matter whether there are errors or not.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar e = Crafty.e(\"2D,DOM,Test\");\ne.removeComponent(\"Test\"); //Soft remove Test component\ne.removeComponent(\"Test\", false); //Hard remove Test component\n```" + "value": "```\nvar assetsObj = {\n \"audio\": {\n \"beep\": [\"beep.wav\", \"beep.mp3\", \"beep.ogg\"],\n \"boop\": \"boop.wav\",\n \"slash\": \"slash.wav\"\n },\n \"images\": [\"badguy.bmp\", \"goodguy.png\"],\n \"sprites\": {\n \"animals.png\": {\n \"tile\": 50,\n \"tileh\": 40,\n \"map\": { \"ladybug\": [0,0], \"lazycat\": [0,1], \"ferociousdog\": [0,2] }\n \"paddingX\": 5,\n \"paddingY\": 5,\n \"paddingAroundBorder\": 10\n },\n \"vehicles.png\": {\n \"tile\": 150,\n \"tileh\": 75,\n \"map\": { \"car\": [0,0], \"truck\": [0,1] }\n }\n },\n};\n\nCrafty.load(assetsObj, // preload assets\n function() { //when loaded\n Crafty.scene(\"main\"); //go to main scene\n Crafty.audio.play(\"boop\"); //Play the audio file\n Crafty.e('2D, DOM, lazycat'); // create entity with sprite\n },\n\n function(e) { //progress\n },\n\n function(e) { //uh oh, error loading\n }\n);\n```\n" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.paths", + "Crafty.assets", + "Crafty.image_whitelist", + "Crafty.removeAssets" + ] } ], - "name": ".removeComponent", - "comp": "Crafty Core" + "name": "Crafty.load", + "categories": [ + "Assets" + ] }, { - "file": "src/core.js", - "startLine": 371, - "endLine": 385, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/loader.js", + "startLine": 357, + "endLine": 404, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Number .getId(void)", - "contents": [] + "signature": "public void Crafty.removeAssets(Object assets)", + "contents": [ + { + "type": "param", + "name": "data", + "description": "Object JSON formatted (or JSON string), with assets to remove (accepts sounds, images and sprites)" + } + ] }, { "type": "raw", - "value": "Returns the ID of this entity.\n\nFor better performance, simply use the this[0] property.\n" + "value": "Removes assets (audio, images, sprites - and related sprite components) in order to allow the browser\nto free memory.\n\nRecieves a JSON fomatted object (or JSON string) containing 'audio', 'images' and/or 'sprites'\nproperties with assets to be deleted. Follows a similar format as Crafty.load 'data' argument. If\nyou pass the exact same object passed to Crafty.load, that will delete everything loaded that way.\nFor sprites, if you want to keep some specific component, just don't pass that component's name in\nthe sprite 'map'.\n\nNote that in order to remove the sprite components related to a given sprite, it's required to\npass the 'map' property of that sprite, and although its own properties's values (the properties refer\nto sprite components) are not used in the removing process, omitting them will cause an error (since\n'map' is an object, thus it's properties can NOT omitted - however, they can be null, or undefined).\nIt will work as long as the 'map' objects' properties have any value. Or if you define 'map' itself\nas an array, like:\n\"map\": [ \"car\", \"truck\" ] instead of \"map\": { \"car\": [0,0], \"truck\": [0,1] }.\nThis is examplified below (\"animals.png\" VS. \"vehicles.png\" sprites).\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "Finding out the `ID` of an entity can be done by returning the property `0`.\n```\n var ent = Crafty.e(\"2D\");\n ent[0]; //ID\n ent.getId(); //also ID\n```" + "value": "```\nvar assetsToRemoveObj = {\n \"audio\": {\n \"beep\": [\"beep.wav\", \"beep.mp3\", \"beep.ogg\"],\n \"boop\": \"boop.wav\"\n },\n \"images\": [\"badguy.bmp\", \"goodguy.png\"],\n \"sprites\": {\n \"animals.png\": {\n \"map\": { \"ladybug\": [0,0], \"lazycat\": [0,1] },\n },\n \"vehicles.png\": {\n \"map\": [ \"car\", \"truck\" ]\n }\n }\n}\n\nCrafty.removeAssets(assetsToRemoveObj);\n```\n" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.load" + ] } ], - "name": ".getId", - "comp": "Crafty Core" + "name": "Crafty.removeAssets", + "categories": [ + "Assets" + ] }, { - "file": "src/core.js", - "startLine": 391, - "endLine": 400, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/model.js", + "startLine": 1, + "endLine": 34, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Boolean .has(String component)", - "contents": [] + "type": "raw", + "value": "Model is a component that offers new features for isolating business\nlogic in your application. It offers default values, dirty values,\nand deep events on your data.\n\nAll data should be accessed via the appropriate methods `.get`, `.set`,\nand `.data` for the proper events to be triggered. It is not encouraged\nto access them directly.\n\nDirty values make it simple to inspect a model and see what values have changed.\n\nDeep events allow you to bind to specific fields, like `name` or even deep fields\nlike `contact.email` and get notified when those specific fields are updated.\n" + }, + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Change", + "description": "When any data on the model has changed.", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "Change[key]", + "description": "When the specific key on the model has changed.", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "Change[key.key]", + "description": "The nested key value has changed.", + "objName": "Data", + "objProp": null + } + ] }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.c('Person', {\n name: 'Fox',\n init: function() { this.requires('Model'); }\n});\nperson = Crafty.e('Person').attr({name: 'blaine'});\nperson.bind('Change[name]', function() {\n Crafty.log('name changed!');\n});\nperson.attr('name', 'blainesch'); // Triggers event\nperson.is_dirty('name'); // true\nperson.changed // name\n```" + } + ] + } + ], + "name": "Model", + "categories": [ + "Model" + ] + }, + { + "file": "src/core/model.js", + "startLine": 73, + "endLine": 90, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "Returns `true` or `false` depending on if the\nentity has the given component.\n\nFor better performance, simply use the `.__c` object\nwhich will be `true` if the entity has the component or\nwill not exist (or be `false`)." + "value": "Helps determine when data or the entire component is \"dirty\" or has changed attributes.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nperson = Crafty.e('Person').attr({name: 'Fox', age: 24})\nperson.is_dirty() // false\nperson.is_dirty('name') // false\n\nperson.attr('name', 'Lucky');\nperson.is_dirty(); // true\nperson.is_dirty('name'); // true\nperson.is_dirty('age'); // false\nperson.changed; // ['name']\n```" + } + ] } ], - "name": ".has", - "comp": "Crafty Core" + "name": ".is_dirty", + "comp": "Model" }, { - "file": "src/core.js", - "startLine": 406, - "endLine": 449, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/scenes.js", + "startLine": 8, + "endLine": 83, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "triggers", "events": [ { "type": "trigger", - "event": "Change", - "description": "when properties change", + "event": "SceneChange", + "description": "just before a new scene is initialized", "objName": "Data", - "objProp": "{key: value}" + "objProp": "{ oldScene:String, newScene:String }" + }, + { + "type": "trigger", + "event": "SceneDestroy", + "description": "just before the current scene is destroyed", + "objName": "Data", + "objProp": "{ newScene:String }" } ] }, - { - "type": "raw", - "value": "" - }, { "type": "method", - "signature": "public this .attr(String property, Any value[, Boolean silent[, Boolean recursive]])", + "signature": "public void Crafty.scene(String sceneName, Function init[, Function uninit])", "contents": [ { "type": "param", - "name": "property", - "description": "Property of the entity to modify" - }, - { - "type": "param", - "name": "value", - "description": "Value to set the property to" + "name": "sceneName", + "description": "Name of the scene to add" }, { "type": "param", - "name": "silent", - "description": "If you would like to supress events" + "name": "init", + "description": "Function to execute when scene is played" }, { "type": "param", - "name": "recursive", - "description": "If you would like merge recursively" + "name": "uninit", + "description": "Function to execute before next scene is played, after entities with `2D` are destroyed" } ] }, { "type": "raw", - "value": "Use this method to set any property of the entity.\n" + "value": "This is equivalent to calling `Crafty.defineScene`.\n" }, { "type": "method", - "signature": "public this .attr(Object map[, Boolean silent[, Boolean recursive]])", + "signature": "public void Crafty.scene(String sceneName[, Data])", "contents": [ { "type": "param", - "name": "map", - "description": "Object where each key is the property to modify and the value as the property value" - }, - { - "type": "param", - "name": "silent", - "description": "If you would like to supress events" + "name": "sceneName", + "description": "Name of scene to play" }, { "type": "param", - "name": "recursive", - "description": "If you would like merge recursively" + "name": "Data", + "description": "The init function of the scene will be called with this data as its parameter. Can be of any type other than a function." } ] }, { "type": "raw", - "value": "Use this method to set multiple properties of the entity.\n\nSetter options:\n`silent`: If you want to prevent it from firing events.\n`recursive`: If you pass in an object you could overwrite sibling keys, this recursively merges instead of just merging it. This is `false` by default, unless you are using dot notation `name.first`.\n" - }, - { - "type": "method", - "signature": "public Any .attr(String property)", - "contents": [ - { - "type": "param", - "name": "property", - "description": "Property of the entity to modify" - }, - { - "type": "return", - "value": "Value - the value of the property" - } - ] - }, - { - "type": "raw", - "value": "Use this method to get any property of the entity. You can also retrieve the property using `this.property`.\n\n" + "value": "This is equivalent to calling `Crafty.enterScene`.\n\nMethod to create scenes on the stage. Pass an ID and function to register a scene.\n\nTo play a scene, just pass the ID. When a scene is played, all\npreviously-created entities with the `2D` component are destroyed. The\nviewport is also reset.\n\nYou can optionally specify an arugment that will be passed to the scene's init function.\n\nIf you want some entities to persist over scenes (as in, not be destroyed)\nsimply add the component `Persist`.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nthis.attr({key: \"value\", prop: 5});\nthis.attr(\"key\"); // returns \"value\"\nthis.attr(\"prop\"); // returns 5\nthis.key; // \"value\"\nthis.prop; // 5\n\nthis.attr(\"key\", \"newvalue\");\nthis.attr(\"key\"); // returns \"newvalue\"\nthis.key; // \"newvalue\"\n\nthis.attr(\"parent.child\", \"newvalue\");\nthis.parent; // {child: \"newvalue\"};\nthis.attr('parent.child'); // \"newvalue\"\n```" + "value": "```\nCrafty.defineScene(\"loading\", function() {\n Crafty.background(\"#000\");\n Crafty.e(\"2D, DOM, Text\")\n .attr({ w: 100, h: 20, x: 150, y: 120 })\n .text(\"Loading\")\n .css({ \"text-align\": \"center\"})\n .textColor(\"#FFFFFF\");\n});\n\nCrafty.defineScene(\"UFO_dance\",\n function() {Crafty.background(\"#444\"); Crafty.e(\"UFO\");},\n function() {...send message to server...});\n\n// An example of an init function which accepts arguments, in this case an object.\nCrafty.defineScene(\"square\", function(attributes) {\n Crafty.background(\"#000\");\n Crafty.e(\"2D, DOM, Color\")\n .attr(attributes)\n .color(\"red\");\n\n});\n\n```\nThis defines (but does not play) two scenes as discussed below.\n```\nCrafty.enterScene(\"loading\");\n```\nThis command will clear the stage by destroying all `2D` entities (except\nthose with the `Persist` component). Then it will set the background to\nblack and display the text \"Loading\".\n```\nCrafty.enterScene(\"UFO_dance\");\n```\nThis command will clear the stage by destroying all `2D` entities (except\nthose with the `Persist` component). Then it will set the background to\ngray and create a UFO entity. Finally, the next time the game encounters\nanother command of the form `Crafty.scene(scene_name)` (if ever), then the\ngame will send a message to the server.\n```\nCrafty.enterScene(\"square\", {x:10, y:10, w:20, h:20});\n```\nThis will clear the stage, set the background black, and create a red square with the specified position and dimensions.\n```" } ] } ], - "name": ".attr", - "comp": "Crafty Core" + "name": "Crafty.scene", + "categories": [ + "Scenes", + "Stage" + ] }, { - "file": "src/core.js", - "startLine": 562, - "endLine": 568, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/storage.js", + "startLine": 4, + "endLine": 10, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this .toArray(void)", - "contents": [] - }, { "type": "raw", - "value": "\nThis method will simply return the found entities as an array of ids. To get an array of the actual entities, use `get()`." - }, - { - "type": "xref", - "xrefs": [ - ".get" - ] + "value": "Very simple way to get and set values, which will persist when the browser is closed also.\nStorage wraps around HTML5 Web Storage, which is well-supported across browsers and platforms, but limited to 5MB total storage per domain.\nStorage is also available for node, which is permanently persisted to the `./localStorage` folder - take care of removing entries. Note that multiple Crafty instances use the same storage, so care has to be taken not to overwrite existing entries." } ], - "name": ".toArray", - "comp": "Crafty Core" + "name": "Storage", + "categories": [ + "Utilities" + ] }, { - "file": "src/core.js", - "startLine": 574, - "endLine": 591, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/storage.js", + "startLine": 11, + "endLine": 56, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .timeout(Function callback, Number delay)", + "signature": "Crafty.storage(String key)", "contents": [ { "type": "param", - "name": "callback", - "description": "Method to execute after given amount of milliseconds" + "name": "key", + "description": "a key you would like to get from the storage." }, { - "type": "param", - "name": "delay", - "description": "Amount of milliseconds to execute the method" + "type": "return", + "value": "The stored value, or `null` if none saved under that key exists" } ] }, { - "type": "raw", - "value": "\nThe delay method will execute a function after a given amount of time in milliseconds.\n\nEssentially a wrapper for `setTimeout`.\n" - }, - { - "type": "example", + "type": "method", + "signature": "Crafty.storage(String key, String value)", "contents": [ { - "type": "raw", - "value": "Destroy itself after 100 milliseconds\n```\nthis.timeout(function() {\nthis.destroy();\n}, 100);\n```" + "type": "param", + "name": "key", + "description": "the key you would like to save the data under." + }, + { + "type": "param", + "name": "value", + "description": "the value you would like to save." } ] - } - ], - "name": ".timeout", - "comp": "Crafty Core" - }, - { - "file": "src/core.js", - "startLine": 603, - "endLine": 635, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "method", - "signature": "public this .bind(String eventName, Function callback)", + "signature": "Crafty.storage(String key, [Object value, Array value, Boolean value])", "contents": [ { "type": "param", - "name": "eventName", - "description": "Name of the event to bind to" + "name": "key", + "description": "the key you would like to save the data under." }, { "type": "param", - "name": "callback", - "description": "Method to execute when the event is triggered" + "name": "value", + "description": "the value you would like to save, can be an Object or an Array." } ] }, { "type": "raw", - "value": "Attach the current entity (or entities) to listen for an event.\n\nCallback will be invoked when an event with the event name passed\nis triggered. Depending on the event, some data may be passed\nvia an argument to the callback function.\n\nThe first argument is the event name (can be anything) whilst the\nsecond argument is the callback. If the event has data, the\ncallback should have an argument.\n\nEvents are arbitrary and provide communication between components.\nYou can trigger or bind an event even if it doesn't exist yet.\n\nUnlike DOM events, Crafty events are exectued synchronously.\n" + "value": "`Crafty.storage` is used synchronously to either get or set values.\n\nYou can store booleans, strings, objects and arrays.\n" + }, + { + "type": "note", + "value": "Because the underlying method is synchronous, it can cause slowdowns if used frequently during gameplay. You should aim to load or save data at reasonable times such as on level load, or in response to specific user actions." }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nthis.attr(\"triggers\", 0); //set a trigger count\nthis.bind(\"myevent\", function() {\n this.triggers++; //whenever myevent is triggered, increment\n});\nthis.bind(\"EnterFrame\", function() {\n this.trigger(\"myevent\"); //trigger myevent on every frame\n});\n```\n" + "value": "Get an already stored value\n```\nvar playername = Crafty.storage('playername');\n```\n" } ] }, { - "type": "xref", - "xrefs": [ - ".trigger", - ".unbind" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Save a value\n```\nCrafty.storage('playername', 'Hero');\n```\n" + } + ] + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Test to see if a value is already there.\n```\nvar heroname = Crafty.storage('name');\nif(!heroname){\n // Maybe ask the player what their name is here\n heroname = 'Guest';\n}\n// Do something with heroname\n```" + } ] } ], - "name": ".bind", - "comp": "Crafty Core" + "name": "Crafty.storage", + "comp": "Storage" }, { - "file": "src/core.js", - "startLine": 665, - "endLine": 675, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/storage.js", + "startLine": 82, + "endLine": 98, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Number .uniqueBind(String eventName, Function callback)", + "signature": "Crafty.storage.remove(String key)", "contents": [ { "type": "param", - "name": "eventName", - "description": "Name of the event to bind to" - }, - { - "type": "param", - "name": "callback", - "description": "Method to execute upon event triggered" - }, - { - "type": "return", - "value": "ID of the current callback used to unbind" + "name": "key", + "description": "a key where you will like to delete the value of." } ] }, { "type": "raw", - "value": "\nWorks like Crafty.bind, but prevents a callback from being bound multiple times.\n" + "value": "Generally you do not need to remove values from localStorage, but if you do\nstore large amount of text, or want to unset something you can do that with\nthis function.\n" }, { - "type": "xref", - "xrefs": [ - ".bind" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Get an already stored value\n```\nCrafty.storage.remove('playername');\n```\n" + } ] } ], - "name": ".uniqueBind", - "comp": "Crafty Core" + "name": "Crafty.storage.remove", + "comp": "Storage" }, { - "file": "src/core.js", - "startLine": 683, - "endLine": 693, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/systems.js", + "startLine": 7, + "endLine": 33, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Registers a system.\n" + }, + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "SystemLoaded", + "description": "When the system has initialized itself", + "objName": "system object", + "objProp": "obj" + }, + { + "type": "trigger", + "event": "SystemDestroyed", + "description": "Right before the system is destroyed", + "objName": "system object", + "objProp": "obj" + } + ] + }, { "type": "method", - "signature": "public Number one(String eventName, Function callback)", + "signature": "void Crafty.s(String name, Obj template[, Boolean lazy])", "contents": [ + { + "type": "raw", + "value": "Register a system" + }, { "type": "param", - "name": "eventName", - "description": "Name of the event to bind to" + "name": "name", + "description": "The name of the system" }, { "type": "param", - "name": "callback", - "description": "Method to execute upon event triggered" + "name": "template", + "description": "an object whose methods and properties will be copied to the new system" }, { - "type": "return", - "value": "ID of the current callback used to unbind" + "type": "param", + "name": "lazy", + "description": "a flag that indicates whether the system should be initialized right away or the first time it is referenced" } ] }, - { - "type": "raw", - "value": "\nWorks like Crafty.bind, but will be unbound once the event triggers.\n" - }, - { - "type": "xref", - "xrefs": [ - ".bind" - ] - } - ], - "name": ".one", - "comp": "Crafty Core" - }, - { - "file": "src/core.js", - "startLine": 705, - "endLine": 716, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public this .unbind(String eventName[, Function callback])", + "signature": "System Crafty.s(String name)", "contents": [ { - "type": "param", - "name": "eventName", - "description": "Name of the event to unbind" + "type": "raw", + "value": "Access the named system" }, { "type": "param", - "name": "callback", - "description": "Function to unbind" + "name": "name", + "description": "The system to return" + }, + { + "type": "return", + "value": "The referenced system. If the system has not been initialized, it will be before it is returned." } ] }, { "type": "raw", - "value": "Removes binding with an event from current entity.\n\nPassing an event name will remove all events bound to\nthat event. Passing a reference to the callback will\nunbind only that callback." - }, - { - "type": "xref", - "xrefs": [ - ".bind", - ".trigger" - ] + "value": "Objects which handle entities might want to subscribe to the event system without being entities themselves.\nWhen you declare a system with a template object, all the methods and properties of that template are copied to a new object.\nThis new system will automatically have the following event related methods, which function like those of components: `.bind()`, `unbind()`, `trigger()`, `one()`, `uniqueBind()`, `destroy()`.\nMuch like components, you can also provide `init()` and `remove()` methods, as well as an `events` parameter for automatically binding to events.\n\n*Note*: The `init()` method is for setting up the internal state of the system -- if you create entities in it that then reference the system, that'll create an infinite loop." } ], - "name": ".unbind", - "comp": "Crafty Core" + "name": "Crafty.s", + "categories": [ + "Core" + ] }, { - "file": "src/core.js", - "startLine": 745, - "endLine": 759, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/time.js", + "startLine": 1, + "endLine": 8, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this .trigger(String eventName[, Object data])", - "contents": [ - { - "type": "param", - "name": "eventName", - "description": "Event to trigger" - }, - { - "type": "param", - "name": "data", - "description": "Arbitrary data that will be passed into every callback as an argument" - } - ] - }, { "type": "raw", - "value": "Trigger an event with arbitrary data. Will invoke all callbacks with\nthe context (value of `this`) of the current entity object.\n\n*Note: This will only execute callbacks within the current entity, no other entity.*\n\nThe first argument is the event name to trigger and the optional\nsecond argument is the arbitrary event data. This can be absolutely anything.\n\nUnlike DOM events, Crafty events are exectued synchronously." + "value": "A component for triggering functions after a given amount of time.\n\nThis syncs with Crafty's internal clock, and so should generally be preferred to using methods such as `setTimeout`." } ], - "name": ".trigger", - "comp": "Crafty Core" + "name": "Delay", + "categories": [ + "Utilities" + ] }, { - "file": "src/core.js", - "startLine": 805, - "endLine": 824, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/time.js", + "startLine": 38, + "endLine": 79, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .each(Function method)", + "signature": "public this.delay(Function callback, Number delay[, Number repeat[, Function callbackOff]])", "contents": [ { "type": "param", - "name": "method", - "description": "Method to call on each iteration" + "name": "callback", + "description": "Method to execute after given amount of milliseconds. If reference of a method is passed, there's possibility to cancel the delay." + }, + { + "type": "param", + "name": "delay", + "description": "Amount of milliseconds to execute the method." + }, + { + "type": "param", + "name": "repeat", + "description": "(optional) How often to repeat the delayed function. A value of 0 triggers the delayed function exactly once. A value n > 0 triggers the delayed function exactly n+1 times. A value of -1 triggers the delayed function indefinitely. Defaults to one execution." + }, + { + "type": "param", + "name": "callbackOff", + "description": "(optional) Method to execute after delay ends(after all iterations are executed). If repeat value equals -1, callbackOff will never be triggered." } ] }, { "type": "raw", - "value": "Iterates over found entities, calling a function for every entity.\n\nThe function will be called for every entity and will pass the index\nin the iteration as an argument. The context (value of `this`) of the\nfunction will be the current entity in the iteration.\n" + "value": "The delay method will execute a function after a given amount of time in milliseconds.\n\nIt is not a wrapper for `setTimeout`.\n\nIf Crafty is paused, the delay is interrupted with the pause and then resume when unpaused\n\nIf the entity is destroyed, the delay is also destroyed and will not have effect.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "Destroy every second 2D entity\n```\nCrafty(\"2D\").each(function(i) {\n if(i % 2 === 0) {\n this.destroy();\n }\n});\n```" + "value": "The simplest delay\n```\nCrafty.log(\"start\");\nCrafty.e(\"Delay\").delay(function() {\n Crafty.log(\"100ms later\");\n}, 100, 0);\n```\n\nDelay with callbackOff to be executed after all delay iterations\n```\nCrafty.log(\"start\");\nCrafty.e(\"Delay\").delay(function() {\n Crafty.log(\"100ms later\");\n}, 100, 3, function() {\n Crafty.log(\"delay finished\");\n});\n```\n" } ] } ], - "name": ".each", - "comp": "Crafty Core" + "name": ".delay", + "comp": "Delay" }, { - "file": "src/core.js", - "startLine": 837, - "endLine": 862, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/time.js", + "startLine": 90, + "endLine": 110, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Array .get()", + "signature": "public this.cancelDelay(Function callback)", "contents": [ { - "type": "return", - "value": "An array of entities corresponding to the active selector" + "type": "param", + "name": "callback", + "description": "Method reference passed to .delay" } ] }, { "type": "raw", - "value": "" + "value": "The cancelDelay method will cancel a delay set previously.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar doSomething = function(){\n Crafty.log(\"doing something\");\n};\n\n// execute doSomething each 100 miliseconds indefinetely\nvar ent = Crafty.e(\"Delay\").delay(doSomething, 100, -1);\n\n// and some time later, cancel further execution of doSomething\nent.cancelDelay(doSomething);\n```" + } + ] + } + ], + "name": ".cancelDelay", + "comp": "Delay" + }, + { + "file": "src/core/tween.js", + "startLine": 1, + "endLine": 7, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "TweenEnd", + "description": "when a tween finishes", + "objName": "property", + "objProp": "String" + } + ] }, + { + "type": "raw", + "value": "Component to animate the change in 2D properties over time." + } + ], + "name": "Tween", + "categories": [ + "Animation" + ] + }, + { + "file": "src/core/tween.js", + "startLine": 40, + "endLine": 71, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public Entity .get(Number index)", + "signature": "public this .tween(Object properties, Number duration[, String|function easingFn])", "contents": [ { - "type": "return", - "value": "an entity belonging to the current selection" + "type": "param", + "name": "properties", + "description": "Object of numeric properties and what they should animate to" }, { "type": "param", - "name": "index", - "description": "The index of the entity to return. If negative, counts back from the end of the array." + "name": "duration", + "description": "Duration to animate the properties over, in milliseconds." + }, + { + "type": "param", + "name": "easingFn", + "description": "A string or custom function specifying an easing. (Defaults to linear behavior.) See Crafty.easing for more information." } ] }, { "type": "raw", - "value": "\n" + "value": "This method will animate numeric properties over the specified duration.\nThese include `x`, `y`, `w`, `h`, `alpha` and `rotation`.\n\nThe object passed should have the properties as keys and the value should be the resulting\nvalues of the properties. The passed object might be modified if later calls to tween animate the same properties.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "Get an array containing every \"2D\" entity\n```\nvar arr = Crafty(\"2D\").get()\n```\nGet the first entity matching the selector\n```\n// equivalent to Crafty(\"2D\").get()[0], but doesn't create a new array\nvar e = Crafty(\"2D\").get(0)\n```\nGet the last \"2D\" entity matching the selector\n```\nvar e = Crafty(\"2D\").get(-1)\n```\n" + "value": "Move an object to 100,100 and fade out over 200 ms.\n```\nCrafty.e(\"2D, Tween\")\n .attr({alpha: 1.0, x: 0, y: 0})\n .tween({alpha: 0.0, x: 100, y: 100}, 200)\n```" } ] - } - ], - "name": ".get", - "comp": "Crafty Core" - }, - { - "file": "src/core.js", - "startLine": 884, - "endLine": 891, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { - "type": "method", - "signature": "public Entity .clone(void)", + "type": "example", "contents": [ { - "type": "return", - "value": "Cloned entity of the current entity" + "type": "raw", + "value": "Rotate an object over 2 seconds, using the \"smootherStep\" easing function.\n```\nCrafty.e(\"2D, Tween\")\n .attr({rotation:0})\n .tween({rotation:180}, 2000, \"smootherStep\")\n```\n" } ] }, { - "type": "raw", - "value": "\nMethod will create another entity with the exact same\nproperties, components and methods as the current entity." + "type": "xref", + "xrefs": [ + "Crafty.easing" + ] } ], - "name": ".clone", - "comp": "Crafty Core" + "name": ".tween", + "comp": "Tween" }, { - "file": "src/core.js", - "startLine": 911, - "endLine": 919, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/tween.js", + "startLine": 95, + "endLine": 106, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .setter(String property, Function callback)", + "signature": "public this .cancelTween(String target)", "contents": [ { "type": "param", - "name": "property", - "description": "Property to watch for modification" - }, + "name": "target", + "description": "The property to cancel" + } + ] + }, + { + "type": "method", + "signature": "public this .cancelTween(Object target)", + "contents": [ { "type": "param", - "name": "callback", - "description": "Method to execute if the property is modified" + "name": "target", + "description": "An object containing the properties to cancel." } ] }, { "type": "raw", - "value": "Will watch a property waiting for modification and will then invoke the\ngiven callback when attempting to modify.\n" + "value": "Stops tweening the specified property or properties.\nPassing the object used to start the tween might be a typical use of the second signature." } ], - "name": ".setter", - "comp": "Crafty Core" + "name": ".cancelTween", + "comp": "Tween" }, { - "file": "src/core.js", - "startLine": 933, - "endLine": 937, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/tween.js", + "startLine": 120, + "endLine": 126, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .destroy(void)", + "signature": "public this .pauseTweens()", "contents": [] }, { "type": "raw", - "value": "Will remove all event listeners and delete all properties as well as removing from the stage" + "value": "Pauses all tweens associated with the entity" } ], - "name": ".destroy", - "comp": "Crafty Core" + "name": ".pauseTweens", + "comp": "Tween" }, { - "file": "src/core.js", - "startLine": 961, - "endLine": 965, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/core/tween.js", + "startLine": 131, + "endLine": 137, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this .resumeTweens()", + "contents": [] + }, { "type": "raw", - "value": "Used to extend the Crafty namespace.\n" + "value": "Resumes all paused tweens associated with the entity" } ], - "name": "Crafty.extend", - "categories": [ - "Core" - ] + "name": ".resumeTWeens", + "comp": "Tween" }, { - "file": "src/core.js", - "startLine": 984, - "endLine": 1003, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/debug-layer.js", + "startLine": 4, + "endLine": 16, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "triggers", "events": [ { "type": "trigger", - "event": "Load", - "description": "Just after the viewport is initialised. Before the EnterFrame loops is started", + "event": "Draw", + "description": "when the entity is ready to be drawn to the stage", "objName": "Data", "objProp": null - } - ] - }, - { - "type": "method", - "signature": "public this Crafty.init([Number width, Number height, String stage_elem])", - "contents": [] - }, - { - "type": "method", - "signature": "public this Crafty.init([Number width, Number height, HTMLElement stage_elem])", - "contents": [ - { - "type": "param", - "name": "Number width", - "description": "Width of the stage" - }, - { - "type": "param", - "name": "Number height", - "description": "Height of the stage" }, { - "type": "param", - "name": "String or HTMLElement stage_elem", - "description": "the element to use for the stage" + "type": "trigger", + "event": "NoCanvas", + "description": "if the browser does not support canvas", + "objName": "Data", + "objProp": null } ] }, { "type": "raw", - "value": "\nSets the element to use as the stage, creating it if necessary. By default a div with id 'cr-stage' is used, but if the 'stage_elem' argument is provided that will be used instead. (see `Crafty.viewport.init`)\n\nStarts the `EnterFrame` interval. This will call the `EnterFrame` event for every frame.\n\nCan pass width and height values for the stage otherwise will default to window size (see `Crafty.DOM.window`).\n\nAll `Load` events will be executed.\n\nUses `requestAnimationFrame` to sync the drawing with the browser but will default to `setInterval` if the browser does not support it." + "value": "When this component is added to an entity it will be drawn by the DebugCanvas layer.\n\nCrafty.debugCanvas.init() will be automatically called if it is not called already to initialize the canvas element.\n\nTo visualise an object's MBR, use \"VisibleMBR\". To visualise a \"Collision\" object's hitbox, use \"WiredHitBox\" or \"SolidHitBox\"." }, { "type": "xref", "xrefs": [ - "Crafty.stop", - "Crafty.viewport" + "DebugPolygon", + "DebugRectangle" ] } ], - "name": "Crafty.init", + "name": "DebugCanvas", "categories": [ - "Core" + "Debug" ] }, { - "file": "src/core.js", - "startLine": 1015, - "endLine": 1026, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/debug-layer.js", + "startLine": 43, + "endLine": 48, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public String Crafty.getVersion()", + "signature": "public .debugAlpha(Number alpha)", "contents": [ { - "type": "return", - "value": "Current version of Crafty as a string" + "type": "param", + "name": "alpha", + "description": "The alpha level the component will be drawn with" } ] - }, + } + ], + "name": ".debugAlpha", + "comp": "DebugCanvas" + }, + { + "file": "src/debug/debug-layer.js", + "startLine": 54, + "endLine": 63, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { - "type": "raw", - "value": "\nReturn current version of crafty\n" + "type": "method", + "signature": "public .debugFill([String fillStyle])", + "contents": [ + { + "type": "param", + "name": "fillStyle", + "description": "The color the component will be filled with. Defaults to \"red\". Pass the boolean false to turn off filling." + } + ] }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.getVersion(); //'0.5.2'\n```" + "value": "```\nvar myEntity = Crafty.e(\"2D, Collision, SolidHitBox \").debugFill(\"purple\")\n```" } ] } ], - "name": "Crafty.getVersion", - "categories": [ - "Core" - ] + "name": ".debugFill", + "comp": "DebugCanvas" }, { - "file": "src/core.js", - "startLine": 1032, - "endLine": 1042, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/debug-layer.js", + "startLine": 71, + "endLine": 80, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ + "type": "method", + "signature": "public .debugStroke([String strokeStyle])", + "contents": [ { - "type": "trigger", - "event": "CraftyStop", - "description": "when the game is stopped", - "objName": "Data", - "objProp": null + "type": "param", + "name": "strokeStyle", + "description": "The color the component will be outlined with. Defaults to \"red\". Pass the boolean false to turn this off." } ] }, { - "type": "method", - "signature": "public this Crafty.stop([bool clearState])", + "type": "example", "contents": [ { - "type": "param", - "name": "clearState", - "description": "if true the stage and all game state is cleared." + "type": "raw", + "value": "```\nvar myEntity = Crafty.e(\"2D, Collision, WiredHitBox \").debugStroke(\"white\")\n```" } ] - }, + } + ], + "name": ".debugStroke", + "comp": "DebugCanvas" + }, + { + "file": "src/debug/debug-layer.js", + "startLine": 115, + "endLine": 129, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nStops the EnterFrame interval and removes the stage element.\n\nTo restart, use `Crafty.init()`." + "value": "A component for rendering an object with a position and dimensions to the debug canvas.\n\n\n```\nvar myEntity = Crafty.e(\"2D, DebugRectangle\")\n .attr({x: 13, y: 37, w: 42, h: 42})\n .debugStroke(\"green\");\nmyEntity.debugRectangle(myEntity)\n```" }, { "type": "xref", "xrefs": [ - "Crafty.init" + "DebugCanvas" ] } ], - "name": "Crafty.stop", + "name": "DebugRectangle", "categories": [ - "Core" + "Debug" ] }, { - "file": "src/core.js", - "startLine": 1061, - "endLine": 1079, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/debug-layer.js", + "startLine": 135, + "endLine": 143, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "Pause", - "description": "when the game is paused", - "objName": "Data", - "objProp": null - }, + "type": "method", + "signature": "public .debugRectangle(Object rect)", + "contents": [ { - "type": "trigger", - "event": "Unpause", - "description": "when the game is unpaused", - "objName": "Data", - "objProp": null + "type": "param", + "name": "rect", + "description": "an object with _x, _y, _w, and _h to draw" } ] }, - { - "type": "method", - "signature": "public this Crafty.pause(void)", - "contents": [] - }, { "type": "raw", - "value": "\nPauses the game by stopping the EnterFrame event from firing. If the game is already paused it is unpaused.\nYou can pass a boolean parameter if you want to pause or unpause no matter what the current state is.\nModern browsers pauses the game when the page is not visible to the user. If you want the Pause event\nto be triggered when that happens you can enable autoPause in `Crafty.settings`.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "Have an entity pause the game when it is clicked.\n```\nbutton.bind(\"click\", function() {\n Crafty.pause();\n});\n```" - } - ] + "value": "Sets the rectangle that this component draws to the debug canvas.\n" } ], - "name": "Crafty.pause", - "categories": [ - "Core" - ] + "name": ".debugRectangle", + "comp": "DebugRectangle" }, { - "file": "src/core.js", - "startLine": 1099, - "endLine": 1109, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/debug-layer.js", + "startLine": 173, + "endLine": 181, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this Crafty.isPaused()", - "contents": [] - }, { "type": "raw", - "value": "\nCheck whether the game is already paused or not.\n" + "value": "Adding this component to an entity will cause it's MBR to be drawn to the debug canvas.\n\nThe methods of DebugCanvas can be used to control this component's appearance." }, { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.isPaused();\n```" - } + "type": "xref", + "xrefs": [ + "2D", + "DebugRectangle", + "DebugCanvas" ] } ], - "name": "Crafty.isPaused", + "name": "VisibleMBR", "categories": [ - "Core" + "Debug" ] }, { - "file": "src/core.js", - "startLine": 1115, - "endLine": 1118, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/debug-layer.js", + "startLine": 202, + "endLine": 213, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Handles game ticks" + "value": "For drawing a polygon to the debug canvas\n\nThe methods of DebugCanvas can be used to control this component's appearance -- by default it is neither filled nor outlined\n\nFor debugging hitboxes, use WiredHitBox or SolidHitBox. For debugging MBR, use VisibleMBR\n" + }, + { + "type": "xref", + "xrefs": [ + "DebugCanvas" + ] } ], - "name": "Crafty.timer", + "name": "DebugPolygon", "categories": [ - "Game Loop" + "Debug" ] }, { - "file": "src/core.js", - "startLine": 1190, - "endLine": 1201, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/debug-layer.js", + "startLine": 220, + "endLine": 228, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.timer.steptype(mode [, maxTimeStep])", + "signature": "public .debugPolygon(Polygon poly)", "contents": [ - { - "type": "raw", - "value": "Can be called to set the type of timestep the game loop uses" - }, - { - "type": "param", - "name": "mode", - "description": "the type of time loop. Allowed values are \"fixed\", \"semifixed\", and \"variable\". Crafty defaults to \"fixed\"." - }, { "type": "param", - "name": "mode", - "description": "For \"fixed\", sets the max number of frames per step. For \"variable\" and \"semifixed\", sets the maximum time step allowed." + "name": "poly", + "description": "a polygon to render" } ] }, { "type": "raw", - "value": "\n* In \"fixed\" mode, each frame is sent the same value of `dt`, and to achieve the target game speed, mulitiple frame events are triggered before each render.\n* In \"variable\" mode, there is only one frame triggered per render. This recieves a value of `dt` equal to the actual elapsed time since the last frame.\n* In \"semifixed\" mode, multiple frames per render are processed, and the total time since the last frame is divided evenly between them.\n" + "value": "Sets the polygon that this component renders to the debug canvas.\n" } ], - "name": "Crafty.timer.steptype", - "comp": "Crafty.timer" + "name": ".debugPolygon", + "comp": "DebugPolygon" }, { - "file": "src/core.js", - "startLine": 1221, - "endLine": 1237, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/debug-layer.js", + "startLine": 256, + "endLine": 264, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public void Crafty.timer.step()", - "contents": [] + "type": "raw", + "value": "Adding this component to an entity with a Collision component will cause its collision polygon to be drawn to the debug canvas as an outline\n\nThe methods of DebugCanvas can be used to control this component's appearance." }, { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "EnterFrame", - "description": "Triggered on each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)", - "objName": "Data", - "objProp": "{ frame: Number, dt:Number }" - }, - { - "type": "trigger", - "event": "ExitFrame", - "description": "Triggered after each frame. Passes the frame number, and the amount of time since the last frame. If the time is greater than maxTimestep, that will be used instead. (The default value of maxTimestep is 50 ms.)", - "objName": "Data", - "objProp": "{ frame: Number, dt:Number }" - }, - { - "type": "trigger", - "event": "PreRender", - "description": "Triggered every time immediately before a scene should be rendered", - "objName": "Data", - "objProp": null - }, - { - "type": "trigger", - "event": "RenderScene", - "description": "Triggered every time a scene should be rendered", - "objName": "Data", - "objProp": null - }, - { - "type": "trigger", - "event": "PostRender", - "description": "Triggered every time immediately after a scene should be rendered", - "objName": "Data", - "objProp": null - }, - { - "type": "trigger", - "event": "MeasureWaitTime", - "description": "Triggered at the beginning of each step after the first. Passes the time the game loop waited between steps.", - "objName": "Data", - "objProp": "Number" - }, - { - "type": "trigger", - "event": "MeasureFrameTime", - "description": "Triggered after each frame. Passes the time it took to advance one frame.", - "objName": "Data", - "objProp": "Number" - }, - { - "type": "trigger", - "event": "MeasureRenderTime", - "description": "Triggered after each render. Passes the time it took to render the scene", - "objName": "Data", - "objProp": "Number" - } + "type": "xref", + "xrefs": [ + "DebugPolygon", + "DebugCanvas" ] - }, + } + ], + "name": "WiredHitBox", + "categories": [ + "Debug" + ] + }, + { + "file": "src/debug/debug-layer.js", + "startLine": 277, + "endLine": 285, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nAdvances the game by performing a step. A step consists of one/multiple frames followed by a render. The amount of frames depends on the timer's steptype.\nSpecifically it triggers `EnterFrame` & `ExitFrame` events for each frame and `PreRender`, `RenderScene` & `PostRender` events for each render.\n" + "value": "Adding this component to an entity with a Collision component will cause its collision polygon to be drawn to the debug canvas, with a default alpha level of 0.7.\n\nThe methods of DebugCanvas can be used to control this component's appearance." }, { "type": "xref", "xrefs": [ - "Crafty.timer.steptype" + "DebugPolygon", + "DebugCanvas" ] } ], - "name": "Crafty.timer.step", - "comp": "Crafty.timer" + "name": "SolidHitBox", + "categories": [ + "Debug" + ] }, { - "file": "src/core.js", - "startLine": 1309, - "endLine": 1317, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/debug-layer.js", + "startLine": 298, + "endLine": 307, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public void Crafty.timer.FPS()", - "contents": [] + "type": "raw", + "value": "Adding this component to an entity with an AreaMap component will cause its click polygon to be drawn to the debug canvas as an outline.\nFollowing click areas exist for an entity (in decreasing order of priority): AreaMap, Hitbox, MBR. Use the appropriate debug components to display them.\n\nThe methods of DebugCanvas can be used to control this component's appearance." }, + { + "type": "xref", + "xrefs": [ + "DebugPolygon", + "DebugCanvas" + ] + } + ], + "name": "WiredAreaMap", + "categories": [ + "Debug" + ] + }, + { + "file": "src/debug/debug-layer.js", + "startLine": 320, + "endLine": 329, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "Returns the target frames per second. This is not an actual frame rate." + "value": "Adding this component to an entity with an AreaMap component will cause its click polygon to be drawn to the debug canvas, with a default alpha level of 0.7.\nFollowing click areas exist for an entity (in decreasing order of priority): AreaMap, Hitbox, MBR. Use the appropriate debug components to display them.\n\nThe methods of DebugCanvas can be used to control this component's appearance." }, + { + "type": "xref", + "xrefs": [ + "DebugPolygon", + "DebugCanvas" + ] + } + ], + "name": "SolidAreaMap", + "categories": [ + "Debug" + ] + }, + { + "file": "src/debug/logging.js", + "startLine": 4, + "endLine": 13, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public void Crafty.timer.FPS(Number value)", + "signature": "Crafty.log( arguments )", "contents": [ { "type": "param", - "name": "value", - "description": "the target rate" + "name": "arguments", + "description": "arguments which are passed to `console.log`" } ] }, { "type": "raw", - "value": "Sets the target frames per second. This is not an actual frame rate.\nThe default rate is 50." + "value": "This is a simple wrapper for `console.log`. You can disable logging messages by setting `Crafty.loggingEnabled` to false.\nIt is recommended to use `Crafty.log`, as `console.log` can crash on IE9." } ], - "name": "Crafty.timer.FPS", - "comp": "Crafty.timer" + "name": "Crafty.log", + "categories": [ + "Debug" + ] }, { - "file": "src/core.js", - "startLine": 1328, - "endLine": 1334, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/debug/logging.js", + "startLine": 14, + "endLine": 23, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.timer.simulateFrames(Number frames[, Number timestep])", + "signature": "Crafty.error( arguments )", "contents": [ - { - "type": "raw", - "value": "Advances the game state by a number of frames and draws the resulting stage at the end. Useful for tests and debugging." - }, - { - "type": "param", - "name": "frames", - "description": "number of frames to simulate" - }, { "type": "param", - "name": "timestep", - "description": "the duration to pass each frame. Defaults to milliSecPerFrame (20 ms) if not specified." + "name": "arguments", + "description": "arguments which are passed to `console.error`" } ] + }, + { + "type": "raw", + "value": "This is a simple wrapper for `console.error`. You can disable logging messages by setting `Crafty.loggingEnabled` to false.\nIt is recommended to use `Crafty.error`, as `console.error` can crash on IE9." } ], - "name": "Crafty.timer.simulateFrames", - "comp": "Crafty.timer" + "name": "Crafty.error", + "categories": [ + "Debug" + ] }, { - "file": "src/core.js", - "startLine": 1355, - "endLine": 1375, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/canvas-layer.js", + "startLine": 4, + "endLine": 9, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "NewEntity", - "description": "When the entity is created and all components are added", - "objName": "Data", - "objProp": "{ id:Number }" - } - ] - }, + "type": "raw", + "value": "Collection of mostly private methods to draw entities on a canvas element." + } + ], + "name": "Crafty.canvasLayer", + "categories": [ + "Graphics" + ] + }, + { + "file": "src/graphics/canvas-layer.js", + "startLine": 22, + "endLine": 29, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public Entity Crafty.e(String componentList)", + "signature": "public Crafty.canvasLayer.add(ent)", "contents": [ { "type": "param", - "name": "componentList", - "description": "List of components to assign to new entity" + "name": "ent", + "description": "The entity to add" } ] }, { - "type": "method", - "signature": "public Entity Crafty.e(String component1[, .., String componentN])", - "contents": [ - { - "type": "param", - "name": "component#", - "description": "Component to add" - } - ] - }, + "type": "raw", + "value": "Add an entity to the list of Canvas objects to draw" + } + ], + "name": "Crafty.canvasLayer.add", + "comp": "Crafty.canvasLayer" + }, + { + "file": "src/graphics/canvas-layer.js", + "startLine": 33, + "endLine": 39, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "This will return the 2D context of the main canvas element.\nThe value returned from `Crafty.canvasLayer._canvas.getContext('2d')`." + } + ], + "name": "Crafty.canvasLayer.context", + "comp": "Crafty.canvasLayer" + }, + { + "file": "src/graphics/canvas-layer.js", + "startLine": 41, + "endLine": 46, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nCreates an entity. Any arguments will be applied in the same\nway `.addComponent()` is applied as a quick way to add components.\n\nAny component added will augment the functionality of\nthe created entity by assigning the properties and methods from the component to the entity.\n" + "value": "Main Canvas element" + } + ], + "name": "Crafty.canvasLayer._canvas", + "comp": "Crafty.canvasLayer" + }, + { + "file": "src/graphics/canvas-layer.js", + "startLine": 49, + "endLine": 60, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void Crafty.canvasLayer.init(void)", + "contents": [] }, { - "type": "example", - "contents": [ + "type": "triggers", + "events": [ { - "type": "raw", - "value": "```\nvar myEntity = Crafty.e(\"2D, DOM, Color\");\n```\n" + "type": "trigger", + "event": "NoCanvas", + "description": "triggered if `Crafty.support.canvas` is false", + "objName": "Data", + "objProp": null } ] }, { - "type": "xref", - "xrefs": [ - "Crafty.c" - ] + "type": "raw", + "value": "Creates a `canvas` element inside `Crafty.stage.elem`. Must be called\nbefore any entities with the Canvas component can be drawn.\n\nThis method will automatically be called if no `Crafty.canvasLayer.context` is\nfound." } ], - "name": "Crafty.e", - "categories": [ - "Core" - ] + "name": "Crafty.canvasLayer.init", + "comp": "Crafty.canvasLayer" }, { - "file": "src/core.js", - "startLine": 1395, - "endLine": 1448, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/canvas-layer.js", + "startLine": 135, + "endLine": 146, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.c(String name, Object component)", - "contents": [ - { - "type": "param", - "name": "name", - "description": "Name of the component" - }, - { - "type": "param", - "name": "component", - "description": "Object with the component's properties and methods" - } - ] + "signature": "public Crafty.canvasLayer.drawDirty()", + "contents": [] }, { "type": "raw", - "value": "Creates a component where the first argument is the ID and the second\nis the object that will be inherited by entities.\n\nSpecifically, each time a component is added to an entity, the component properties are copied over to the entity.\n* In the case of primitive datatypes (booleans, numbers, strings) the property is copied by value.\n* In the case of complex datatypes (objects, arrays, functions) the property is copied by reference and will thus reference the components' original property.\n* (See the two examples below for further explanation)\nNote that when a component method gets called, the `this` keyword will refer to the current entity the component was added to.\n\nA couple of methods are treated specially. They are invoked in partiular contexts, and (in those contexts) cannot be overridden by other components.\n\n- `init` will be called when the component is added to an entity\n- `remove` will be called just before a component is removed, or before an entity is destroyed. It is passed a single boolean parameter that is `true` if the entity is being destroyed.\n\nIn addition to these hardcoded special methods, there are some conventions for writing components.\n\n- Properties or methods that start with an underscore are considered private.\n- A method with the same name as the component is considered to be a constructor\nand is generally used when you need to pass configuration data to the component on a per entity basis.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.c(\"Annoying\", {\n _message: \"HiHi\",\n init: function() {\n this.bind(\"EnterFrame\", function() { alert(this.message); });\n },\n annoying: function(message) { this.message = message; }\n});\n\nCrafty.e(\"Annoying\").annoying(\"I'm an orange...\");\n```\n\n\nWARNING:\n\nin the example above the field _message is local to the entity. That is, if you create many entities with the Annoying component they can all have different values for _message. That is because it is a simple value, and simple values are copied by value. If however the field had been an object or array, the value would have been shared by all entities with the component because complex types are copied by reference in javascript. This is probably not what you want and the following example demonstrates how to work around it:\n\n```\nCrafty.c(\"MyComponent\", {\n _iAmShared: { a: 3, b: 4 },\n init: function() {\n this._iAmNotShared = { a: 3, b: 4 };\n },\n});\n```\n" - } - ] + "value": "- Triggered by the \"RenderScene\" event\n- If the number of rects is over 60% of the total number of objects\n do the naive method redrawing `Crafty.canvasLayer.drawAll` instead\n- Otherwise, clear the dirty regions, and redraw entities overlapping the dirty regions.\n" }, { "type": "xref", "xrefs": [ - "Crafty.e" + "Canvas#.draw" ] } ], - "name": "Crafty.c", - "categories": [ - "Core" - ] + "name": "Crafty.canvasLayer.drawDirty", + "comp": "Crafty.canvasLayer" }, { - "file": "src/core.js", - "startLine": 1454, - "endLine": 1464, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/canvas-layer.js", + "startLine": 236, + "endLine": 244, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.trigger(String eventName, * data)", + "signature": "public Crafty.canvasLayer.drawAll([Object rect])", "contents": [ { "type": "param", - "name": "eventName", - "description": "Name of the event to trigger" - }, - { - "type": "param", - "name": "data", - "description": "Arbitrary data to pass into the callback as an argument" + "name": "rect", + "description": "a rectangular region {_x: x_val, _y: y_val, _w: w_val, _h: h_val}" } ] }, { "type": "raw", - "value": "\nThis method will trigger every single callback attached to the event name. This means\nevery global event and every entity that has a callback.\n" - }, - { - "type": "xref", - "xrefs": [ - "Crafty.bind" - ] + "value": "- If rect is omitted, redraw within the viewport\n- If rect is provided, redraw within the rect" } ], - "name": "Crafty.trigger", - "categories": [ - "Core", - "Events" - ] + "name": "Crafty.canvasLayer.drawAll", + "comp": "Crafty.canvasLayer" }, { - "file": "src/core.js", - "startLine": 1503, - "endLine": 1514, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/canvas.js", + "startLine": 4, + "endLine": 20, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Number bind(String eventName, Function callback)", - "contents": [ - { - "type": "param", - "name": "eventName", - "description": "Name of the event to bind to" - }, + "type": "triggers", + "events": [ { - "type": "param", - "name": "callback", - "description": "Method to execute upon event triggered" + "type": "trigger", + "event": "Draw", + "description": "when the entity is ready to be drawn to the stage", + "objName": "Data", + "objProp": "{type: \"canvas\", pos, co, ctx}" }, { - "type": "return", - "value": "callback function which can be used for unbind" + "type": "trigger", + "event": "NoCanvas", + "description": "if the browser does not support canvas", + "objName": "Data", + "objProp": null } ] }, { "type": "raw", - "value": "\nBinds to a global event. Method will be executed when `Crafty.trigger` is used\nwith the event name.\n" - }, - { - "type": "xref", - "xrefs": [ - "Crafty.trigger", - "Crafty.unbind" - ] + "value": "When this component is added to an entity it will be drawn to the global canvas element. The canvas element (and hence all Canvas entities) is always rendered below any DOM entities.\n\nCrafty.canvasLayer.init() will be automatically called if it is not called already to initialize the canvas element.\n\nCreate a canvas entity like this\n```\nvar myEntity = Crafty.e(\"2D, Canvas, Color\")\n .color(\"green\")\n .attr({x: 13, y: 37, w: 42, h: 42});\n```" } ], - "name": "Crafty.bind", + "name": "Canvas", "categories": [ - "Core", - "Events" + "Graphics" ] }, { - "file": "src/core.js", - "startLine": 1548, - "endLine": 1558, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/canvas.js", + "startLine": 55, + "endLine": 66, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Number uniqueBind(String eventName, Function callback)", + "signature": "public this .draw([[Context ctx, ]Number x, Number y, Number w, Number h])", "contents": [ { "type": "param", - "name": "eventName", - "description": "Name of the event to bind to" + "name": "ctx", + "description": "Canvas 2D context if drawing on another canvas is required" }, { "type": "param", - "name": "callback", - "description": "Method to execute upon event triggered" + "name": "x", + "description": "X offset for drawing a segment" }, { - "type": "return", - "value": "callback function which can be used for unbind" + "type": "param", + "name": "y", + "description": "Y offset for drawing a segment" + }, + { + "type": "param", + "name": "w", + "description": "Width of the segment to draw" + }, + { + "type": "param", + "name": "h", + "description": "Height of the segment to draw" } ] }, { "type": "raw", - "value": "\nWorks like Crafty.bind, but prevents a callback from being bound multiple times.\n" - }, - { - "type": "xref", - "xrefs": [ - "Crafty.bind" - ] + "value": "Method to draw the entity on the canvas element. Can pass rect values for redrawing a segment of the entity." } ], - "name": "Crafty.uniqueBind", - "categories": [ - "Core", - "Events" - ] + "name": ".draw", + "comp": "Canvas" }, { - "file": "src/core.js", - "startLine": 1565, - "endLine": 1575, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/color.js", + "startLine": 7, + "endLine": 16, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Number one(String eventName, Function callback)", + "signature": "Crafty.assignColor(color[, assignee])", "contents": [ { "type": "param", - "name": "eventName", - "description": "Name of the event to bind to" + "name": "color", + "description": "a string represenation of the color to assign, in any valid HTML format" }, { "type": "param", - "name": "callback", - "description": "Method to execute upon event triggered" + "name": "assignee", + "description": "an object to use instead of creating one from scratch" }, { "type": "return", - "value": "callback function which can be used for unbind" + "value": "An object with `_red`, `_green`, and `_blue` properties assigned. Potentially with `_strength` representing the alpha channel. If the assignee parameter is passed, that object will be assigned those values and returned." } ] - }, + } + ], + "name": "Crafty.assignColor", + "categories": [ + "Graphics" + ] + }, + { + "file": "src/graphics/color.js", + "startLine": 149, + "endLine": 153, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nWorks like Crafty.bind, but will be unbound once the event triggers.\n" - }, - { - "type": "xref", - "xrefs": [ - "Crafty.bind" - ] + "value": "Draw a colored rectangle." } ], - "name": "Crafty.one", + "name": "Color", "categories": [ - "Core", - "Events" + "Graphics" ] }, { - "file": "src/core.js", - "startLine": 1586, - "endLine": 1614, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/color.js", + "startLine": 197, + "endLine": 231, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Boolean Crafty.unbind(String eventName, Function callback)", - "contents": [ - { - "type": "param", - "name": "eventName", - "description": "Name of the event to unbind" - }, + "type": "triggers", + "events": [ { - "type": "param", - "name": "callback", - "description": "Function to unbind" + "type": "trigger", + "event": "Invalidate", + "description": "when the color changes", + "objName": "Data", + "objProp": null } ] }, + { + "type": "raw", + "value": "Will assign the color and opacity, either through a string shorthand, or through explicit rgb values." + }, { "type": "method", - "signature": "public Boolean Crafty.unbind(String eventName, Number callbackID)", + "signature": "public this .color(String color[, Float strength])", "contents": [ { "type": "param", - "name": "callbackID", - "description": "ID of the callback" + "name": "color", + "description": "Color of the rectangle" }, { - "type": "return", - "value": "True or false depending on if a callback was unbound" + "type": "param", + "name": "strength", + "description": "the opacity of the rectangle" } ] }, { - "type": "raw", - "value": "Unbind any event from any entity or global event." - }, - { - "type": "example", + "type": "method", + "signature": "public this .color(r, g, b[, strength])", "contents": [ { - "type": "raw", - "value": "```\n var play_gameover_sound = function () {...};\n Crafty.bind('GameOver', play_gameover_sound);\n ...\n Crafty.unbind('GameOver', play_gameover_sound);\n```\n\nThe first line defines a callback function. The second line binds that\nfunction so that `Crafty.trigger('GameOver')` causes that function to\nrun. The third line unbinds that function.\n\n```\n Crafty.unbind('GameOver');\n```\n\nThis unbinds ALL global callbacks for the event 'GameOver'. That\nincludes all callbacks attached by `Crafty.bind('GameOver', ...)`, but\nnone of the callbacks attached by `some_entity.bind('GameOver', ...)`." - } + "type": "param", + "name": "r", + "description": "value for the red channel" + }, + { + "type": "param", + "name": "g", + "description": "value for the green channel" + }, + { + "type": "param", + "name": "b", + "description": "value for the blue channel" + }, + { + "type": "param", + "name": "strength", + "description": "the opacity of the rectangle" + } ] - } - ], - "name": "Crafty.unbind", - "categories": [ - "Core", - "Events" - ] - }, - { - "file": "src/core.js", - "startLine": 1643, - "endLine": 1647, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "method", - "signature": "public Number Crafty.frame(void)", - "contents": [] + "signature": "public String .color()", + "contents": [ + { + "type": "return", + "value": "A string representing the current color as a CSS property." + } + ] }, { - "type": "raw", - "value": "Returns the current frame number" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar c = Crafty.e(\"2D, DOM, Color\");\nc.color(\"#FF0000\");\nc.color(\"red\");\nc.color(255, 0, 0);\nc.color(\"rgb(255, 0, 0\")\n```\nThree different ways of assign the color red.\n```\nvar c = Crafty.e(\"2D, DOM, Color\");\nc.color(\"#00FF00\", 0.5);\nc.color(\"rgba(0, 255, 0, 0.5)\");\n```\nTwo ways of assigning a transparent green color." + } + ] } ], - "name": "Crafty.frame", - "categories": [ - "Core" - ] + "name": ".color", + "comp": "Color" }, { - "file": "src/core.js", - "startLine": 1669, - "endLine": 1672, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom-helper.js", + "startLine": 5, + "endLine": 10, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Modify the inner workings of Crafty through the settings." + "value": "Collection of utilities for using the DOM." } ], - "name": "Crafty.settings", + "name": "Crafty.domHelper", "categories": [ - "Core" + "Graphics" ] }, { - "file": "src/core.js", - "startLine": 1679, - "endLine": 1688, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom-helper.js", + "startLine": 12, + "endLine": 21, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.settings.register(String settingName, Function callback)", + "signature": "public Object Crafty.domHelper.innerPosition(HTMLElement obj)", "contents": [ { "type": "param", - "name": "settingName", - "description": "Name of the setting" + "name": "obj", + "description": "HTML element to calculate the position" }, { - "type": "param", - "name": "callback", - "description": "Function to execute when use modifies setting" + "type": "return", + "value": "Object with `x` key being the `x` position, `y` being the `y` position" } ] }, { "type": "raw", - "value": "\nUse this to register custom settings. Callback will be executed when `Crafty.settings.modify` is used.\n" - }, - { - "type": "xref", - "xrefs": [ - "Crafty.settings.modify" - ] + "value": "Find a DOM elements position including\npadding and border." } ], - "name": "Crafty.settings.register", - "comp": "Crafty.settings" + "name": "Crafty.domHelper.innerPosition", + "comp": "Crafty.domHelper" }, { - "file": "src/core.js", - "startLine": 1694, - "endLine": 1703, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom-helper.js", + "startLine": 40, + "endLine": 49, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.settings.modify(String settingName, * value)", + "signature": "public Object Crafty.domHelper.getStyle(HTMLElement obj, String property)", "contents": [ { "type": "param", - "name": "settingName", - "description": "Name of the setting" + "name": "obj", + "description": "HTML element to find the style" }, { "type": "param", - "name": "value", - "description": "Value to set the setting to" + "name": "property", + "description": "Style to return" } ] }, { "type": "raw", - "value": "\nModify settings through this method.\n" - }, - { - "type": "xref", - "xrefs": [ - "Crafty.settings.register", - "Crafty.settings.get" - ] + "value": "Determine the value of a style on an HTML element. Notation can be\nin either CSS or JS." } ], - "name": "Crafty.settings.modify", - "comp": "Crafty.settings" + "name": "Crafty.domHelper.getStyle", + "comp": "Crafty.domHelper" }, { - "file": "src/core.js", - "startLine": 1711, - "endLine": 1720, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom-helper.js", + "startLine": 79, + "endLine": 91, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public * Crafty.settings.get(String settingName)", + "signature": "public Object Crafty.domHelper.translate(Number clientX, Number clientY)", "contents": [ { "type": "param", - "name": "settingName", - "description": "Name of the setting" + "name": "clientX", + "description": "clientX position in the browser screen" + }, + { + "type": "param", + "name": "clientY", + "description": "clientY position in the browser screen" }, { "type": "return", - "value": "Current value of the setting" + "value": "Object `{x: ..., y: ...}` with Crafty coordinates." } ] }, { "type": "raw", - "value": "\nReturns the current value of the setting.\n" - }, - { - "type": "xref", - "xrefs": [ - "Crafty.settings.register", - "Crafty.settings.get" - ] + "value": "The parameters clientX and clientY are pixel coordinates within the visible\nbrowser window. This function translates those to Crafty coordinates (i.e.,\nthe coordinates that you might apply to an entity), by taking into account\nwhere the stage is within the screen, what the current viewport is, etc." } ], - "name": "Crafty.settings.get", - "comp": "Crafty.settings" + "name": "Crafty.domHelper.translate", + "comp": "Crafty.domHelper" }, { - "file": "src/core.js", - "startLine": 1744, - "endLine": 1750, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom-layer.js", + "startLine": 5, + "endLine": 10, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public Object .clone(Object obj)", - "contents": [ - { - "type": "param", - "name": "obj", - "description": "an object" - } - ] - }, { "type": "raw", - "value": "\nDeep copy (a.k.a clone) of an object." + "value": "Collection of mostly private methods to represent entities using the DOM." } ], - "name": "Crafty.clone", + "name": "Crafty.domLayer", "categories": [ - "Core" + "Graphics" ] }, { - "file": "src/device.js", - "startLine": 5, - "endLine": 7, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [], - "name": "Crafty.device", - "categories": [ - "Misc" - ] + "file": "src/graphics/dom-layer.js", + "startLine": 64, + "endLine": 68, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public Crafty.domLayer.debug()", + "contents": [] + } + ], + "name": "Crafty.domLayer.debug", + "comp": "Crafty.domLayer" }, { - "file": "src/device.js", - "startLine": 81, - "endLine": 105, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom-layer.js", + "startLine": 74, + "endLine": 82, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Crafty.device.deviceOrientation(Function callback)", - "contents": [ - { - "type": "param", - "name": "callback", - "description": "Callback method executed once as soon as device orientation is change" - } - ] + "signature": "public Crafty.domLayer.render()", + "contents": [] }, { "type": "raw", - "value": "\nDo something with normalized device orientation data:\n```\n{\n 'tiltLR' : 'gamma the angle in degrees the device is tilted left-to-right.',\n 'tiltFB' : 'beta the angle in degrees the device is tilted front-to-back',\n 'dir' : 'alpha the direction the device is facing according to the compass',\n 'motUD' : 'The angles values increase as you tilt the device to the right or towards you.'\n}\n```\n" + "value": "When \"RenderScene\" is triggered, draws all DOM entities that have been flagged\n" }, { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\n// Get DeviceOrientation event normalized data.\nCrafty.device.deviceOrientation(function(data){\n console.log('data.tiltLR : '+Math.round(data.tiltLR)+', data.tiltFB : '+Math.round(data.tiltFB)+', data.dir : '+Math.round(data.dir)+', data.motUD : '+data.motUD+'');\n});\n```\n\nSee browser support at http://caniuse.com/#search=device orientation." - } + "type": "xref", + "xrefs": [ + "DOM#.draw" ] } ], - "name": "Crafty.device.deviceOrientation", - "comp": "Crafty.device" + "name": "Crafty.domLayer._render", + "comp": "Crafty.domLayer" }, { - "file": "src/device.js", - "startLine": 120, - "endLine": 145, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom-layer.js", + "startLine": 107, + "endLine": 114, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Crafty.device.deviceMotion(Function callback)", + "signature": "public Crafty.domLayer.add(ent)", "contents": [ { "type": "param", - "name": "callback", - "description": "Callback method executed once as soon as device motion is change" + "name": "ent", + "description": "The entity to add" } ] }, { "type": "raw", - "value": "\nDo something with normalized device motion data:\n```\n{\n 'acceleration' : ' Grab the acceleration including gravity from the results',\n 'rawAcceleration' : 'Display the raw acceleration data',\n 'facingUp' : 'Z is the acceleration in the Z axis, and if the device is facing up or down',\n 'tiltLR' : 'Convert the value from acceleration to degrees. acceleration.x is the acceleration according to gravity, we'll assume we're on Earth and divide by 9.81 (earth gravity) to get a percentage value, and then multiply that by 90 to convert to degrees.',\n 'tiltFB' : 'Convert the value from acceleration to degrees.'\n}\n```\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\n// Get DeviceMotion event normalized data.\nCrafty.device.deviceMotion(function(data){\n console.log('data.moAccel : '+data.rawAcceleration+', data.moCalcTiltLR : '+Math.round(data.tiltLR)+', data.moCalcTiltFB : '+Math.round(data.tiltFB)+'');\n});\n```\n\nSee browser support at http://caniuse.com/#search=motion." - } - ] + "value": "Add an entity to the list of DOM object to draw" } ], - "name": "Crafty.device.deviceMotion", - "comp": "Crafty.device" + "name": "Crafty.domLayer.add", + "comp": "Crafty.domLayer" }, { - "file": "src/diamondiso.js", - "startLine": 5, - "endLine": 8, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom.js", + "startLine": 4, + "endLine": 9, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Place entities in a 45deg diamond isometric fashion. It is similar to isometric but has another grid locations" + "value": "A component which renders entities as DOM nodes, specifically `
    `s." } ], - "name": "Crafty.diamondIso", + "name": "DOM", "categories": [ - "2D" + "Graphics" ] }, { - "file": "src/diamondiso.js", - "startLine": 27, - "endLine": 45, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom.js", + "startLine": 11, + "endLine": 15, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this Crafty.diamondIso.init(Number tileWidth,Number tileHeight,Number mapWidth,Number mapHeight)", - "contents": [ - { - "type": "param", - "name": "tileWidth", - "description": "The size of base tile width in Pixel" - }, - { - "type": "param", - "name": "tileHeight", - "description": "The size of base tile height in Pixel" - }, - { - "type": "param", - "name": "mapWidth", - "description": "The width of whole map in Tiles" - }, - { - "type": "param", - "name": "mapHeight", - "description": "The height of whole map in Tiles" - } - ] - }, { "type": "raw", - "value": "\nMethod used to initialize the size of the isometric placement.\nRecommended to use a size alues in the power of `2` (128, 64 or 32).\nThis makes it easy to calculate positions and implement zooming.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nvar iso = Crafty.diamondIso.init(64,128,20,20);\n```\n" - } - ] - }, + "value": "The DOM element used to represent the entity." + } + ], + "name": "._element", + "comp": "DOM" + }, + { + "file": "src/graphics/dom.js", + "startLine": 20, + "endLine": 24, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { - "type": "xref", - "xrefs": [ - "Crafty.diamondIso.place" - ] + "type": "raw", + "value": "Avoids using of CSS 3D Transform for positioning when true. Default value is false." } ], - "name": "Crafty.diamondIso.init", - "comp": "Crafty.diamondIso" + "name": ".avoidCss3dTransforms", + "comp": "DOM" }, { - "file": "src/diamondiso.js", - "startLine": 58, - "endLine": 75, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom.js", + "startLine": 65, + "endLine": 71, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.diamondIso.place(Entity tile,Number x, Number y, Number layer)", - "contents": [ - { - "type": "param", - "name": "x", - "description": "The `x` position to place the tile" - }, - { - "type": "param", - "name": "y", - "description": "The `y` position to place the tile" - }, - { - "type": "param", - "name": "layer", - "description": "The `z` position to place the tile (calculated by y position * layer)" - }, - { - "type": "param", - "name": "tile", - "description": "The entity that should be position in the isometric fashion" - } - ] - }, - { - "type": "raw", - "value": "\nUse this method to place an entity in an isometric grid.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nvar iso = Crafty.diamondIso.init(64,128,20,20);\nisos.place(Crafty.e('2D, DOM, Color').color('red').attr({w:128, h:128}),1,1,2);\n```\n" - } - ] + "signature": "public this .getId()", + "contents": [] }, - { - "type": "xref", - "xrefs": [ - "Crafty.diamondIso.size" - ] - } - ], - "name": "Crafty.diamondIso.place", - "comp": "Crafty.diamondIso" - }, - { - "file": "src/drawing.js", - "startLine": 5, - "endLine": 8, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "raw", - "value": "Draw an image with or without repeating (tiling)." + "value": "Get the Id of the DOM element used to represent the entity." } ], - "name": "Image", - "categories": [ - "Graphics" - ] + "name": ".getDomId", + "comp": "DOM" }, { - "file": "src/drawing.js", - "startLine": 41, - "endLine": 69, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom.js", + "startLine": 109, + "endLine": 117, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "triggers", "events": [ { "type": "trigger", - "event": "Invalidate", - "description": "when the image is loaded", + "event": "Draw", + "description": "when the entity is ready to be drawn to the stage", "objName": "Data", - "objProp": null + "objProp": "{ style:String, type:\"DOM\", co}" } ] }, { "type": "method", - "signature": "public this .image(String url[, String repeat])", + "signature": "public this .DOM(HTMLElement elem)", "contents": [ { "type": "param", - "name": "url", - "description": "URL of the image" - }, - { - "type": "param", - "name": "repeat", - "description": "If the image should be repeated to fill the entity." + "name": "elem", + "description": "HTML element that will replace the dynamically created one" } ] }, { "type": "raw", - "value": "\nDraw specified image. Repeat follows CSS syntax (`\"no-repeat\", \"repeat\", \"repeat-x\", \"repeat-y\"`);\n\n*Note: Default repeat is `no-repeat` which is different to standard DOM (which is `repeat`)*\n\nIf the width and height are `0` and repeat is set to `no-repeat` the width and\nheight will automatically assume that of the image. This is an\neasy way to create an image without needing sprites.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "Will default to no-repeat. Entity width and height will be set to the images width and height\n```\nvar ent = Crafty.e(\"2D, DOM, Image\").image(\"myimage.png\");\n```\nCreate a repeating background.\n```\nvar bg = Crafty.e(\"2D, DOM, Image\")\n .attr({w: Crafty.viewport.width, h: Crafty.viewport.height})\n .image(\"bg.png\", \"repeat\");\n```\n" - } - ] - }, - { - "type": "xref", - "xrefs": [ - "Crafty.sprite" - ] + "value": "Pass a DOM element to use rather than one created. Will set `._element` to this value. Removes the old element." } ], - "name": ".image", - "comp": "Image" + "name": ".DOM", + "comp": "DOM" }, { - "file": "src/drawing.js", - "startLine": 112, - "endLine": 118, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom.js", + "startLine": 127, + "endLine": 133, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "Crafty.DrawManager", + "signature": "public this .draw(void)", "contents": [] }, { "type": "raw", - "value": "\nAn internal object manage objects to be drawn and implement\nthe best method of drawing in both DOM and canvas" + "value": "Updates the CSS properties of the node to draw on the stage." } ], - "name": "Crafty.DrawManager", - "categories": [ - "Graphics" - ] + "name": ".draw", + "comp": "DOM" }, { - "file": "src/drawing.js", - "startLine": 212, - "endLine": 216, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom.js", + "startLine": 219, + "endLine": 225, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this .undraw(void)", + "contents": [] + }, { "type": "raw", - "value": "\nTotal number of the entities that have the `2D` component." + "value": "Removes the element from the stage." } ], - "name": "Crafty.DrawManager.total2D", - "comp": "Crafty.DrawManager" + "name": ".undraw", + "comp": "DOM" }, { - "file": "src/drawing.js", - "startLine": 220, - "endLine": 226, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/dom.js", + "startLine": 234, + "endLine": 263, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Crafty.DrawManager.onScreen(Object rect)", + "signature": "public css(String property, String value)", "contents": [ { "type": "param", - "name": "rect", - "description": "A rectangle with field {_x: x_val, _y: y_val, _w: w_val, _h: h_val}" + "name": "property", + "description": "CSS property to modify" + }, + { + "type": "param", + "name": "value", + "description": "Value to give the CSS property" } ] }, - { - "type": "raw", - "value": "\nTest if a rectangle is completely in viewport" - } - ], - "name": "Crafty.DrawManager.onScreen", - "comp": "Crafty.DrawManager" - }, - { - "file": "src/drawing.js", - "startLine": 233, - "endLine": 244, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public Object Crafty.DrawManager.mergeSet(Object set)", + "signature": "public css(Object map)", "contents": [ { "type": "param", - "name": "set", - "description": "an array of rectangular regions" + "name": "map", + "description": "Object where the key is the CSS property and the value is CSS value" } ] }, { "type": "raw", - "value": "\nMerge any consecutive, overlapping rects into each other.\nIts an optimization for the redraw regions.\n\nThe order of set isn't strictly meaningful,\nbut overlapping objects will often cause each other to change,\nand so might be consecutive." - } - ], - "name": "Crafty.DrawManager.mergeSet", - "comp": "Crafty.DrawManager" - }, - { - "file": "src/drawing.js", - "startLine": 263, - "endLine": 269, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "value": "Apply CSS styles to the element.\n\nCan pass an object where the key is the style property and the value is style value.\n\nFor setting one style, simply pass the style as the first argument and the value as the second.\n\nThe notation can be CSS or JS (e.g. `text-align` or `textAlign`).\n\nTo return a value, pass the property.\n\nNote: For entities with \"Text\" component, some css properties are controlled by separate functions\n`.textFont()` and `.textColor()`, and ignore `.css()` settings. See Text component for details.\n" + }, { - "type": "method", - "signature": "public Crafty.DrawManager.addCanvas(ent)", + "type": "example", "contents": [ { - "type": "param", - "name": "ent", - "description": "The entity to add" + "type": "raw", + "value": "```\nthis.css({'text-align': 'center', 'text-decoration': 'line-through'});\nthis.css(\"textAlign\", \"center\");\nthis.css(\"text-align\"); //returns center\n```" } ] - }, - { - "type": "raw", - "value": "\nAdd an entity to the list of Canvas objects to draw" } ], - "name": "Crafty.DrawManager.addCanvas", - "comp": "Crafty.DrawManager" + "name": ".css", + "comp": "DOM" }, { - "file": "src/drawing.js", - "startLine": 275, - "endLine": 281, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/drawing.js", + "startLine": 4, + "endLine": 39, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Crafty.DrawManager.addDom(ent)", + "signature": "public void Crafty.pixelart(Boolean enabled)", "contents": [ { "type": "param", - "name": "ent", - "description": "The entity to add" + "name": "enabled", + "description": "whether to preserve sharp edges when rendering images" } ] }, { "type": "raw", - "value": "\nAdd an entity to the list of DOM object to draw" + "value": "Sets the image smoothing for drawing images (for all layer types).\n\nSetting this to true disables smoothing for images, which is the preferred\nway for drawing pixel art. Defaults to false.\n\nThis feature is experimental and you should be careful with cross-browser compatibility.\nThe best way to disable image smoothing is to use the Canvas render method and the Sprite component for drawing your entities.\n\nIf you want to switch modes in the middle of a scene,\nbe aware that canvas entities won't be drawn in the new style until something else invalidates them.\n(You can manually invalidate all canvas entities with `Crafty(\"Canvas\").trigger(\"Invalidate\");`)\n" + }, + { + "type": "note", + "value": "Firefox_26 currently has a [bug](https://bugzilla.mozilla.org/show_bug.cgi?id=696630) which prevents disabling image smoothing for Canvas entities that use the Image component. Use the Sprite component instead." + }, + { + "type": "note", + "value": "Webkit (Chrome & Safari) currently has a bug [link1](http://code.google.com/p/chromium/issues/detail?id=134040) [link2](http://code.google.com/p/chromium/issues/detail?id=106662) that prevents disabling image smoothing for DOM entities." + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "This is the preferred way to draw pixel art with the best cross-browser compatibility.\n```\nCrafty.canvasLayer.init();\nCrafty.pixelart(true);\n\nCrafty.sprite(imgWidth, imgHeight, \"spriteMap.png\", {sprite1:[0,0]});\nCrafty.e(\"2D, Canvas, sprite1\");\n```" + } + ] } ], - "name": "Crafty.DrawManager.addDom", - "comp": "Crafty.DrawManager" + "name": "Crafty.pixelart", + "categories": [ + "Graphics" + ] }, { - "file": "src/drawing.js", - "startLine": 287, - "endLine": 290, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/html.js", + "startLine": 4, + "endLine": 11, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Crafty.DrawManager.debug()", - "contents": [] + "type": "raw", + "value": "A component which allows for the insertion of arbitrary HTML into a DOM entity.\n\nAdding this to an entity will automatically add the `DOM` component." } ], - "name": "Crafty.DrawManager.debug", - "comp": "Crafty.DrawManager" + "name": "HTML", + "categories": [ + "Graphics" + ] }, { - "file": "src/drawing.js", - "startLine": 296, - "endLine": 303, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/html.js", + "startLine": 19, + "endLine": 34, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Crafty.DrawManager.drawAll([Object rect])", + "signature": "public this .replace(String html)", "contents": [ { "type": "param", - "name": "rect", - "description": "a rectangular region {_x: x_val, _y: y_val, _w: w_val, _h: h_val}" + "name": "html", + "description": "arbitrary html" } ] }, { "type": "raw", - "value": "\n- If rect is omitted, redraw within the viewport\n- If rect is provided, redraw within the rect" + "value": "This method will replace the content of this entity with the supplied html\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Create a link\n```\nCrafty.e(\"HTML\")\n .attr({x:20, y:20, w:100, h:100})\n .replace(\"Index\");\n```" + } + ] } ], - "name": "Crafty.DrawManager.drawAll", - "comp": "Crafty.DrawManager" + "name": ".replace", + "comp": "HTML" }, { - "file": "src/drawing.js", - "startLine": 326, - "endLine": 333, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/html.js", + "startLine": 41, + "endLine": 56, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Crafty.DrawManager.boundingRect(set)", + "signature": "public this .append(String html)", "contents": [ { "type": "param", - "name": "set", - "description": "Undocumented" + "name": "html", + "description": "arbitrary html" } ] }, { "type": "raw", - "value": "\n- Calculate the common bounding rect of multiple canvas entities.\n- Returns coords" + "value": "This method will add the supplied html in the end of the entity\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Create a link\n```\nCrafty.e(\"HTML\")\n .attr({x:20, y:20, w:100, h:100})\n .append(\"Index\");\n```" + } + ] } ], - "name": "Crafty.DrawManager.boundingRect", - "comp": "Crafty.DrawManager" + "name": ".append", + "comp": "HTML" }, { - "file": "src/drawing.js", - "startLine": 365, - "endLine": 375, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/html.js", + "startLine": 63, + "endLine": 78, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Crafty.DrawManager.renderCanvas()", - "contents": [] + "signature": "public this .prepend(String html)", + "contents": [ + { + "type": "param", + "name": "html", + "description": "arbitrary html" + } + ] }, { "type": "raw", - "value": "\n- Triggered by the \"RenderScene\" event\n- If the number of rects is over 60% of the total number of objects\n\tdo the naive method redrawing `Crafty.DrawManager.drawAll`\n- Otherwise, clear the dirty regions, and redraw entities overlapping the dirty regions.\n" + "value": "This method will add the supplied html in the beginning of the entity\n" }, { - "type": "xref", - "xrefs": [ - "Canvas.draw" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Create a link\n```\nCrafty.e(\"HTML\")\n .attr({x:20, y:20, w:100, h:100})\n .prepend(\"Index\");\n```" + } ] } ], - "name": "Crafty.DrawManager.renderCanvas", - "comp": "Crafty.DrawManager" + "name": ".prepend", + "comp": "HTML" }, { - "file": "src/drawing.js", - "startLine": 484, - "endLine": 491, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/image.js", + "startLine": 16, + "endLine": 20, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public Crafty.DrawManager.renderDOM()", - "contents": [] - }, { "type": "raw", - "value": "\nWhen \"RenderScene\" is triggered, draws all DOM entities that have been flagged\n" - }, - { - "type": "xref", - "xrefs": [ - "DOM.draw" - ] + "value": "Draw an image with or without repeating (tiling)." } ], - "name": "Crafty.DrawManager.renderDOM", - "comp": "Crafty.DrawManager" + "name": "Image", + "categories": [ + "Graphics" + ] }, { - "file": "src/drawing.js", - "startLine": 525, - "endLine": 556, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/image.js", + "startLine": 37, + "endLine": 69, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public void Crafty.pixelart(Boolean enabled)", - "contents": [] - }, + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Invalidate", + "description": "when the image is loaded", + "objName": "Data", + "objProp": null + } + ] + }, + { + "type": "method", + "signature": "public this .image(String url[, String repeat])", + "contents": [ + { + "type": "param", + "name": "url", + "description": "URL of the image" + }, + { + "type": "param", + "name": "repeat", + "description": "If the image should be repeated to fill the entity. This follows CSS syntax: (`\"no-repeat\", \"repeat\", \"repeat-x\", \"repeat-y\"`), but defaults to `no-repeat`." + } + ] + }, + { + "type": "raw", + "value": "Draw the specified image.\n" + }, + { + "type": "note", + "value": "The default value of repeat is `no-repeat`, which is different than the standard CSS default" + }, + { + "type": "raw", + "value": "If the width and height are `0` and repeat is set to `no-repeat` the width and\nheight will automatically assume that of the image. This is an\neasy way to create an image without needing sprites.\n\nIf set to `no-repeat` and given dimensions larger than that of the image,\nthe exact appearance will depend on what renderer (WebGL, DOM, or Canvas) is used.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Will default to no-repeat. Entity width and height will be set to the images width and height\n```\nvar ent = Crafty.e(\"2D, DOM, Image\").image(\"myimage.png\");\n```\nCreate a repeating background.\n```\nvar bg = Crafty.e(\"2D, DOM, Image\")\n .attr({w: Crafty.viewport.width, h: Crafty.viewport.height})\n .image(\"bg.png\", \"repeat\");\n```\n" + } + ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.sprite" + ] + } + ], + "name": ".image", + "comp": "Image" + }, + { + "file": "src/graphics/particles.js", + "startLine": 4, + "endLine": 14, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "ParticleEnd", + "description": "when the particle animation has finished", + "objName": "Data", + "objProp": null + } + ] + }, + { + "type": "raw", + "value": "Based on Parcycle by Mr. Speaker, licensed under the MIT, Ported by Leo Koppelkamm\n" + }, + { + "type": "note", + "value": "This requires the canvas element, and won't do anything if the browser doesn't support it!" + }, + { + "type": "raw", + "value": "For implementation details, check out the source code." + } + ], + "name": "Particles", + "categories": [ + "Graphics" + ] + }, + { + "file": "src/graphics/particles.js", + "startLine": 22, + "endLine": 64, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .particles(Object options)", + "contents": [ + { + "type": "param", + "name": "options", + "description": "Map of options that specify the behavior and look of the particles." + } + ] + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar options = {\n maxParticles: 150,\n size: 18,\n sizeRandom: 4,\n speed: 1,\n speedRandom: 1.2,\n // Lifespan in frames\n lifeSpan: 29,\n lifeSpanRandom: 7,\n // Angle is calculated clockwise: 12pm is 0deg, 3pm is 90deg etc.\n angle: 65,\n angleRandom: 34,\n startColour: [255, 131, 0, 1],\n startColourRandom: [48, 50, 45, 0],\n endColour: [245, 35, 0, 0],\n endColourRandom: [60, 60, 60, 0],\n // Only applies when fastMode is off, specifies how sharp the gradients are drawn\n sharpness: 20,\n sharpnessRandom: 10,\n // Random spread from origin\n spread: 10,\n // How many frames should this last\n duration: -1,\n // Will draw squares instead of circle gradients\n fastMode: false,\n gravity: { x: 0, y: 0.1 },\n // sensible values are 0-3\n jitter: 0,\n // Offset for the origin of the particles\n originOffset: {x: 0, y: 0}\n};\n\nCrafty.e(\"2D,Canvas,Particles\").particles(options);\n```" + } + ] + } + ], + "name": ".particles", + "comp": "Particles" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 4, + "endLine": 27, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "StartAnimation", + "description": "When an animation starts playing, or is resumed from the paused state", + "objName": "Data", + "objProp": "{Reel}" + }, + { + "type": "trigger", + "event": "AnimationEnd", + "description": "When the animation finishes", + "objName": "Data", + "objProp": "{ Reel }" + }, + { + "type": "trigger", + "event": "FrameChange", + "description": "Each time the frame of the current reel changes", + "objName": "Data", + "objProp": "{ Reel }" + }, + { + "type": "trigger", + "event": "ReelChange", + "description": "When the reel changes", + "objName": "Data", + "objProp": "{ Reel }" + } + ] + }, + { + "type": "raw", + "value": "Used to animate sprites by treating a sprite map as a set of animation frames.\nMust be applied to an entity that has a sprite-map component.\n\nTo define an animation, see the `reel` method. To play an animation, see the `animate` method.\n\nA reel is an object that contains the animation frames and current state for an animation. The reel object has the following properties:" + }, + { + "type": "param", + "name": "id: (String)", + "description": "the name of the reel" + }, + { + "type": "param", + "name": "frames: (Array)", + "description": "A list of frames in the format [xpos, ypos]" + }, + { + "type": "param", + "name": "currentFrame: (Number)", + "description": "The index of the current frame" + }, + { + "type": "param", + "name": "easing: (Crafty.easing object)", + "description": "The object that handles the internal progress of the animation." + }, + { + "type": "param", + "name": "duration: (Number)", + "description": "The duration in milliseconds." + }, + { + "type": "raw", + "value": "Many animation related events pass a reel object as data. As typical with events, this should be treated as read only data that might be later altered by the entity. If you wish to preserve the data, make a copy of it.\n" + }, + { + "type": "xref", + "xrefs": [ + "Crafty.sprite" + ] + } + ], + "name": "SpriteAnimation", + "categories": [ + "Animation" + ] + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 55, + "endLine": 60, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "The playback rate of the animation. This property defaults to 1." + } + ], + "name": ".animationSpeed", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 68, + "endLine": 117, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Used to define reels, to change the active reel, and to fetch the id of the active reel.\n" + }, + { + "type": "method", + "signature": "public this .reel(String reelId, Duration duration, Number fromX, Number fromY, Number frameCount)", + "contents": [ + { + "type": "raw", + "value": "Defines a reel by starting and ending position on the sprite sheet." + }, + { + "type": "param", + "name": "reelId", + "description": "ID of the animation reel being created" + }, + { + "type": "param", + "name": "duration", + "description": "The length of the animation in milliseconds." + }, + { + "type": "param", + "name": "fromX", + "description": "Starting `x` position on the sprite map (x's unit is the horizontal size of the sprite in the sprite map)." + }, + { + "type": "param", + "name": "fromY", + "description": "`y` position on the sprite map (y's unit is the horizontal size of the sprite in the sprite map). Remains constant through the animation." + }, + { + "type": "param", + "name": "frameCount", + "description": "The number of sequential frames in the animation. If negative, the animation will play backwards." + } + ] + }, + { + "type": "method", + "signature": "public this .reel(String reelId, Duration duration, Array frames)", + "contents": [ + { + "type": "raw", + "value": "Defines a reel by an explicit list of frames" + }, + { + "type": "param", + "name": "reelId", + "description": "ID of the animation reel being created" + }, + { + "type": "param", + "name": "duration", + "description": "The length of the animation in milliseconds." + }, + { + "type": "param", + "name": "frames", + "description": "An array of arrays containing the `x` and `y` values of successive frames: [[x1,y1],[x2,y2],...] (the values are in the unit of the sprite map's width/height respectively)." + } + ] + }, + { + "type": "method", + "signature": "public this .reel(String reelId)", + "contents": [ + { + "type": "raw", + "value": "Switches to the specified reel. The sprite will be updated to that reel's current frame" + }, + { + "type": "param", + "name": "reelID", + "description": "the ID to switch to" + } + ] + }, + { + "type": "method", + "signature": "public Reel .reel()", + "contents": [ + { + "type": "return", + "value": "The id of the current reel" + } + ] + }, + { + "type": "raw", + "value": "A method to handle animation reels. Only works for sprites built with the Crafty.sprite methods.\nSee the Tween component for animation of 2D properties.\n\nTo setup an animation reel, pass the name of the reel (used to identify the reel later), and either an\narray of absolute sprite positions or the start x on the sprite map, the y on the sprite map and then the end x on the sprite map.\n\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\n// Define a sprite-map component\nCrafty.sprite(16, \"images/sprite.png\", {\n PlayerSprite: [0,0]\n});\n\n// Define an animation on the second row of the sprite map (fromY = 1)\n// from the left most sprite (fromX = 0) to the fourth sprite\n// on that row (frameCount = 4), with a duration of 1 second\nCrafty.e(\"2D, DOM, SpriteAnimation, PlayerSprite\").reel('PlayerRunning', 1000, 0, 1, 4);\n\n// This is the same animation definition, but using the alternative method\nCrafty.e(\"2D, DOM, SpriteAnimation, PlayerSprite\").reel('PlayerRunning', 1000, [[0, 1], [1, 1], [2, 1], [3, 1]]);\n```" + } + ] + } + ], + "name": ".reel", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 180, + "endLine": 210, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .animate([String reelId] [, Number loopCount])", + "contents": [ + { + "type": "param", + "name": "reelId", + "description": "ID of the animation reel to play. Defaults to the current reel if none is specified." + }, + { + "type": "param", + "name": "loopCount", + "description": "Number of times to repeat the animation. Use -1 to repeat indefinitely. Defaults to 1." + } + ] + }, + { + "type": "raw", + "value": "Play one of the reels previously defined through `.reel(...)`. Simply pass the name of the reel. If you wish the\nanimation to play multiple times in succession, pass in the amount of times as an additional parameter.\nTo have the animation repeat indefinitely, pass in `-1`.\n\nIf another animation is currently playing, it will be paused.\n\nThis will always play an animation from the beginning. If you wish to resume from the current state of a reel, use `resumeAnimation()`.\n\nOnce an animation ends, it will remain at its last frame.\n\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\n// Define a sprite-map component\nCrafty.sprite(16, \"images/sprite.png\", {\n PlayerSprite: [0,0]\n});\n\n// Play the animation across 20 frames (so each sprite in the 4 sprite animation should be seen for 5 frames) and repeat indefinitely\nCrafty.e(\"2D, DOM, SpriteAnimation, PlayerSprite\")\n .reel('PlayerRunning', 20, 0, 0, 3) // setup animation\n .animate('PlayerRunning', -1); // start animation\n```" + } + ] + } + ], + "name": ".animate", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 252, + "endLine": 259, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .resumeAnimation()", + "contents": [] + }, + { + "type": "raw", + "value": "This will resume animation of the current reel from its current state.\nIf a reel is already playing, or there is no current reel, there will be no effect." + } + ], + "name": ".resumeAnimation", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 270, + "endLine": 276, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .pauseAnimation(void)", + "contents": [] + }, + { + "type": "raw", + "value": "Pauses the currently playing animation, or does nothing if no animation is playing." + } + ], + "name": ".pauseAnimation", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 286, + "endLine": 294, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .resetAnimation()", + "contents": [] + }, + { + "type": "raw", + "value": "Resets the current animation to its initial state. Resets the number of loops to the last specified value, which defaults to 1.\n\nNeither pauses nor resumes the current animation." + } + ], + "name": ".resetAnimation", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 305, + "endLine": 316, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .loops(Number loopCount)", + "contents": [ + { + "type": "param", + "name": "loopCount", + "description": "The number of times to play the animation" + } + ] + }, + { + "type": "raw", + "value": "Sets the number of times the animation will loop for.\nIf called while an animation is in progress, the current state will be considered the first loop.\n" + }, + { + "type": "method", + "signature": "public Number .loops()", + "contents": [ + { + "type": "return", + "value": "The number of loops left. Returns 0 if no reel is active." + } + ] + } + ], + "name": ".loops", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 335, + "endLine": 353, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .reelPosition(Integer position)", + "contents": [ + { + "type": "raw", + "value": "Sets the position of the current reel by frame number." + }, + { + "type": "param", + "name": "position", + "description": "the frame to jump to. This is zero-indexed. A negative values counts back from the last frame." + } + ] + }, + { + "type": "method", + "signature": "public this .reelPosition(Number position)", + "contents": [ + { + "type": "raw", + "value": "Sets the position of the current reel by percent progress." + }, + { + "type": "param", + "name": "position", + "description": "a non-integer number between 0 and 1" + } + ] + }, + { + "type": "method", + "signature": "public this .reelPosition(String position)", + "contents": [] + }, + { + "type": "raw", + "value": "Jumps to the specified position. The only currently accepted value is \"end\", which will jump to the end of the reel.\n" + }, + { + "type": "method", + "signature": "public Number .reelPosition()", + "contents": [ + { + "type": "return", + "value": "The current frame number" + } + ] + } + ], + "name": ".reelPosition", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 434, + "endLine": 449, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public Boolean .isPlaying([String reelId])", + "contents": [ + { + "type": "param", + "name": "reelId", + "description": "The reelId of the reel we wish to examine" + }, + { + "type": "return", + "value": "The current animation state" + } + ] + }, + { + "type": "raw", + "value": "Determines if the specified animation is currently playing. If no reelId is specified,\nchecks if any animation is playing.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nmyEntity.isPlaying() // is any animation playing\nmyEntity.isPlaying('PlayerRunning') // is the PlayerRunning animation playing\n```" + } + ] + } + ], + "name": ".isPlaying", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite-animation.js", + "startLine": 457, + "endLine": 467, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public Reel .getReel()", + "contents": [ + { + "type": "return", + "value": "The current reel, or null if there is no active reel" + } + ] + }, + { + "type": "method", + "signature": "public Reel .getReel(reelId)", + "contents": [ + { + "type": "param", + "name": "reelId", + "description": "The id of the reel to fetch." + }, + { + "type": "return", + "value": "The specified reel, or `undefined` if no such reel exists." + } + ] + } + ], + "name": ".getReel", + "comp": "SpriteAnimation" + }, + { + "file": "src/graphics/sprite.js", + "startLine": 17, + "endLine": 68, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this Crafty.sprite([Number tile, [Number tileh]], String url, Object map[, Number paddingX[, Number paddingY[, Boolean paddingAroundBorder]]])", + "contents": [ + { + "type": "param", + "name": "tile", + "description": "Tile size of the sprite map, defaults to 1" + }, + { + "type": "param", + "name": "tileh", + "description": "Height of the tile; if provided, tile is interpreted as the width" + }, + { + "type": "param", + "name": "url", + "description": "URL of the sprite image" + }, + { + "type": "param", + "name": "map", + "description": "Object where the key is what becomes a new component and the value points to a position on the sprite map" + }, + { + "type": "param", + "name": "paddingX", + "description": "Horizontal space in between tiles. Defaults to 0." + }, + { + "type": "param", + "name": "paddingY", + "description": "Vertical space in between tiles. Defaults to paddingX." + }, + { + "type": "param", + "name": "paddingAroundBorder", + "description": "If padding should be applied around the border of the sprite sheet. If enabled the first tile starts at (paddingX,paddingY) instead of (0,0). Defaults to false." + } + ] + }, + { + "type": "raw", + "value": "Generates components based on positions in a sprite image to be applied to entities.\n\nAccepts a tile size, URL and map for the name of the sprite and its position.\n\nThe position must be an array containing the position of the sprite where index `0`\nis the `x` position, `1` is the `y` position and optionally `2` is the width and `3`\nis the height. If the sprite map has padding, pass the values for the `x` padding\nor `y` padding. If they are the same, just add one value.\n\nIf the sprite image has no consistent tile size, `1` or no argument need be\npassed for tile size.\n\nEntities that add the generated components are also given the `2D` component, and\na component called `Sprite`.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.sprite(\"imgs/spritemap6.png\", {flower:[0,0,20,30]});\nvar flower_entity = Crafty.e(\"2D, DOM, flower\");\n```\nThe first line creates a component called `flower` associated with the sub-image of\nspritemap6.png with top-left corner (0,0), width 20 pixels, and height 30 pixels.\nThe second line creates an entity with that image. (Note: The `2D` is not really\nnecessary here, because adding the `flower` component automatically also adds the\n`2D` component.)\n```\nCrafty.sprite(50, \"imgs/spritemap6.png\", {flower:[0,0], grass:[0,1,3,1]});\n```\nIn this case, the `flower` component is pixels 0 <= x < 50, 0 <= y < 50, and the\n`grass` component is pixels 0 <= x < 150, 50 <= y < 100. (The `3` means grass has a\nwidth of 3 tiles, i.e. 150 pixels.)\n```\nCrafty.sprite(50, 100, \"imgs/spritemap6.png\", {flower:[0,0], grass:[0,1]}, 10);\n```\nIn this case, each tile is 50x100, and there is a spacing of 10 pixels between\nconsecutive tiles. So `flower` is pixels 0 <= x < 50, 0 <= y < 100, and `grass` is\npixels 0 <= x < 50, 110 <= y < 210.\n" + } + ] + }, + { + "type": "xref", + "xrefs": [ + "Sprite" + ] + } + ], + "name": "Crafty.sprite", + "categories": [ + "Graphics" + ] + }, + { + "file": "src/graphics/sprite.js", + "startLine": 160, + "endLine": 171, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Invalidate", + "description": "when the sprites change", + "objName": "Data", + "objProp": null + } + ] + }, + { + "type": "raw", + "value": "A component for using tiles in a sprite map.\n\nThis is automatically added to entities which use the components created by `Crafty.sprite` or `Crafty.load`.\nSince these are also used to define tile size, you'll rarely need to use this components methods directly.\n" + }, + { + "type": "xref", + "xrefs": [ + "Crafty.sprite", + "Crafty.load" + ] + } + ], + "name": "Sprite", + "categories": [ + "Graphics" + ] + }, + { + "file": "src/graphics/sprite.js", + "startLine": 256, + "endLine": 274, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .sprite(Number x, Number y[, Number w, Number h])", + "contents": [ + { + "type": "param", + "name": "x", + "description": "X cell position" + }, + { + "type": "param", + "name": "y", + "description": "Y cell position" + }, + { + "type": "param", + "name": "w", + "description": "Width in cells. Optional." + }, + { + "type": "param", + "name": "h", + "description": "Height in cells. Optional." + } + ] + }, + { + "type": "raw", + "value": "Uses a new location on the sprite map as its sprite. If w or h are ommitted, the width and height are not changed.\n\nValues should be in tiles or cells (not pixels).\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.e(\"2D, DOM, Sprite\")\n .sprite(0, 0, 2, 2);\n```" + } + ] + } + ], + "name": ".sprite", + "comp": "Sprite" + }, + { + "file": "src/graphics/sprite.js", + "startLine": 276, + "endLine": 281, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "The coordinate of the slide within the sprite in the format of [x, y, w, h]." + } + ], + "name": ".__coord", + "comp": "Sprite" + }, + { + "file": "src/graphics/sprite.js", + "startLine": 296, + "endLine": 314, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .crop(Number x, Number y, Number w, Number h)", + "contents": [ + { + "type": "param", + "name": "x", + "description": "Offset x position" + }, + { + "type": "param", + "name": "y", + "description": "Offset y position" + }, + { + "type": "param", + "name": "w", + "description": "New width" + }, + { + "type": "param", + "name": "h", + "description": "New height" + } + ] + }, + { + "type": "raw", + "value": "If the entity needs to be smaller than the tile size, use this method to crop it.\n\nThe values should be in pixels rather than tiles.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.e(\"2D, DOM, Sprite\")\n .crop(40, 40, 22, 23);\n```" + } + ] + } + ], + "name": ".crop", + "comp": "Sprite" + }, + { + "file": "src/graphics/text.js", + "startLine": 4, + "endLine": 26, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Invalidate", + "description": "when the text is changed", + "objName": "Data", + "objProp": null + } + ] + }, + { + "type": "raw", + "value": "By default, text will have the style \"10px sans-serif\".\n" + }, + { + "type": "note", + "value": "An entity with the text component is just text! If you want to write text inside an image, you need one entity for the text and another entity for the image. More tips for writing text inside an image: (1) Use the z-index (from 2D component) to ensure that the text is on top of the image, not the other way around; (2) use .attach() (from 2D component) to glue the text to the image so they move and rotate together." + }, + { + "type": "note", + "value": "For DOM (but not canvas) text entities, various font settings (like text-decoration and text-align) can be set using `.css()` (see DOM component). But you cannot use `.css()` to set the properties which are controlled by `.textFont()` or `.textColor()` -- the settings will be ignored." + }, + { + "type": "note", + "value": "If you use canvas text with glyphs that are taller than standard letters, portions of the glyphs might be cut off." + } + ], + "name": "Text", + "categories": [ + "Graphics" + ], + "requires": "Canvas or DOM Component to make a text entity." + }, + { + "file": "src/graphics/text.js", + "startLine": 98, + "endLine": 124, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .text(String text)", + "contents": [ + { + "type": "param", + "name": "text", + "description": "String of text that will be inserted into the DOM or Canvas element." + } + ] + }, + { + "type": "method", + "signature": "public this .text(Function textGenerator)", + "contents": [ + { + "type": "param", + "name": "textGenerator", + "description": "A function that returns a string. It will be immediately invoked in the context of the entity, with the result used as the text to display." + } + ] + }, + { + "type": "raw", + "value": "This method will update the text inside the entity.\n\nIf you need to reference attributes on the entity itself you can pass a function instead of a string.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.e(\"2D, DOM, Text\").attr({ x: 100, y: 100 }).text(\"Look at me!!\");\n\nCrafty.e(\"2D, DOM, Text\").attr({ x: 100, y: 100 })\n .text(function () { return \"My position is \" + this._x });\n\nCrafty.e(\"2D, Canvas, Text\").attr({ x: 100, y: 100 }).text(\"Look at me!!\");\n\nCrafty.e(\"2D, Canvas, Text\").attr({ x: 100, y: 100 })\n .text(function () { return \"My position is \" + this._x });\n```" + } + ] + } + ], + "name": ".text", + "comp": "Text" + }, + { + "file": "src/graphics/text.js", + "startLine": 155, + "endLine": 177, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public this .textColor(String color)", + "contents": [ + { + "type": "param", + "name": "color", + "description": "The color in name, hex, rgb or rgba" + } + ] + }, + { + "type": "raw", + "value": "Change the color of the text. You can use HEX, rgb and rgba colors.\n\nIf you want the text to be transparent, you should use rgba where you can define alphaChannel.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.e(\"2D, DOM, Text\").attr({ x: 100, y: 100 }).text(\"Look at me!!\")\n .textColor('#FF0000');\n\nCrafty.e(\"2D, Canvas, Text\").attr({ x: 100, y: 100 }).text('Look at me!!')\n .textColor('rgba(0, 255, 0, 0.5)');\n\nCrafty.e(\"2D, Canvas, Text\").attr({ x: 100, y: 100 }).text('Look at me!!')\n .textColor('white');\n```" + } + ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.assignColor" + ] + } + ], + "name": ".textColor", + "comp": "Text" + }, + { + "file": "src/graphics/text.js", + "startLine": 185, + "endLine": 208, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Invalidate", + "objName": "Data", + "objProp": null + } + ] + }, + { + "type": "method", + "signature": "public this .textFont(String key, * value)", + "contents": [ + { + "type": "param", + "name": "key", + "description": "Property of the entity to modify" + }, + { + "type": "param", + "name": "value", + "description": "Value to set the property to" + } + ] + }, + { + "type": "method", + "signature": "public this .textFont(Object map)", + "contents": [ + { + "type": "param", + "name": "map", + "description": "Object where the key is the property to modify and the value as the property value" + } + ] + }, + { + "type": "raw", + "value": "Use this method to set font property of the text entity. Possible values are: type, weight, size, family, lineHeight, and variant.\n\nWhen rendered by the canvas, lineHeight and variant will be ignored.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.e(\"2D, DOM, Text\").textFont({ type: 'italic', family: 'Arial' });\nCrafty.e(\"2D, Canvas, Text\").textFont({ size: '20px', weight: 'bold' });\n\nCrafty.e(\"2D, Canvas, Text\").textFont(\"type\", \"italic\");\nCrafty.e(\"2D, Canvas, Text\").textFont(\"type\"); // italic\n```" + } + ] + } + ], + "name": ".textFont", + "comp": "Text" + }, + { + "file": "src/graphics/text.js", + "startLine": 235, + "endLine": 251, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Invalidate", + "objName": "Data", + "objProp": null + } + ] + }, + { + "type": "method", + "signature": "public this .unselectable()", + "contents": [] + }, + { + "type": "raw", + "value": "This method sets the text so that it cannot be selected (highlighted) by dragging.\n(Canvas text can never be highlighted, so this only matters for DOM text.)\nWorks by changing the css property \"user-select\" and its variants.\n\nLikewise, this sets the mouseover cursor to be \"default\" (arrow), not \"text\" (I-beam)\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.e(\"2D, DOM, Text\").text('This text cannot be highlighted!').unselectable();\n```" + } + ] + } + ], + "name": ".unselectable", + "comp": "Text" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 5, + "endLine": 43, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "ViewportScroll", + "description": "when the viewport's x or y coordinates change", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "ViewportScale", + "description": "when the viewport's scale changes", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "ViewportResize", + "description": "when the viewport's dimension's change", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "InvalidateViewport", + "description": "when the viewport changes", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "StopCamera", + "description": "when any camera animations should stop, such as at the start of a new animation.", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "CameraAnimationDone", + "description": "when a camera animation reaches completion", + "objName": "Data", + "objProp": null + } + ] + }, + { + "type": "raw", + "value": "Viewport is essentially a 2D camera looking at the stage. Can be moved or zoomed, which\nin turn will react just like a camera moving in that direction.\n\nThere are multiple camera animation methods available - these are the viewport methods with an animation time parameter and the `follow` method.\nOnly one animation can run at a time. Starting a new animation will cancel the previous one and the appropriate events will be fired.\n\nTip: At any given moment, the stuff that you can see is...\n\n`x` between `(-Crafty.viewport._x)` and `(-Crafty.viewport._x + (Crafty.viewport._width / Crafty.viewport._scale))`\n\n`y` between `(-Crafty.viewport._y)` and `(-Crafty.viewport._y + (Crafty.viewport._height / Crafty.viewport._scale))`\n\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Prevent viewport from adjusting itself when outside the game world.\nScale the viewport so that entities appear twice as large.\nThen center the viewport on an entity over the duration of 3 seconds.\nAfter that animation finishes, start following the entity.\n```\nvar ent = Crafty.e('2D, DOM').attr({x: 250, y: 250, w: 100, h: 100});\n\nCrafty.viewport.clampToEntities = false;\nCrafty.viewport.scale(2);\nCrafty.one(\"CameraAnimationDone\", function() {\n Crafty.viewport.follow(ent, 0, 0);\n});\nCrafty.viewport.centerOn(ent, 3000);\n```" + } + ] + } + ], + "name": "Crafty.viewport", + "categories": [ + "Stage" + ] + }, + { + "file": "src/graphics/viewport.js", + "startLine": 45, + "endLine": 53, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Decides if the viewport functions should clamp to game entities.\nWhen set to `true` functions such as Crafty.viewport.mouselook() will not allow you to move the\nviewport over areas of the game that has no entities.\nFor development it can be useful to set this to false." + } + ], + "name": "Crafty.viewport.clampToEntities", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 57, + "endLine": 67, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Will move the stage and therefore every visible entity along the `x`\naxis in the opposite direction.\n\nWhen this value is set, it will shift the entire stage. This means that entity\npositions are not exactly where they are on screen. To get the exact position,\nsimply add `Crafty.viewport.x` onto the entities `x` position." + } + ], + "name": "Crafty.viewport.x", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 69, + "endLine": 79, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Will move the stage and therefore every visible entity along the `y`\naxis in the opposite direction.\n\nWhen this value is set, it will shift the entire stage. This means that entity\npositions are not exactly where they are on screen. To get the exact position,\nsimply add `Crafty.viewport.y` onto the entities `y` position." + } + ], + "name": "Crafty.viewport.y", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 82, + "endLine": 92, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "This value is the current scale (zoom) of the viewport. When the value is bigger than 1, everything\nlooks bigger (zoomed in). When the value is less than 1, everything looks smaller (zoomed out). This\ndoes not alter the size of the stage itself, just the magnification of what it shows.\n\nThis is a read-only property: Do not set it directly. Instead, use `Crafty.viewport.scale(...)`\nor `Crafty.viewport.zoom(...)`" + } + ], + "name": "Crafty.viewport._scale", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 96, + "endLine": 117, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "A rectangle which defines the bounds of the viewport.\nIt should be an object with two properties, `max` and `min`,\nwhich are each an object with `x` and `y` properties.\n\nIf this property is null, Crafty uses the bounding box of all the items\non the stage. This is the initial value. (To prevent this behavior, set `Crafty.viewport.clampToEntities` to `false`)\n\nIf you wish to bound the viewport along one axis but not the other, you can use `-Infinity` and `+Infinity` as bounds.\n" + }, + { + "type": "xref", + "xrefs": [ + "Crafty.viewport.clampToEntities" + ] + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Set the bounds to a 500 by 500 square:\n\n```\nCrafty.viewport.bounds = {min:{x:0, y:0}, max:{x:500, y:500}};\n```" + } + ] + } + ], + "name": "Crafty.viewport.bounds", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 120, + "endLine": 136, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "Crafty.viewport.scroll(String axis, Number val)", + "contents": [ + { + "type": "param", + "name": "axis", + "description": "'x' or 'y'" + }, + { + "type": "param", + "name": "val", + "description": "The new absolute position on the axis" + } + ] + }, + { + "type": "raw", + "value": "Will move the viewport to the position given on the specified axis\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "Will move the camera 500 pixels right of its initial position, in effect\nshifting everything in the viewport 500 pixels to the left.\n\n```\nCrafty.viewport.scroll('_x', 500);\n```" + } + ] + } + ], + "name": "Crafty.viewport.scroll", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 153, + "endLine": 170, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void Crafty.viewport.pan(Number dx, Number dy, Number time[, String|function easingFn])", + "contents": [ + { + "type": "param", + "name": "Number dx", + "description": "The distance along the x axis" + }, + { + "type": "param", + "name": "Number dy", + "description": "The distance along the y axis" + }, + { + "type": "param", + "name": "Number time", + "description": "The duration in ms for the entire camera movement" + }, + { + "type": "param", + "name": "easingFn", + "description": "A string or custom function specifying an easing. (Defaults to linear behavior.) See Crafty.easing for more information." + } + ] + }, + { + "type": "raw", + "value": "Pans the camera a given number of pixels over the specified time\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\n// pan the camera 100 px right and down over the duration of 2 seconds using linear easing behaviour\nCrafty.viewport.pan(100, 100, 2000);\n```" + } + ] + } + ], + "name": "Crafty.viewport.pan", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 216, + "endLine": 232, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void Crafty.viewport.follow(Object target, Number offsetx, Number offsety)", + "contents": [ + { + "type": "param", + "name": "Object target", + "description": "An entity with the 2D component" + }, + { + "type": "param", + "name": "Number offsetx", + "description": "Follow target's center should be offsetx pixels away from viewport's center. Positive values puts target to the right of the screen." + }, + { + "type": "param", + "name": "Number offsety", + "description": "Follow target's center should be offsety pixels away from viewport's center. Positive values puts target to the bottom of the screen." + } + ] + }, + { + "type": "raw", + "value": "Follows a given entity with the 2D component. If following target will take a portion of\nthe viewport out of bounds of the world, following will stop until the target moves away.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar ent = Crafty.e('2D, DOM').attr({w: 100, h: 100});\nCrafty.viewport.follow(ent, 0, 0);\n```" + } + ] + } + ], + "name": "Crafty.viewport.follow", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 269, + "endLine": 283, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void Crafty.viewport.centerOn(Object target, Number time)", + "contents": [ + { + "type": "param", + "name": "Object target", + "description": "An entity with the 2D component" + }, + { + "type": "param", + "name": "Number time", + "description": "The duration in ms of the camera motion" + } + ] + }, + { + "type": "raw", + "value": "Centers the viewport on the given entity.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar ent = Crafty.e('2D, DOM').attr({x: 250, y: 250, w: 100, h: 100});\nCrafty.viewport.centerOn(ent, 3000);\n```" + } + ] + } + ], + "name": "Crafty.viewport.centerOn", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 297, + "endLine": 316, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void Crafty.viewport.zoom(Number amt, Number cent_x, Number cent_y, Number time[, String|function easingFn])", + "contents": [ + { + "type": "param", + "name": "Number amt", + "description": "amount to zoom in on the target by (eg. 2, 4, 0.5)" + }, + { + "type": "param", + "name": "Number cent_x", + "description": "the center to zoom on" + }, + { + "type": "param", + "name": "Number cent_y", + "description": "the center to zoom on" + }, + { + "type": "param", + "name": "Number time", + "description": "the duration in ms of the entire zoom operation" + }, + { + "type": "param", + "name": "easingFn", + "description": "A string or custom function specifying an easing. (Defaults to linear behavior.) See Crafty.easing for more information." + } + ] + }, + { + "type": "raw", + "value": "Zooms the camera in on a given point. amt > 1 will bring the camera closer to the subject\namt < 1 will bring it farther away. amt = 0 will reset to the default zoom level\nZooming is multiplicative. To reset the zoom amount, pass 0.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\n// Make the entities appear twice as large by zooming in on the specified coordinates over the duration of 3 seconds using linear easing behavior\nCrafty.viewport.zoom(2, 100, 100, 3000);\n```" + } + ] + } + ], + "name": "Crafty.viewport.zoom", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 393, + "endLine": 414, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void Crafty.viewport.scale(Number amt)", + "contents": [ + { + "type": "param", + "name": "Number amt", + "description": "amount to zoom/scale in on the elements" + } + ] + }, + { + "type": "raw", + "value": "Adjusts the scale (zoom). When `amt` is 1, it is set to the normal scale,\ne.g. an entity with `this.w == 20` would appear exactly 20 pixels wide.\nWhen `amt` is 10, that same entity would appear 200 pixels wide (i.e., zoomed in\nby a factor of 10), and when `amt` is 0.1, that same entity would be 2 pixels wide\n(i.e., zoomed out by a factor of `(1 / 0.1)`).\n\nIf you pass an `amt` of 0, it is treated the same as passing 1, i.e. the scale is reset.\n\nThis method sets the absolute scale, while `Crafty.viewport.zoom` sets the scale relative to the existing value." + }, + { + "type": "xref", + "xrefs": [ + "Crafty.viewport.zoom" + ] + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.viewport.scale(2); // Zoom in -- all entities will appear twice as large.\n```" + } + ] + } + ], + "name": "Crafty.viewport.scale", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 423, + "endLine": 434, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void Crafty.viewport.mouselook(Boolean active)", + "contents": [ + { + "type": "param", + "name": "Boolean active", + "description": "Activate or deactivate mouselook" + } + ] + }, + { + "type": "raw", + "value": "Toggle mouselook on the current viewport.\nSimply call this function and the user will be able to\ndrag the viewport around.\n\nIf the user starts a drag, \"StopCamera\" will be triggered, which will cancel any existing camera animations." + } + ], + "name": "Crafty.viewport.mouselook", + "comp": "Crafty.viewport" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 513, + "endLine": 527, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void Crafty.viewport.init([Number width, Number height, String stage_elem])", + "contents": [] + }, + { + "type": "method", + "signature": "public void Crafty.viewport.init([Number width, Number height, HTMLElement stage_elem])", + "contents": [ + { + "type": "param", + "name": "Number width", + "description": "Width of the viewport" + }, + { + "type": "param", + "name": "Number height", + "description": "Height of the viewport" + }, + { + "type": "param", + "name": "String or HTMLElement stage_elem", + "description": "the element to use as the stage (either its id or the actual element)." + } + ] + }, { "type": "raw", - "value": "\nSets the image smoothing for drawing images (for both DOM and Canvas).\nSetting this to true disables smoothing for images, which is the preferred\nway for drawing pixel art. Defaults to false.\n\nThis feature is experimental and you should be careful with cross-browser compatibility.\nThe best way to disable image smoothing is to use the Canvas render method and the Sprite component for drawing your entities.\n\nIf you want to switch modes in the middle of a scene,\nbe aware that canvas entities won't be drawn in the new style until something else invalidates them.\n(You can manually invalidate all canvas entities with `Crafty(\"Canvas\").trigger(\"Invalidate\");`)\n\nNote that Firefox_26 currently has a [bug](https://bugzilla.mozilla.org/show_bug.cgi?id=696630)\nwhich prevents disabling image smoothing for Canvas entities that use the Image component. Use the Sprite\ncomponent instead.\nNote that Webkit (Chrome & Safari) currently has a bug [link1](http://code.google.com/p/chromium/issues/detail?id=134040)\n[link2](http://code.google.com/p/chromium/issues/detail?id=106662) that prevents disabling image smoothing\nfor DOM entities.\n" + "value": "Initialize the viewport. If the arguments 'width' or 'height' are missing, use `window.innerWidth` and `window.innerHeight` (full screen model).\n\nThe argument 'stage_elem' is used to specify a stage element other than the default, and can be either a string or an HTMLElement. If a string is provided, it will look for an element with that id and, if none exists, create a div. If an HTMLElement is provided, that is used directly. Omitting this argument is the same as passing an id of 'cr-stage'.\n" }, { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "This is the preferred way to draw pixel art with the best cross-browser compatibility.\n```\nCrafty.canvas.init();\nCrafty.pixelart(true);\n\nCrafty.sprite(imgWidth, imgHeight, \"spriteMap.png\", {sprite1:[0,0]});\nCrafty.e(\"2D, Canvas, sprite1\");\n```" - } + "type": "xref", + "xrefs": [ + "Crafty.device", + "Crafty.domHelper", + "Crafty.stage" ] } ], - "name": "Crafty.pixelart", - "categories": [ - "Graphics" - ] + "name": "Crafty.viewport.init", + "comp": "Crafty.viewport" }, { - "file": "src/extensions.js", - "startLine": 4, - "endLine": 7, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/viewport.js", + "startLine": 554, + "endLine": 558, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Determines feature support for what Crafty can do." + "value": "The stage where all the DOM entities will be placed." } ], - "name": "Crafty.support", + "name": "Crafty.stage", "categories": [ - "Misc", "Core" ] }, { - "file": "src/extensions.js", - "startLine": 18, - "endLine": 31, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/viewport.js", + "startLine": 560, + "endLine": 564, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "The `#cr-stage` div element." + } + ], + "name": "Crafty.stage.elem", + "comp": "Crafty.stage" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 566, + "endLine": 578, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nDetermines if Crafty is running on mobile device.\n\nIf Crafty.mobile is equal true Crafty does some things under hood:\n```\n- set viewport on max device width and height\n- set Crafty.stage.fullscreen on true\n- hide window scrollbars\n```\n" + "value": "`Crafty.domLayer._div` is a div inside the `#cr-stage` div that holds all DOM entities.\nIf you use canvas, a `canvas` element is created at the same level in the dom\nas the the `Crafty.domLayer._div` div. So the hierarchy in the DOM is\n\n```\nCrafty.stage.elem\n - Crafty.domLayer._div (a div HTMLElement)\n - Crafty.canvasLayer._canvas (a canvas HTMLElement)\n```" + } + ], + "name": "Crafty.domLayer._div", + "comp": "Crafty.domLayer" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 727, + "endLine": 737, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public Crafty.viewport.reload()", + "contents": [] }, { - "type": "xref", - "xrefs": [ - "Crafty.viewport" + "type": "raw", + "value": "Recalculate and reload stage width, height and position.\nUseful when browser return wrong results on init (like safari on Ipad2).\nYou should also call this method if you insert custom DOM elements that affect Crafty's stage offset.\n" + } + ], + "name": "Crafty.viewport.reload", + "comp": "Crafty.stage" + }, + { + "file": "src/graphics/viewport.js", + "startLine": 755, + "endLine": 764, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "StopCamera", + "description": "called to cancel camera animations", + "objName": "Data", + "objProp": null + } ] + }, + { + "type": "method", + "signature": "public Crafty.viewport.reset()", + "contents": [] + }, + { + "type": "raw", + "value": "Resets the viewport to starting values, and cancels any existing camera animations.\nCalled when scene() is run." } ], - "name": "Crafty.mobile", - "comp": "Crafty.device" + "name": "Crafty.viewport.reset", + "comp": "Crafty.stage" }, { - "file": "src/extensions.js", - "startLine": 35, - "endLine": 38, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/viewport.js", + "startLine": 774, + "endLine": 781, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public Crafty.viewport.onScreen(Object rect)", + "contents": [ + { + "type": "param", + "name": "rect", + "description": "A rectangle with field {_x: x_val, _y: y_val, _w: w_val, _h: h_val}" + } + ] + }, { "type": "raw", - "value": "Is `Object.defineProperty` supported?" + "value": "Test if a rectangle is completely in viewport" } ], - "name": "Crafty.support.defineProperty", - "comp": "Crafty.support" + "name": "Crafty.viewport.onScreen", + "comp": "Crafty.viewport" }, { - "file": "src/extensions.js", - "startLine": 50, - "endLine": 53, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/webgl.js", + "startLine": 175, + "endLine": 195, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Draw", + "description": "when the entity is ready to be drawn to the stage", + "objName": "Data", + "objProp": "{type: \"canvas\", pos, co, ctx}" + }, + { + "type": "trigger", + "event": "NoCanvas", + "description": "if the browser does not support canvas", + "objName": "Data", + "objProp": null + } + ] + }, { "type": "raw", - "value": "Is HTML5 `Audio` supported?" + "value": "When this component is added to an entity it will be drawn to the global webgl canvas element. Its canvas element (and hence any WebGL entity) is always rendered below any DOM entities.\n\nSprite, Image, SpriteAnimation, and Color all support WebGL rendering. Text entities will need to use DOM or Canvas for now.\n\nIf a webgl context does not yet exist, a WebGL entity will automatically create one by calling `Crafty.webgl.init()` before rendering.\n" + }, + { + "type": "note", + "value": "For better performance, minimize the number of spritesheets used, and try to arrange it so that entities with different spritesheets are on different z-levels. This is because entities are rendered in z order, and only entities sharing the same texture can be efficiently batched." + }, + { + "type": "raw", + "value": "Create a webgl entity like this\n```\nvar myEntity = Crafty.e(\"2D, WebGL, Color\")\n .color(1, 1, 0, 0.5)\n .attr({x: 13, y: 37, w: 42, h: 42});\n```" } ], - "name": "Crafty.support.audio", - "comp": "Crafty.support" + "name": "WebGL", + "categories": [ + "Graphics" + ] }, { - "file": "src/extensions.js", - "startLine": 57, - "endLine": 60, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/webgl.js", + "startLine": 198, + "endLine": 203, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Returns the browser specific prefix (`Moz`, `O`, `ms`, `webkit`)." + "value": "The webgl context this entity will be rendered to." } ], - "name": "Crafty.support.prefix", - "comp": "Crafty.support" + "name": ".context", + "comp": "WebGL" }, { - "file": "src/extensions.js", - "startLine": 69, - "endLine": 72, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/webgl.js", + "startLine": 242, + "endLine": 253, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this .draw([[Context ctx, ]Number x, Number y, Number w, Number h])", + "contents": [ + { + "type": "param", + "name": "ctx", + "description": "Optionally supply a different r 2D context if drawing on another canvas is required" + }, + { + "type": "param", + "name": "x", + "description": "X offset for drawing a segment" + }, + { + "type": "param", + "name": "y", + "description": "Y offset for drawing a segment" + }, + { + "type": "param", + "name": "w", + "description": "Width of the segment to draw" + }, + { + "type": "param", + "name": "h", + "description": "Height of the segment to draw" + } + ] + }, { "type": "raw", - "value": "Version of the browser" + "value": "An internal method to draw the entity on the webgl canvas element. Rather then rendering directly, it writes relevent information into a buffer to allow batch rendering." } ], - "name": "Crafty.support.versionName", - "comp": "Crafty.support" + "name": ".draw", + "comp": "WebGL" }, { - "file": "src/extensions.js", - "startLine": 76, - "endLine": 79, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/webgl.js", + "startLine": 338, + "endLine": 343, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Version number of the browser as an Integer (first number)" + "value": "A collection of methods to handle webgl contexts." } ], - "name": "Crafty.support.version", - "comp": "Crafty.support" + "name": "Crafty.webgl", + "categories": [ + "Graphics" + ] }, { - "file": "src/extensions.js", - "startLine": 84, - "endLine": 87, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/graphics/webgl.js", + "startLine": 347, + "endLine": 352, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Is the `canvas` element supported?" + "value": "This will return the context of the webgl canvas element." } ], - "name": "Crafty.support.canvas", - "comp": "Crafty.support" + "name": "Crafty.webgl.context", + "comp": "Crafty.webgl" + }, + { + "file": "src/graphics/webgl.js", + "startLine": 422, + "endLine": 432, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void Crafty.webgl.init(void)", + "contents": [] + }, + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "NoWebGL", + "description": "triggered if `Crafty.support.webgl` is false", + "objName": "Data", + "objProp": null + } + ] + }, + { + "type": "raw", + "value": "This will create a `canvas` element inside `Crafty.stage.elem`, used for displaying \"WebGL\" components.\n\nThis method will automatically be called by any \"WebGL\" component if no `Crafty.webgl.context` is\nfound, so it is not neccessary to call this manually." + } + ], + "name": "Crafty.webgl.init", + "comp": "Crafty.webgl" + }, + { + "file": "src/isometric/diamond-iso.js", + "startLine": 5, + "endLine": 11, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Place entities in a 45deg diamond isometric fashion. It is similar to isometric but has another grid locations\nIn this mode, the x axis and y axis are aligned to the edges of tiles with x increasing being down and to the\nright and y being down and to the left." + } + ], + "name": "Crafty.diamondIso", + "categories": [ + "2D" + ] }, { - "file": "src/extensions.js", - "startLine": 91, - "endLine": 94, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/isometric/diamond-iso.js", + "startLine": 32, + "endLine": 53, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "Is WebGL supported on the canvas element?" + "type": "method", + "signature": "public this Crafty.diamondIso.init(Number tileWidth,Number tileHeight,Number mapWidth,Number mapHeight)", + "contents": [ + { + "type": "param", + "name": "tileWidth", + "description": "The size of base tile width's grid space in Pixel" + }, + { + "type": "param", + "name": "tileHeight", + "description": "The size of base tile height grid space in Pixel" + }, + { + "type": "param", + "name": "mapWidth", + "description": "The width of whole map in Tiles" + }, + { + "type": "param", + "name": "mapHeight", + "description": "The height of whole map in Tiles" + }, + { + "type": "param", + "name": "x", + "description": "the x coordinate of the TOP corner of the 0,0 tile" + }, + { + "type": "param", + "name": "y", + "description": "the y coordinate of the TOP corner of the 0,0, tile" + } + ] + }, + { + "type": "raw", + "value": "Method used to initialize the size of the isometric placement.\nRecommended to use a size alues in the power of `2` (128, 64 or 32).\nThis makes it easy to calculate positions and implement zooming.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar iso = Crafty.diamondIso.init(64,128,20,20);\n```\n" + } + ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.diamondIso.place" + ] } ], - "name": "Crafty.support.webgl", - "comp": "Crafty.support" + "name": "Crafty.diamondIso.init", + "comp": "Crafty.diamondIso" }, { - "file": "src/extensions.js", - "startLine": 108, - "endLine": 111, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/isometric/diamond-iso.js", + "startLine": 72, + "endLine": 90, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this Crafty.diamondIso.place(Entity tile,Number x, Number y, Number layer)", + "contents": [ + { + "type": "param", + "name": "x", + "description": "The `x` position to place the tile" + }, + { + "type": "param", + "name": "y", + "description": "The `y` position to place the tile" + }, + { + "type": "param", + "name": "layer", + "description": "The `z` position to place the tile" + }, + { + "type": "param", + "name": "tile", + "description": "The entity that should be position in the isometric fashion" + } + ] + }, { "type": "raw", - "value": "Is css3Dtransform supported by browser." + "value": "Use this method to place an entity in an isometric grid.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar iso = Crafty.diamondIso.init(64,128,20,20);\nisos.place(Crafty.e('2D, DOM, Color').color('red').attr({w:128, h:128}),1,1,2);\n```\n" + } + ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.diamondIso.size" + ] } ], - "name": "Crafty.support.css3dtransform", - "comp": "Crafty.support" + "name": "Crafty.diamondIso.place", + "comp": "Crafty.diamondIso" }, { - "file": "src/extensions.js", - "startLine": 115, - "endLine": 118, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/isometric/isometric.js", + "startLine": 5, + "endLine": 12, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Is deviceorientation event supported by browser." + "value": "Place entities in a 45deg isometric fashion. The alignment of this\ngrid's axes for tile placement is 90 degrees. If you are looking\nto have the grid of tile indicies for this.place aligned to the tiles\nthemselves, use DiamondIso instead." } ], - "name": "Crafty.support.deviceorientation", - "comp": "Crafty.support" + "name": "Crafty.isometric", + "categories": [ + "2D" + ] }, { - "file": "src/extensions.js", - "startLine": 122, - "endLine": 125, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/isometric/isometric.js", + "startLine": 24, + "endLine": 40, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this Crafty.isometric.size(Number tileSize)", + "contents": [ + { + "type": "param", + "name": "tileSize", + "description": "The size of the tiles to place." + } + ] + }, { "type": "raw", - "value": "Is devicemotion event supported by browser." + "value": "Method used to initialize the size of the isometric placement.\nRecommended to use a size values in the power of `2` (128, 64 or 32).\nThis makes it easy to calculate positions and implement zooming.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar iso = Crafty.isometric.size(128);\n```\n" + } + ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.isometric.place" + ] } ], - "name": "Crafty.support.devicemotion", - "comp": "Crafty.support" + "name": "Crafty.isometric.size", + "comp": "Crafty.isometric" }, { - "file": "src/extensions.js", - "startLine": 134, - "endLine": 162, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/isometric/isometric.js", + "startLine": 46, + "endLine": 64, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.addEvent(Object ctx, HTMLElement obj, String event, Function callback)", + "signature": "public this Crafty.isometric.place(Number x, Number y, Number z, Entity tile)", "contents": [ { "type": "param", - "name": "ctx", - "description": "Context of the callback or the value of `this`" + "name": "x", + "description": "The `x` position to place the tile" }, { "type": "param", - "name": "obj", - "description": "Element to add the DOM event to" + "name": "y", + "description": "The `y` position to place the tile" }, { "type": "param", - "name": "event", - "description": "Event name to bind to" + "name": "z", + "description": "The `z` position or height to place the tile" }, { "type": "param", - "name": "callback", - "description": "Method to execute when triggered" + "name": "tile", + "description": "The entity that should be position in the isometric fashion" } ] }, { "type": "raw", - "value": "\nAdds DOM level 3 events to elements. The arguments it accepts are the call\ncontext (the value of `this`), the DOM element to attach the event to,\nthe event name (without `on` (`click` rather than `onclick`)) and\nfinally the callback method.\n\nIf no element is passed, the default element will be `window.document`.\n\nCallbacks are passed with event data.\n" + "value": "Use this method to place an entity in an isometric grid.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "Will add a stage-wide MouseDown event listener to the player. Will log which button was pressed\n& the (x,y) coordinates in viewport/world/game space.\n```\nvar player = Crafty.e(\"2D\");\n player.onMouseDown = function(e) {\n console.log(e.mouseButton, e.realX, e.realY);\n };\nCrafty.addEvent(player, Crafty.stage.elem, \"mousedown\", player.onMouseDown);\n```" + "value": "```\nvar iso = Crafty.isometric.size(128);\niso.place(2, 1, 0, Crafty.e('2D, DOM, Color').color('red').attr({w:128, h:128}));\n```\n" } ] }, { "type": "xref", "xrefs": [ - "Crafty.removeEvent" + "Crafty.isometric.size" ] } ], - "name": "Crafty.addEvent", - "categories": [ - "Events", - "Misc" - ] + "name": "Crafty.isometric.place", + "comp": "Crafty.isometric" }, { - "file": "src/extensions.js", - "startLine": 191, - "endLine": 204, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/isometric/isometric.js", + "startLine": 74, + "endLine": 89, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.removeEvent(Object ctx, HTMLElement obj, String event, Function callback)", + "signature": "public Object Crafty.isometric.pos2px(Number x,Number y)", "contents": [ { "type": "param", - "name": "ctx", - "description": "Context of the callback or the value of `this`" + "name": "x", + "description": "A position along the x axis" }, { "type": "param", - "name": "obj", - "description": "Element the event is on" + "name": "y", + "description": "A position along the y axis" }, + { + "type": "return", + "value": "An object with `left` and `top` fields {left Number,top Number}" + } + ] + }, + { + "type": "raw", + "value": "This method converts a position in x and y coordinates to one in pixels\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar iso = Crafty.isometric.size(128,96);\nvar position = iso.pos2px(100,100); //Object { left=12800, top=4800}\n```" + } + ] + } + ], + "name": "Crafty.isometric.pos2px", + "comp": "Crafty.isometric" + }, + { + "file": "src/isometric/isometric.js", + "startLine": 96, + "endLine": 112, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public Object Crafty.isometric.px2pos(Number left,Number top)", + "contents": [ { "type": "param", - "name": "event", - "description": "Name of the event" + "name": "top", + "description": "Offset from the top in pixels" }, { "type": "param", - "name": "callback", - "description": "Method executed when triggered" + "name": "left", + "description": "Offset from the left in pixels" + }, + { + "type": "return", + "value": "An object with `x` and `y` fields representing the position" } ] }, { "type": "raw", - "value": "\nRemoves events attached by `Crafty.addEvent()`. All parameters must\nbe the same that were used to attach the event including a reference\nto the callback method.\n" + "value": "This method converts a position in pixels to x,y coordinates\n" }, { - "type": "xref", - "xrefs": [ - "Crafty.addEvent" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar iso = Crafty.isometric.size(128,96);\nvar px = iso.pos2px(12800,4800);\nCrafty.log(px); //Object { x=100, y=100}\n```" + } + ] + } + ], + "name": "Crafty.isometric.px2pos", + "comp": "Crafty.isometric" + }, + { + "file": "src/isometric/isometric.js", + "startLine": 119, + "endLine": 138, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public Obect Crafty.isometric.centerAt()", + "contents": [ + { + "type": "return", + "value": "An object with `top` and `left` fields represneting the viewport's current center" + } + ] + }, + { + "type": "method", + "signature": "public this Crafty.isometric.centerAt(Number x, Number y)", + "contents": [ + { + "type": "param", + "name": "x", + "description": "The x position to center at" + }, + { + "type": "param", + "name": "y", + "description": "The y position to center at" + } + ] + }, + { + "type": "raw", + "value": "This method centers the Viewport at an `x,y` location or gives the current centerpoint of the viewport\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar iso = Crafty.isometric.size(128,96).centerAt(10,10); //Viewport is now moved\n//After moving the viewport by another event you can get the new center point\nCrafty.log(iso.centerAt());\n```" + } + ] + } + ], + "name": "Crafty.isometric.centerAt", + "comp": "Crafty.isometric" + }, + { + "file": "src/isometric/isometric.js", + "startLine": 152, + "endLine": 171, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public Object Crafty.isometric.area()", + "contents": [ + { + "type": "return", + "value": "An obect with `x` and `y` fields, each of which have a start and end field. In other words, the object has this structure: `{x:{start Number,end Number},y:{start Number,end Number}}`" + } + ] + }, + { + "type": "raw", + "value": "This method returns an object representing the bounds of the viewport\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar iso = Crafty.isometric.size(128,96).centerAt(10,10); //Viewport is now moved\nvar area = iso.area(); //get the area\nfor(var y = area.y.start;y <= area.y.end;y++){\n for(var x = area.x.start ;x <= area.x.end;x++){\n iso.place(x,y,0,Crafty.e(\"2D,DOM,gras\")); //Display tiles in the Screen\n }\n}\n```" + } ] } ], - "name": "Crafty.removeEvent", + "name": "Crafty.isometric.area", + "comp": "Crafty.isometric" + }, + { + "file": "src/sound/sound.js", + "startLine": 5, + "endLine": 16, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Add sound files and play them. Chooses best format for browser support.\nDue to the nature of HTML5 audio, three types of audio files will be\nrequired for cross-browser capabilities. These formats are MP3, Ogg and WAV.\nWhen sound was not muted on before pause, sound will be unmuted after unpause.\nWhen sound is muted Crafty.pause() does not have any effect on sound\n\nThe maximum number of sounds that can be played simultaneously is defined by Crafty.audio.maxChannels. The default value is 7." + } + ], + "name": "Crafty.audio", "categories": [ - "Events", - "Misc" + "Audio" ] }, { - "file": "src/extensions.js", - "startLine": 225, - "endLine": 240, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 53, + "endLine": 60, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.background(String value)", + "signature": "public this Crafty.audio.supports(String extension)", "contents": [ { "type": "param", - "name": "style", - "description": "Modify the background with a color or image" + "name": "extension", + "description": "A file extension to check audio support for" } ] }, { "type": "raw", - "value": "\nThis method is a shortcut for adding a background\nstyle to the stage element, i.e.\n`Crafty.stage.elem.style.background = ...`\n\nFor example, if you want the background to be white,\nwith an image in the center, you might use:\n```\nCrafty.background('#FFFFFF url(landscape.png) no-repeat center center');\n```\n" + "value": "Return true if the browser thinks it can play the given file type, otherwise false" } ], - "name": "Crafty.background", - "categories": [ - "Graphics", - "Stage" - ] + "name": "Crafty.audio.supports", + "comp": "Crafty.audio" }, { - "file": "src/html.js", - "startLine": 4, - "endLine": 7, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 80, + "endLine": 90, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public this Crafty.audio.create(String id, String url)", + "contents": [ + { + "type": "param", + "name": "id", + "description": "A string to refer to sounds" + }, + { + "type": "param", + "name": "url", + "description": "A string pointing to the sound file" + } + ] + }, { "type": "raw", - "value": "Component allow for insertion of arbitrary HTML into an entity" + "value": "Creates an audio asset with the given id and resource. `Crafty.audio.add` is a more flexible interface that allows cross-browser compatibility.\n\nIf the sound file extension is not supported, returns false; otherwise, returns the audio asset." } ], - "name": "HTML", - "categories": [ - "Graphics" - ] + "name": "Crafty.audio.create", + "comp": "Crafty.audio" }, { - "file": "src/html.js", - "startLine": 16, - "endLine": 30, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 115, + "endLine": 156, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .replace(String html)", + "signature": "public this Crafty.audio.add(String id, String url)", "contents": [ { "type": "param", - "name": "html", - "description": "arbitrary html" + "name": "id", + "description": "A string to refer to sounds" + }, + { + "type": "param", + "name": "url", + "description": "A string pointing to the sound file" } ] }, { - "type": "raw", - "value": "\nThis method will replace the content of this entity with the supplied html\n" - }, - { - "type": "example", + "type": "method", + "signature": "public this Crafty.audio.add(String id, Array urls)", "contents": [ { - "type": "raw", - "value": "Create a link\n```\nCrafty.e(\"HTML\")\n .attr({x:20, y:20, w:100, h:100})\n .replace(\"Index\");\n```" + "type": "param", + "name": "urls", + "description": "Array of urls pointing to different format of the same sound, selecting the first that is playable" } ] - } - ], - "name": ".replace", - "comp": "HTML" - }, - { - "file": "src/html.js", - "startLine": 38, - "endLine": 52, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "method", - "signature": "public this .append(String html)", + "signature": "public this Crafty.audio.add(Object map)", "contents": [ { "type": "param", - "name": "html", - "description": "arbitrary html" + "name": "map", + "description": "key-value pairs where the key is the `id` and the value is either a `url` or `urls`" } ] }, { "type": "raw", - "value": "\nThis method will add the supplied html in the end of the entity\n" + "value": "Loads a sound to be played. Due to the nature of HTML5 audio,\nthree types of audio files will be required for cross-browser capabilities.\nThese formats are MP3, Ogg and WAV.\n\nPassing an array of URLs will determine which format the browser can play and select it over any other.\n\nAccepts an object where the key is the audio name and\neither a URL or an Array of URLs (to determine which type to use).\n\nThe ID you use will be how you refer to that sound when using `Crafty.audio.play`.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "Create a link\n```\nCrafty.e(\"HTML\")\n .attr({x:20, y:20, w:100, h:100})\n .append(\"Index\");\n```" + "value": "```\n//adding audio from an object\nCrafty.audio.add({\n shoot: [\"sounds/shoot.wav\",\n \"sounds/shoot.mp3\",\n \"sounds/shoot.ogg\"]\n});\n\n//adding a single sound\nCrafty.audio.add(\"walk\", [\n\"sounds/walk.mp3\",\n\"sounds/walk.ogg\",\n\"sounds/walk.wav\"\n]);\n\n//only one format\nCrafty.audio.add(\"jump\", \"sounds/jump.mp3\");\n```" } ] } ], - "name": ".append", - "comp": "HTML" + "name": "Crafty.audio.add", + "comp": "Crafty.audio" }, { - "file": "src/html.js", - "startLine": 60, - "endLine": 74, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 190, + "endLine": 214, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .prepend(String html)", + "signature": "public this Crafty.audio.play(String id)", + "contents": [] + }, + { + "type": "method", + "signature": "public this Crafty.audio.play(String id, Number repeatCount)", + "contents": [] + }, + { + "type": "method", + "signature": "public this Crafty.audio.play(String id, Number repeatCount, Number volume)", "contents": [ { "type": "param", - "name": "html", - "description": "arbitrary html" + "name": "id", + "description": "A string to refer to sounds" + }, + { + "type": "param", + "name": "repeatCount", + "description": "Repeat count for the file, where -1 stands for repeat forever." + }, + { + "type": "param", + "name": "volume", + "description": "volume can be a number between 0.0 and 1.0" + }, + { + "type": "return", + "value": "The audio element used to play the sound. Null if the call failed due to a lack of open channels." } ] }, { "type": "raw", - "value": "\nThis method will add the supplied html in the beginning of the entity\n" + "value": "Will play a sound previously added by using the ID that was used in `Crafty.audio.add`.\nHas a default maximum of 5 channels so that the same sound can play simultaneously unless all of the channels are playing.\n\n*Note that the implementation of HTML5 Audio is buggy at best.*\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "Create a link\n```\nCrafty.e(\"HTML\")\n .attr({x:20, y:20, w:100, h:100})\n .prepend(\"Index\");\n```" + "value": "```\nCrafty.audio.play(\"walk\");\n\n//play and repeat forever\nCrafty.audio.play(\"backgroundMusic\", -1);\nCrafty.audio.play(\"explosion\",1,0.5); //play sound once with volume of 50%\n```" } ] } ], - "name": ".prepend", - "comp": "HTML" + "name": "Crafty.audio.play", + "comp": "Crafty.audio" }, { - "file": "src/isometric.js", - "startLine": 5, - "endLine": 8, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 260, + "endLine": 265, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "Place entities in a 45deg isometric fashion." + "type": "method", + "signature": "public this Crafty.audio.setChannels(Number n)", + "contents": [ + { + "type": "param", + "name": "n", + "description": "The maximum number of channels" + } + ] } ], - "name": "Crafty.isometric", - "categories": [ - "2D" - ] + "name": "Crafty.audio.setChannels", + "comp": "Crafty.audio" }, { - "file": "src/isometric.js", - "startLine": 21, - "endLine": 36, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 305, + "endLine": 320, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.isometric.size(Number tileSize)", + "signature": "public this Crafty.audio.remove([String id])", "contents": [ { "type": "param", - "name": "tileSize", - "description": "The size of the tiles to place." + "name": "id", + "description": "A string to refer to sounds" } ] }, { "type": "raw", - "value": "\nMethod used to initialize the size of the isometric placement.\nRecommended to use a size values in the power of `2` (128, 64 or 32).\nThis makes it easy to calculate positions and implement zooming.\n" + "value": "Will stop the sound and remove all references to the audio object allowing the browser to free the memory.\nIf no id is given, all sounds will be removed.\n\nThis function uses audio path set in Crafty.path in order to remove sound from the assets object.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar iso = Crafty.isometric.size(128);\n```\n" + "value": "```\nCrafty.audio.remove(\"walk\");\n```" } ] - }, - { - "type": "xref", - "xrefs": [ - "Crafty.isometric.place" - ] } ], - "name": "Crafty.isometric.size", - "comp": "Crafty.isometric" + "name": "Crafty.audio.remove", + "comp": "Crafty.audio" }, { - "file": "src/isometric.js", - "startLine": 43, - "endLine": 60, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 348, + "endLine": 361, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.isometric.place(Number x, Number y, Number z, Entity tile)", - "contents": [ - { - "type": "param", - "name": "x", - "description": "The `x` position to place the tile" - }, - { - "type": "param", - "name": "y", - "description": "The `y` position to place the tile" - }, - { - "type": "param", - "name": "z", - "description": "The `z` position or height to place the tile" - }, - { - "type": "param", - "name": "tile", - "description": "The entity that should be position in the isometric fashion" - } - ] + "signature": "public this Crafty.audio.stop([Number ID])", + "contents": [] }, { "type": "raw", - "value": "\nUse this method to place an entity in an isometric grid.\n" + "value": "Stops any playing sound. if id is not set, stop all sounds which are playing\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar iso = Crafty.isometric.size(128);\niso.place(2, 1, 0, Crafty.e('2D, DOM, Color').color('red').attr({w:128, h:128}));\n```\n" + "value": "```\n//all sounds stopped playing now\nCrafty.audio.stop();\n\n```" } ] - }, - { - "type": "xref", - "xrefs": [ - "Crafty.isometric.size" - ] } ], - "name": "Crafty.isometric.place", - "comp": "Crafty.isometric" + "name": "Crafty.audio.stop", + "comp": "Crafty.audio" }, { - "file": "src/isometric.js", - "startLine": 71, - "endLine": 85, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 391, + "endLine": 404, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.isometric.pos2px(Number x,Number y)", - "contents": [ - { - "type": "param", - "name": "x", - "description": "" - }, - { - "type": "param", - "name": "y", - "description": "" - }, - { - "type": "return", - "value": "Object {left Number,top Number}" - } - ] + "signature": "public this Crafty.audio.toggleMute()", + "contents": [] }, { "type": "raw", - "value": "\nThis method calculate the X and Y Coordinates to Pixel Positions\n" + "value": "Mute or unmute every Audio instance that is playing. Toggles between\npausing or playing depending on the state.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar iso = Crafty.isometric.size(128,96);\nvar position = iso.pos2px(100,100); //Object { left=12800, top=4800}\n```" + "value": "```\n//toggle mute and unmute depending on current state\nCrafty.audio.toggleMute();\n```" } ] } ], - "name": "Crafty.isometric.pos2px", - "comp": "Crafty.isometric" + "name": "Crafty.audio.toggleMute", + "comp": "Crafty.audio" }, { - "file": "src/isometric.js", - "startLine": 93, - "endLine": 108, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 413, + "endLine": 424, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.isometric.px2pos(Number left,Number top)", - "contents": [ - { - "type": "param", - "name": "top", - "description": "" - }, - { - "type": "param", - "name": "left", - "description": "" - }, - { - "type": "return", - "value": "Object {x Number,y Number}" - } - ] + "signature": "public this Crafty.audio.mute()", + "contents": [] }, { "type": "raw", - "value": "\nThis method calculate pixel top,left positions to x,y coordinates\n" + "value": "Mute every Audio instance that is playing.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar iso = Crafty.isometric.size(128,96);\nvar px = iso.pos2px(12800,4800);\nconsole.log(px); //Object { x=100, y=100}\n```" + "value": "```\nCrafty.audio.mute();\n```" } ] } ], - "name": "Crafty.isometric.px2pos", - "comp": "Crafty.isometric" + "name": "Crafty.audio.mute", + "comp": "Crafty.audio" }, { - "file": "src/isometric.js", - "startLine": 116, - "endLine": 130, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 428, + "endLine": 439, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.isometric.centerAt(Number x,Number y)", - "contents": [ - { - "type": "param", - "name": "top", - "description": "" - }, - { - "type": "param", - "name": "left", - "description": "" - } - ] + "signature": "public this Crafty.audio.unmute()", + "contents": [] }, { "type": "raw", - "value": "\nThis method center the Viewport at x/y location or gives the current centerpoint of the viewport\n" + "value": "Unmute every Audio instance that is playing.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar iso = Crafty.isometric.size(128,96).centerAt(10,10); //Viewport is now moved\n//After moving the viewport by another event you can get the new center point\nconsole.log(iso.centerAt());\n```" + "value": "```\nCrafty.audio.unmute();\n```" } ] } ], - "name": "Crafty.isometric.centerAt", - "comp": "Crafty.isometric" + "name": "Crafty.audio.unmute", + "comp": "Crafty.audio" }, { - "file": "src/isometric.js", - "startLine": 145, - "endLine": 162, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 444, + "endLine": 457, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.isometric.area()", + "signature": "public this Crafty.audio.pause(string ID)", "contents": [ { - "type": "return", - "value": "Object {x:{start Number,end Number},y:{start Number,end Number}}" + "type": "param", + "name": "{string} id", + "description": "The id of the audio object to pause" } ] }, { "type": "raw", - "value": "\nThis method get the Area surrounding by the centerpoint depends on viewport height and width\n" + "value": "Pause the Audio instance specified by id param.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar iso = Crafty.isometric.size(128,96).centerAt(10,10); //Viewport is now moved\nvar area = iso.area(); //get the area\nfor(var y = area.y.start;y <= area.y.end;y++){\n for(var x = area.x.start ;x <= area.x.end;x++){\n iso.place(x,y,0,Crafty.e(\"2D,DOM,gras\")); //Display tiles in the Screen\n }\n}\n```" + "value": "```\nCrafty.audio.pause('music');\n```\n" } ] } ], - "name": "Crafty.isometric.area", - "comp": "Crafty.isometric" - }, - { - "file": "src/keycodes.js", - "startLine": 5, - "endLine": 102, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "Object of key names and the corresponding key code.\n\n```\nBACKSPACE: 8,\nTAB: 9,\nENTER: 13,\nPAUSE: 19,\nCAPS: 20,\nESC: 27,\nSPACE: 32,\nPAGE_UP: 33,\nPAGE_DOWN: 34,\nEND: 35,\nHOME: 36,\nLEFT_ARROW: 37,\nUP_ARROW: 38,\nRIGHT_ARROW: 39,\nDOWN_ARROW: 40,\nINSERT: 45,\nDELETE: 46,\n0: 48,\n1: 49,\n2: 50,\n3: 51,\n4: 52,\n5: 53,\n6: 54,\n7: 55,\n8: 56,\n9: 57,\nA: 65,\nB: 66,\nC: 67,\nD: 68,\nE: 69,\nF: 70,\nG: 71,\nH: 72,\nI: 73,\nJ: 74,\nK: 75,\nL: 76,\nM: 77,\nN: 78,\nO: 79,\nP: 80,\nQ: 81,\nR: 82,\nS: 83,\nT: 84,\nU: 85,\nV: 86,\nW: 87,\nX: 88,\nY: 89,\nZ: 90,\nNUMPAD_0: 96,\nNUMPAD_1: 97,\nNUMPAD_2: 98,\nNUMPAD_3: 99,\nNUMPAD_4: 100,\nNUMPAD_5: 101,\nNUMPAD_6: 102,\nNUMPAD_7: 103,\nNUMPAD_8: 104,\nNUMPAD_9: 105,\nMULTIPLY: 106,\nADD: 107,\nSUBSTRACT: 109,\nDECIMAL: 110,\nDIVIDE: 111,\nF1: 112,\nF2: 113,\nF3: 114,\nF4: 115,\nF5: 116,\nF6: 117,\nF7: 118,\nF8: 119,\nF9: 120,\nF10: 121,\nF11: 122,\nF12: 123,\nSHIFT: 16,\nCTRL: 17,\nALT: 18,\nPLUS: 187,\nCOMMA: 188,\nMINUS: 189,\nPERIOD: 190,\nPULT_UP: 29460,\nPULT_DOWN: 29461,\nPULT_LEFT: 4,\nPULT_RIGHT': 5\n```" - } - ], - "name": "Crafty.keys", - "categories": [ - "Input" - ] + "name": "Crafty.audio.pause", + "comp": "Crafty.audio" }, { - "file": "src/keycodes.js", - "startLine": 199, - "endLine": 209, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 470, + "endLine": 483, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "An object mapping mouseButton names to the corresponding button ID.\nIn all mouseEvents, we add the `e.mouseButton` property with a value normalized to match e.button of modern webkit browsers:\n\n```\nLEFT: 0,\nMIDDLE: 1,\nRIGHT: 2\n```" - } - ], - "name": "Crafty.mouseButtons", - "categories": [ - "Input" - ] - }, - { - "file": "src/loader.js", - "startLine": 5, - "endLine": 17, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "type": "method", + "signature": "public this Crafty.audio.unpause(string ID)", + "contents": [ + { + "type": "param", + "name": "{string} id", + "description": "The id of the audio object to unpause" + } + ] + }, { "type": "raw", - "value": "An object containing every asset used in the current Crafty game.\nThe key is the URL and the value is the `Audio` or `Image` object.\n\nIf loading an asset, check that it is in this object first to avoid loading twice.\n" + "value": "Resume playing the Audio instance specified by id param.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar isLoaded = !!Crafty.assets[\"images/sprite.png\"];\n```" + "value": "```\nCrafty.audio.unpause('music');\n```\n" } ] - }, - { - "type": "xref", - "xrefs": [ - "Crafty.loader" - ] } ], - "name": "Crafty.assets", - "categories": [ - "Assets" - ] + "name": "Crafty.audio.unpause", + "comp": "Crafty.audio" }, { - "file": "src/loader.js", - "startLine": 21, - "endLine": 52, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 495, + "endLine": 508, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.paths([Object paths])", + "signature": "public this Crafty.audio.togglePause(string ID)", "contents": [ { "type": "param", - "name": "paths", - "description": "Object containing paths for audio and images folders" + "name": "{string} id", + "description": "The id of the audio object to pause/" } ] }, { "type": "raw", - "value": "\nFunction to define custom folder for audio and images. You should use\nthis function to avoid typing the same paths again and again when\nloading assets with the Crafty.load() function.\n\nIf you do not give a object you get the current paths for both audio\nand images back.\n\nYou do not have to define paths.\n" + "value": "Toggle the pause status of the Audio instance specified by id param.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "\n\nSetting folders:\n```\nCrafty.paths({ audio: \"custom/audio/path/\", images: \"custom/images/path/\" });\n\nCrafty.load({\n \"audio\": {\n \"ray\": ['ray.mp3'] // This loads ray.mp3 from custom/audio/path/ray.mp3\n }\n}, function() {\n console.log('loaded');\n});\n```\n" + "value": "```\nCrafty.audio.togglePause('music');\n```\n" } ] - }, - { - "type": "xref", - "xrefs": [ - "Crafty.load" - ] } ], - "name": "Crafty.paths", - "categories": [ - "Assets" - ] + "name": "Crafty.audio.togglePause", + "comp": "Crafty.audio" }, { - "file": "src/loader.js", - "startLine": 65, - "endLine": 84, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/sound/sound.js", + "startLine": 525, + "endLine": 539, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "NewAsset", - "description": "After setting new asset", - "objName": "key and value of new added asset.", - "objProp": "Object" - } - ] - }, { "type": "method", - "signature": "public void Crafty.asset(String key, Object asset)", + "signature": "public Boolean Crafty.audio.isPlaying(string ID)", "contents": [ { "type": "param", - "name": "key", - "description": "asset url." + "name": "{string} id", + "description": "The id of the audio object" }, { - "type": "param", - "name": "asset", - "description": "`Audio` or `Image` object." - } - ] - }, - { - "type": "raw", - "value": "Add new asset to assets object.\n" - }, - { - "type": "method", - "signature": "public void Crafty.asset(String key)", - "contents": [ - { - "type": "param", - "name": "key", - "description": "asset url." + "type": "return", + "value": "a Boolean indicating whether the audio is playing or not" } ] }, { "type": "raw", - "value": "Get asset from assets object.\n" + "value": "Check if audio with the given ID is playing or not (on at least one channel).\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.asset(key, value);\nvar asset = Crafty.asset(key); //object with key and value fields\n```\n" + "value": "```\nvar isPlaying = Crafty.audio.isPlaying('music');\n```\n" } ] - }, - { - "type": "xref", - "xrefs": [ - "Crafty.assets" - ] } ], - "name": "Crafty.asset", - "categories": [ - "Assets" - ] + "name": "Crafty.audio.isPlaying", + "comp": "Crafty.audio" }, { - "file": "src/loader.js", - "startLine": 100, - "endLine": 139, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 6, + "endLine": 11, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nA list of file extensions that can be loaded as images by Crafty.load\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\n// add tif extension to list of supported image files\nCrafty.image_whitelist.push(\"tif\");\n\nvar assets = {\n \"sprites\": {\n \"sprite.tif\": { //set a tif sprite\n \"tile\": 64,\n \"tileh\": 32,\n \"map\": { \"sprite_car\": [0, 0] }\n }\n },\n \"audio\": {\n \"jump\": \"jump.mp3\";\n }\n};\n\nCrafty.load( assets, // preload the assets\n function() { //when loaded\n Crafty.audio.play(\"jump\"); //Play the audio file\n Crafty.e('2D, DOM, sprite_car'); // create entity with sprite\n },\n\n function(e) { //progress\n },\n\n function(e) { //uh oh, error loading\n }\n);\n```\n" - } - ] + "value": "Functions related with querying entities." }, { "type": "xref", "xrefs": [ - "Crafty.asset", - "Crafty.load" + "Crafty.HashMap" ] } ], - "name": "Crafty.image_whitelist", + "name": "Crafty.map", "categories": [ - "Assets" + "2D" ] }, { - "file": "src/loader.js", - "startLine": 142, - "endLine": 225, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 19, + "endLine": 27, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public void Crafty.load(Object assets, Function onLoad[, Function onProgress[, Function onError]])", - "contents": [ + "type": "raw", + "value": "Component for any entity that has a position on the stage." + }, + { + "type": "triggers", + "events": [ { - "type": "param", - "name": "assets", - "description": "Object JSON formatted (or JSON string), with assets to load (accepts sounds, images and sprites)" + "type": "trigger", + "event": "Move", + "description": "when the entity has moved", + "objName": "Old position", + "objProp": "{ _x:Number, _y:Number, _w:Number, _h:Number }" }, { - "type": "param", - "name": "onLoad", - "description": "Callback when the assets are loaded" + "type": "trigger", + "event": "Invalidate", + "description": "when the entity needs to be redrawn", + "objName": "Data", + "objProp": null }, { - "type": "param", - "name": "onProgress", - "description": "Callback when an asset is loaded. Contains information about assets loaded" + "type": "trigger", + "event": "Rotate", + "description": "when the entity is rotated", + "objName": "Data", + "objProp": "{ cos:Number, sin:Number, deg:Number, rad:Number, o: {x:Number, y:Number}}" }, { - "type": "param", - "name": "onError", - "description": "Callback when an asset fails to load" + "type": "trigger", + "event": "Reorder", + "description": "when the entity's z index has changed", + "objName": "Data", + "objProp": null } ] - }, + } + ], + "name": "2D", + "categories": [ + "2D" + ] + }, + { + "file": "src/spatial/2d.js", + "startLine": 29, + "endLine": 36, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nPreloader for all assets. Takes a JSON formatted object (or JSON string) of files and adds them to the\n`Crafty.assets` object, as well as setting sprites accordingly.\n\nFormat must follow the pattern shown in the example below, but it's not required to pass all \"audio\",\n\"images\" and \"sprites\" properties, only those you'll need. For example, if you don't need to preload\nsprites, you can omit that property.\n\nBy default, Crafty will assume all files are in the current path. For changing these,\nuse the function `Crafty.paths`.\n\nFiles with suffixes in `image_whitelist` (case insensitive) will be loaded.\n\nIt's possible to pass the full file path(including protocol), instead of just the filename.ext, in case\nyou want some asset to be loaded from another domain.\n\nIf `Crafty.support.audio` is `true`, files with the following suffixes `mp3`, `wav`, `ogg` and\n`mp4` (case insensitive) can be loaded.\n\nThe `onProgress` function will be passed on object with information about\nthe progress including how many assets loaded, total of all the assets to\nload and a percentage of the progress.\n```\n{ loaded: j, total: total, percent: (j / total * 100), src:src }\n```\n\n`onError` will be passed with the asset that couldn't load.\n\nWhen `onError` is not provided, the onLoad is loaded even when some assets are not successfully loaded.\nOtherwise, onLoad will be called no matter whether there are errors or not.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nvar assetsObj = {\n \"audio\": {\n \"beep\": [\"beep.wav\", \"beep.mp3\", \"beep.ogg\"],\n \"boop\": \"boop.wav\",\n \"slash\": \"slash.wav\"\n },\n \"images\": [\"badguy.bmp\", \"goodguy.png\"],\n \"sprites\": {\n \"animals.png\": {\n \"tile\": 50,\n \"tileh\": 40,\n \"map\": { \"ladybug\": [0,0], \"lazycat\": [0,1], \"ferociousdog\": [0,2] }\n \"paddingX\": 5,\n \"paddingY\": 5,\n \"paddingAroundBorder\": 10\n },\n \"vehicles.png\": {\n \"tile\": 150,\n \"tileh\": 75,\n \"map\": { \"car\": [0,0], \"truck\": [0,1] }\n }\n },\n};\n\nCrafty.load(assetsObj, // preload assets\n function() { //when loaded\n Crafty.scene(\"main\"); //go to main scene\n Crafty.audio.play(\"boop\"); //Play the audio file\n Crafty.e('2D, DOM, lazycat'); // create entity with sprite\n },\n\n function(e) { //progress\n },\n\n function(e) { //uh oh, error loading\n }\n);\n```\n" - } - ] + "value": "The `x` position on the stage. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._x` property." }, { - "type": "xref", - "xrefs": [ - "Crafty.paths", - "Crafty.assets", - "Crafty.image_whitelist", - "Crafty.removeAssets" + "type": "xref", + "xrefs": [ + "._attr" ] } ], - "name": "Crafty.loader", - "categories": [ - "Assets" - ] + "name": ".x", + "comp": "2D" }, { - "file": "src/loader.js", - "startLine": 349, - "endLine": 394, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 38, + "endLine": 45, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "" + "value": "The `y` position on the stage. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._y` property." }, { - "type": "method", - "signature": "public void Crafty.removeAssets(Object assets)", - "contents": [ - { - "type": "param", - "name": "data", - "description": "Object JSON formatted (or JSON string), with assets to remove (accepts sounds, images and sprites)" - } + "type": "xref", + "xrefs": [ + "._attr" ] - }, + } + ], + "name": ".y", + "comp": "2D" + }, + { + "file": "src/spatial/2d.js", + "startLine": 47, + "endLine": 56, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "Removes assets (audio, images, sprites - and related sprite components) in order to allow the browser\nto free memory.\n\nRecieves a JSON fomatted object (or JSON string) containing 'audio', 'images' and/or 'sprites'\nproperties with assets to be deleted. Follows a similar format as Crafty.load 'data' argument. If\nyou pass the exact same object passed to Crafty.load, that will delete everything loaded that way.\nFor sprites, if you want to keep some specific component, just don't pass that component's name in\nthe sprite 'map'.\n\nNote that in order to remove the sprite components related to a given sprite, it's required to\npass the 'map' property of that sprite, and although its own properties's values (the properties refer\nto sprite components) are not used in the removing process, omitting them will cause an error (since\n'map' is an object, thus it's properties can NOT omitted - however, they can be null, or undefined).\nIt will work as long as the 'map' objects' properties have any value. Or if you define 'map' itself\nas an array, like:\n\"map\": [ \"car\", \"truck\" ] instead of \"map\": { \"car\": [0,0], \"truck\": [0,1] }.\nThis is examplified below (\"animals.png\" VS. \"vehicles.png\" sprites).\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nvar assetsToRemoveObj = {\n \"audio\": {\n \"beep\": [\"beep.wav\", \"beep.mp3\", \"beep.ogg\"],\n \"boop\": \"boop.wav\"\n },\n \"images\": [\"badguy.bmp\", \"goodguy.png\"],\n \"sprites\": {\n \"animals.png\": {\n \"map\": { \"ladybug\": [0,0], \"lazycat\": [0,1] },\n },\n \"vehicles.png\": {\n \"map\": [ \"car\", \"truck\" ]\n }\n }\n}\n\nCrafty.removeAssets(assetsToRemoveObj);\n```\n" - } - ] + "value": "The width of the entity. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._w` property.\n\nChanging this value is not recommended as canvas has terrible resize quality and DOM will just clip the image." }, { "type": "xref", "xrefs": [ - "Crafty.load" + "._attr" ] } ], - "name": "Crafty.removeAssets", - "categories": [ - "Assets" - ] + "name": ".w", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 4, - "endLine": 7, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 58, + "endLine": 67, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Static functions." + "value": "The height of the entity. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._h` property.\n\nChanging this value is not recommended as canvas has terrible resize quality and DOM will just clip the image." + }, + { + "type": "xref", + "xrefs": [ + "._attr" + ] } ], - "name": "Crafty.math", - "categories": [ - "2D" - ] + "name": ".h", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 10, - "endLine": 17, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 69, + "endLine": 82, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this Crafty.math.abs(Number n)", - "contents": [ - { - "type": "param", - "name": "n", - "description": "Some value." - }, - { - "type": "return", - "value": "Absolute value." - } - ] + "type": "raw", + "value": "The `z` index on the stage. When modified, will automatically be redrawn.\nIs actually a getter/setter so when using this value for calculations and not modifying it,\nuse the `._z` property.\n\nA higher `z` value will be closer to the front of the stage. A smaller `z` value will be closer to the back.\nA global Z index is produced based on its `z` value as well as the GID (which entity was created first).\nTherefore entities will naturally maintain order depending on when it was created if same z value.\n\n`z` is required to be an integer, e.g. `z=11.2` is not allowed." }, { - "type": "raw", - "value": "\nReturns the absolute value." + "type": "xref", + "xrefs": [ + "._attr" + ] } ], - "name": "Crafty.math.abs", - "comp": "Crafty.math" + "name": ".z", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 23, - "endLine": 33, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 84, + "endLine": 105, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Number Crafty.math.amountOf(Number checkValue, Number minValue, Number maxValue)", - "contents": [ - { - "type": "param", - "name": "checkValue", - "description": "Value that should checked with minimum and maximum." - }, - { - "type": "param", - "name": "minValue", - "description": "Minimum value to check." - }, - { - "type": "param", - "name": "maxValue", - "description": "Maximum value to check." - }, - { - "type": "return", - "value": "Amount of checkValue compared to minValue and maxValue." - } - ] + "type": "raw", + "value": "The rotation state of the entity, in clockwise degrees.\n`this.rotation = 0` sets it to its original orientation; `this.rotation = 10`\nsets it to 10 degrees clockwise from its original orientation;\n`this.rotation = -10` sets it to 10 degrees counterclockwise from its\noriginal orientation, etc.\n\nWhen modified, will automatically be redrawn. Is actually a getter/setter\nso when using this value for calculations and not modifying it,\nuse the `._rotation` property.\n\n`this.rotation = 0` does the same thing as `this.rotation = 360` or `720` or\n`-360` or `36000` etc. So you can keep increasing or decreasing the angle for continuous\nrotation. (Numerical errors do not occur until you get to millions of degrees.)\n\nThe default is to rotate the entity around its (initial) top-left corner; use\n`.origin()` to change that.\n" }, { - "type": "raw", - "value": "\nReturns the amount of how much a checkValue is more like minValue (=0)\nor more like maxValue (=1)" + "type": "xref", + "xrefs": [ + "._attr", + ".origin" + ] } ], - "name": "Crafty.math.amountOf", - "comp": "Crafty.math" + "name": ".rotation", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 43, - "endLine": 52, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 107, + "endLine": 111, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public Number Crafty.math.clamp(Number value, Number min, Number max)", - "contents": [ - { - "type": "param", - "name": "value", - "description": "A value." - }, - { - "type": "param", - "name": "max", - "description": "Maximum that value can be." - }, - { - "type": "param", - "name": "min", - "description": "Minimum that value can be." - }, - { - "type": "return", - "value": "The value between minimum and maximum." - } - ] - }, { "type": "raw", - "value": "\nRestricts a value to be within a specified range." + "value": "Transparency of an entity. Must be a decimal value between 0.0 being fully transparent to 1.0 being fully opaque." } ], - "name": "Crafty.math.clamp", - "comp": "Crafty.math" + "name": ".alpha", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 63, - "endLine": 68, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 113, + "endLine": 120, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Converts angle from degree to radian." - }, - { - "type": "param", - "name": "angleInDeg", - "description": "The angle in degree." - }, - { - "type": "return", - "value": "The angle in radian." + "value": "If the entity is visible or not. Accepts a true or false value.\nCan be used for optimization by setting an entities visibility to false when not needed to be drawn.\n\nThe entity will still exist and can be collided with but just won't be drawn." } ], - "name": "Crafty.math.degToRad", - "comp": "Crafty.math" + "name": ".visible", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 74, - "endLine": 84, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 123, + "endLine": 127, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public Number Crafty.math.distance(Number x1, Number y1, Number x2, Number y2)", - "contents": [ - { - "type": "param", - "name": "x1", - "description": "First x coordinate." - }, - { - "type": "param", - "name": "y1", - "description": "First y coordinate." - }, - { - "type": "param", - "name": "x2", - "description": "Second x coordinate." - }, - { - "type": "param", - "name": "y2", - "description": "Second y coordinate." - }, - { - "type": "return", - "value": "The distance between the two points." - } - ] - }, { "type": "raw", - "value": "\nDistance between two points." + "value": "When two entities overlap, the one with the larger `_globalZ` will be on top of the other." } ], - "name": "Crafty.math.distance", - "comp": "Crafty.math" + "name": "._globalZ", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 91, - "endLine": 101, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 316, + "endLine": 332, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public Number Crafty.math.lerp(Number value1, Number value2, Number amount)", - "contents": [ - { - "type": "param", - "name": "value1", - "description": "One value." - }, - { - "type": "param", - "name": "value2", - "description": "Another value." - }, - { - "type": "param", - "name": "amount", - "description": "Amount of value2 to value1." - }, + "type": "raw", + "value": "Extends the MBR of the entity by a specified amount.\n" + }, + { + "type": "triggers", + "events": [ { - "type": "return", - "value": "Linear interpolated value." + "type": "trigger", + "event": "BoundaryOffset", + "description": "when the MBR offset changes", + "objName": "Data", + "objProp": null } ] }, - { - "type": "raw", - "value": "\nLinear interpolation. Passing amount with a value of 0 will cause value1 to be returned,\na value of 1 will cause value2 to be returned." - } - ], - "name": "Crafty.math.lerp", - "comp": "Crafty.math" - }, - { - "file": "src/math.js", - "startLine": 107, - "endLine": 114, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public Number Crafty.math.negate(Number percent)", + "signature": "public this .offsetBoundary(Number dx1, Number dy1, Number dx2, Number dy2)", "contents": [ { "type": "param", - "name": "percent", - "description": "If you pass 1 a -1 will be returned. If you pass 0 a 1 will be returned." + "name": "dx1", + "description": "Extends the MBR to the left by this amount" }, { - "type": "return", - "value": "1 or -1." + "type": "param", + "name": "dy1", + "description": "Extends the MBR upward by this amount" + }, + { + "type": "param", + "name": "dx2", + "description": "Extends the MBR to the right by this amount" + }, + { + "type": "param", + "name": "dy2", + "description": "Extends the MBR downward by this amount" } ] }, - { - "type": "raw", - "value": "\nReturnes \"randomly\" -1." - } - ], - "name": "Crafty.math.negate", - "comp": "Crafty.math" - }, - { - "file": "src/math.js", - "startLine": 123, - "endLine": 130, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public Number Crafty.math.radToDeg(Number angle)", + "signature": "public this .offsetBoundary(Number offset)", "contents": [ { "type": "param", - "name": "angleInRad", - "description": "The angle in radian." - }, - { - "type": "return", - "value": "The angle in degree." + "name": "offset", + "description": "Extend the MBR in all directions by this amount" } ] }, { "type": "raw", - "value": "\nConverts angle from radian to degree." + "value": "You would most likely use this function to ensure that custom canvas rendering beyond the extent of the entity's normal bounds is not clipped." } ], - "name": "Crafty.math.radToDeg", - "comp": "Crafty.math" + "name": ".offsetBoundary", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 136, - "endLine": 143, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 450, + "endLine": 455, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Object Crafty.math.randomElementOfArray(Array array)", - "contents": [ - { - "type": "param", - "name": "array", - "description": "A specific array." - }, - { - "type": "return", - "value": "A random element of a specific array." - } - ] + "signature": "public Number .area(void)", + "contents": [] }, { "type": "raw", - "value": "\nReturns a random element of a specific array." + "value": "Calculates the area of the entity" } ], - "name": "Crafty.math.randomElementOfArray", - "comp": "Crafty.math" + "name": ".area", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 149, - "endLine": 157, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 460, + "endLine": 472, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Number Crafty.math.randomInt(Number start, Number end)", + "signature": "public Boolean .intersect(Number x, Number y, Number w, Number h)", "contents": [ { "type": "param", - "name": "start", - "description": "Smallest int value that can be returned." + "name": "x", + "description": "X position of the rect" }, { "type": "param", - "name": "end", - "description": "Biggest int value that can be returned." + "name": "y", + "description": "Y position of the rect" }, { - "type": "return", - "value": "A random int." + "type": "param", + "name": "w", + "description": "Width of the rect" + }, + { + "type": "param", + "name": "h", + "description": "Height of the rect" } ] }, - { - "type": "raw", - "value": "\nReturns a random int in within a specific range." - } - ], - "name": "Crafty.math.randomInt", - "comp": "Crafty.math" - }, - { - "file": "src/math.js", - "startLine": 163, - "endLine": 171, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public Number Crafty.math.randomInt(Number start, Number end)", + "signature": "public Boolean .intersect(Object rect)", "contents": [ { "type": "param", - "name": "start", - "description": "Smallest number value that can be returned." - }, - { - "type": "param", - "name": "end", - "description": "Biggest number value that can be returned." - }, - { - "type": "return", - "value": "A random number." + "name": "rect", + "description": "An object that must have the `_x, _y, _w, _h` values as properties" } ] }, { "type": "raw", - "value": "\nReturns a random number in within a specific range." + "value": "Determines if this entity intersects a rectangle. If the entity is rotated, its MBR is used for the test." } ], - "name": "Crafty.math.randomNumber", - "comp": "Crafty.math" + "name": ".intersect", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 177, - "endLine": 187, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 490, + "endLine": 502, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Number Crafty.math.squaredDistance(Number x1, Number y1, Number x2, Number y2)", + "signature": "public Boolean .within(Number x, Number y, Number w, Number h)", "contents": [ { "type": "param", - "name": "x1", - "description": "First x coordinate." + "name": "x", + "description": "X position of the rect" }, { "type": "param", - "name": "y1", - "description": "First y coordinate." + "name": "y", + "description": "Y position of the rect" }, { "type": "param", - "name": "x2", - "description": "Second x coordinate." + "name": "w", + "description": "Width of the rect" }, { "type": "param", - "name": "y2", - "description": "Second y coordinate." - }, - { - "type": "return", - "value": "The squared distance between the two points." + "name": "h", + "description": "Height of the rect" } ] }, - { - "type": "raw", - "value": "\nSquared distance between two points." - } - ], - "name": "Crafty.math.squaredDistance", - "comp": "Crafty.math" - }, - { - "file": "src/math.js", - "startLine": 193, - "endLine": 202, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public Boolean Crafty.math.withinRange(Number value, Number min, Number max)", + "signature": "public Boolean .within(Object rect)", "contents": [ { "type": "param", - "name": "value", - "description": "The specific value." - }, - { - "type": "param", - "name": "min", - "description": "Minimum value." - }, - { - "type": "param", - "name": "max", - "description": "Maximum value." - }, - { - "type": "return", - "value": "Returns true if value is within a specific range." + "name": "rect", + "description": "An object that must have the `_x, _y, _w, _h` values as properties" } ] }, { "type": "raw", - "value": "\nCheck if a value is within a specific range." + "value": "Determines if this current entity is within another rectangle." } ], - "name": "Crafty.math.withinRange", - "comp": "Crafty.math" + "name": ".within", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 210, - "endLine": 223, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 520, + "endLine": 532, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nVector2D uses the following form:\n\n" - }, - { - "type": "method", - "signature": "public {Vector2D} Vector2D();", - "contents": [] - }, - { - "type": "method", - "signature": "public {Vector2D} Vector2D(Vector2D);", - "contents": [] - }, { "type": "method", - "signature": "public {Vector2D} Vector2D(Number, Number);", + "signature": "public Boolean .contains(Number x, Number y, Number w, Number h)", "contents": [ { "type": "param", - "name": "{Vector2D|Number=0} x", - "description": "" + "name": "x", + "description": "X position of the rect" }, { "type": "param", - "name": "{Number=0} y", - "description": "" - } - ] - } - ], - "name": "Crafty.math.Vector2D", - "categories": [ - "2D" - ], - "class": "This is a general purpose 2D vector class", - "public": true - }, - { - "file": "src/math.js", - "startLine": 240, - "endLine": 249, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nAdds the passed vector to this vector\n" - }, - { - "type": "method", - "signature": "public {Vector2D} add(Vector2D);", - "contents": [ + "name": "y", + "description": "Y position of the rect" + }, { "type": "param", - "name": "{vector2D} vecRH", - "description": "" + "name": "w", + "description": "Width of the rect" }, { - "type": "return", - "value": "{Vector2D} this after adding" + "type": "param", + "name": "h", + "description": "Height of the rect" } ] - } - ], - "name": ".add", - "comp": "Crafty.math.Vector2D", - "public": true - }, - { - "file": "src/math.js", - "startLine": 257, - "endLine": 267, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nCalculates the angle between the passed vector and this vector, using <0,0> as the point of reference.\nAngles returned have the range (−π, π].\n" }, { "type": "method", - "signature": "public {Number} angleBetween(Vector2D);", + "signature": "public Boolean .contains(Object rect)", "contents": [ { "type": "param", - "name": "{Vector2D} vecRH", - "description": "" - }, - { - "type": "return", - "value": "{Number} the angle between the two vectors in radians" + "name": "rect", + "description": "An object that must have the `_x, _y, _w, _h` values as properties." } ] + }, + { + "type": "raw", + "value": "Determines if the rectangle is within the current entity. If the entity is rotated, its MBR is used for the test." } - ], - "name": ".angleBetween", - "comp": "Crafty.math.Vector2D", - "public": true + ], + "name": ".contains", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 273, - "endLine": 282, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 550, + "endLine": 561, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nCalculates the angle to the passed vector from this vector, using this vector as the point of reference.\n" - }, { "type": "method", - "signature": "public {Number} angleTo(Vector2D);", + "signature": "public Object .pos([Object pos])", "contents": [ { "type": "param", - "name": "{Vector2D} vecRH", - "description": "" + "name": "pos", + "description": "an object to use as output" }, { "type": "return", - "value": "{Number} the angle to the passed vector in radians" + "value": "An object with this entity's `_x`, `_y`, `_w`, and `_h` values. If an object is passed in, it will be reused rather than creating a new object." } ] + }, + { + "type": "note", + "value": "The keys have an underscore prefix. This is due to the x, y, w, h properties being setters and getters that wrap the underlying properties with an underscore (_x, _y, _w, _h)." } ], - "name": ".angleTo", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".pos", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 288, - "endLine": 296, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 571, + "endLine": 577, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "\nCreates and exact, numeric copy of this vector\n" + "type": "method", + "signature": "public Object .mbr()", + "contents": [] }, { - "type": "method", - "signature": "public {Vector2D} clone();", - "contents": [ - { - "type": "return", - "value": "{Vector2D} the new vector" - } - ] + "type": "raw", + "value": "Returns the minimum bounding rectangle. If there is no rotation\non the entity it will return the rect." } ], - "name": ".clone", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".mbr", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 302, - "endLine": 311, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 591, + "endLine": 602, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nCalculates the distance from this vector to the passed vector.\n" - }, { "type": "method", - "signature": "public {Number} distance(Vector2D);", + "signature": "public Boolean .isAt(Number x, Number y)", "contents": [ { "type": "param", - "name": "{Vector2D} vecRH", - "description": "" + "name": "x", + "description": "X position of the point" }, { - "type": "return", - "value": "{Number} the distance between the two vectors" + "type": "param", + "name": "y", + "description": "Y position of the point" } ] + }, + { + "type": "raw", + "value": "Determines whether a point is contained by the entity. Unlike other methods,\nan object can't be passed. The arguments require the x and y value.\n\nThe given point is tested against the first of the following that exists: a mapArea associated with \"Mouse\", the hitarea associated with \"Collision\", or the object's MBR." } ], - "name": ".distance", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".isAt", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 317, - "endLine": 328, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 614, + "endLine": 622, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nCalculates the squared distance from this vector to the passed vector.\nThis function avoids calculating the square root, thus being slightly faster than .distance( ).\n" - }, { "type": "method", - "signature": "public {Number} distanceSq(Vector2D);", + "signature": "public this .move(String dir, Number by)", "contents": [ { "type": "param", - "name": "{Vector2D} vecRH", - "description": "" + "name": "dir", + "description": "Direction to move (n,s,e,w,ne,nw,se,sw)" }, { - "type": "return", - "value": "{Number} the squared distance between the two vectors" + "type": "param", + "name": "by", + "description": "Amount to move in the specified direction" } ] }, { - "type": "xref", - "xrefs": [ - ".distance" - ] + "type": "raw", + "value": "Quick method to move the entity in a direction (n, s, e, w, ne, nw, se, sw) by an amount of pixels." } ], - "name": ".distanceSq", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".move", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 334, - "endLine": 343, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 632, + "endLine": 643, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nDivides this vector by the passed vector.\n" - }, { "type": "method", - "signature": "public {Vector2D} divide(Vector2D);", + "signature": "public this .shift(Number x, Number y, Number w, Number h)", "contents": [ { "type": "param", - "name": "{Vector2D} vecRH", - "description": "" + "name": "x", + "description": "Amount to move X" }, { - "type": "return", - "value": "{Vector2D} this vector after dividing" + "type": "param", + "name": "y", + "description": "Amount to move Y" + }, + { + "type": "param", + "name": "w", + "description": "Amount to widen" + }, + { + "type": "param", + "name": "h", + "description": "Amount to increase height" } ] + }, + { + "type": "raw", + "value": "Shift or move the entity by an amount. Use negative values\nfor an opposite direction." } ], - "name": ".divide", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".shift", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 351, - "endLine": 360, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 653, + "endLine": 663, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nCalculates the dot product of this and the passed vectors\n" - }, { "type": "method", - "signature": "public {Number} dotProduct(Vector2D);", + "signature": "public void ._cascade(e)", "contents": [ { "type": "param", - "name": "{Vector2D} vecRH", - "description": "" - }, - { - "type": "return", - "value": "{Number} the resultant dot product" + "name": "e", + "description": "An object describing the motion" } ] + }, + { + "type": "raw", + "value": "Move or rotate the entity's children according to a certain motion.\nThis method is part of a function bound to \"Move\": It is used\ninternally for ensuring that when a parent moves, the child also\nmoves in the same way." } ], - "name": ".dotProduct", - "comp": "Crafty.math.Vector2D", - "public": true + "name": "._cascade", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 366, - "endLine": 375, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 690, + "endLine": 707, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nCalculates the z component of the cross product of the two vectors augmented to 3D.\n" - }, { "type": "method", - "signature": "public {Number} crossProduct(Vector2D);", + "signature": "public this .attach(Entity obj[, .., Entity objN])", "contents": [ { "type": "param", - "name": "{Vector2D} vecRH", - "description": "" - }, - { - "type": "return", - "value": "{Number} the resultant cross product" + "name": "obj", + "description": "Child entity(s) to attach" } ] + }, + { + "type": "raw", + "value": "Sets one or more entities to be children, with the current entity (`this`)\nas the parent. When the parent moves or rotates, its children move or\nrotate by the same amount. (But not vice-versa: If you move a child, it\nwill not move the parent.) When the parent is destroyed, its children are\ndestroyed.\n\nFor any entity, `this._children` is the array of its children entity\nobjects (if any), and `this._parent` is its parent entity object (if any).\n\nAs many objects as wanted can be attached, and a hierarchy of objects is\npossible by attaching." } ], - "name": ".crossProduct", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".attach", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 381, - "endLine": 390, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 725, + "endLine": 733, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nDetermines if this vector is numerically equivalent to the passed vector.\n" - }, { "type": "method", - "signature": "public {Boolean} equals(Vector2D);", + "signature": "public this .detach([Entity obj])", "contents": [ { "type": "param", - "name": "{Vector2D} vecRH", - "description": "" - }, - { - "type": "return", - "value": "{Boolean} true if the vectors are equivalent" + "name": "obj", + "description": "The entity to detach. Left blank will remove all attached entities" } ] + }, + { + "type": "raw", + "value": "Stop an entity from following the current entity. Passing no arguments will stop\nevery entity attached." } ], - "name": ".equals", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".detach", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 397, - "endLine": 407, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 756, + "endLine": 778, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "\nCalculates a new vector that is perpendicular to this vector.\nThe perpendicular vector has the same magnitude as this vector and is obtained by a counter-clockwise rotation of 90° of this vector.\n" + "type": "method", + "signature": "public this .origin(Number x, Number y)", + "contents": [ + { + "type": "param", + "name": "x", + "description": "Pixel value of origin offset on the X axis" + }, + { + "type": "param", + "name": "y", + "description": "Pixel value of origin offset on the Y axis" + } + ] }, { "type": "method", - "signature": "public {Vector2D} perpendicular([Vector2D]);", + "signature": "public this .origin(String offset)", "contents": [ { "type": "param", - "name": "{Vector2D} [result]", - "description": "An optional parameter to save the result in" - }, + "name": "offset", + "description": "Combination of center, top, bottom, middle, left and right" + } + ] + }, + { + "type": "raw", + "value": "Set the origin point of an entity for it to rotate around.\n" + }, + { + "type": "example", + "contents": [ { - "type": "return", - "value": "{Vector2D} the perpendicular vector" + "type": "raw", + "value": "```\nthis.origin(\"top left\")\nthis.origin(\"center\")\nthis.origin(\"bottom right\")\nthis.origin(\"middle right\")\n```\n" } ] + }, + { + "type": "xref", + "xrefs": [ + ".rotation" + ] } ], - "name": ".perpendicular", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".origin", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 414, - "endLine": 424, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 803, + "endLine": 816, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Invalidate", + "description": "when the entity has flipped", + "objName": "Data", + "objProp": null + } + ] + }, + { + "type": "method", + "signature": "public this .flip(String dir)", + "contents": [ + { + "type": "param", + "name": "dir", + "description": "Flip direction" + } + ] + }, { "type": "raw", - "value": "\nCalculates a new right-handed unit vector that is perpendicular to the line created by this and the passed vector.\n" + "value": "Flip entity on passed direction\n" }, { - "type": "method", - "signature": "public {Vector2D} getNormal(Vector2D[, Vector2D]);", + "type": "example", "contents": [ { - "type": "param", - "name": "{Vector2D} vecRH", - "description": "" - }, - { - "type": "param", - "name": "{Vector2D} [result]", - "description": "An optional parameter to save the result in" - }, - { - "type": "return", - "value": "{Vector2D} the new normal vector" + "type": "raw", + "value": "```\nthis.flip(\"X\")\n```" } ] } ], - "name": ".getNormal", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".flip", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 431, - "endLine": 439, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 826, + "endLine": 839, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "\nDetermines if this vector is equal to <0,0>\n" + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "Invalidate", + "description": "when the entity has unflipped", + "objName": "Data", + "objProp": null + } + ] }, { "type": "method", - "signature": "public {Boolean} isZero();", + "signature": "public this .unflip(String dir)", "contents": [ { - "type": "return", - "value": "{Boolean} true if this vector is equal to <0,0>" + "type": "param", + "name": "dir", + "description": "Unflip direction" } ] - } - ], - "name": ".isZero", - "comp": "Crafty.math.Vector2D", - "public": true - }, - { - "file": "src/math.js", - "startLine": 445, - "endLine": 454, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "raw", - "value": "\nCalculates the magnitude of this vector.\nNote: Function objects in JavaScript already have a 'length' member, hence the use of magnitude instead.\n" + "value": "Unflip entity on passed direction (if it's flipped)\n" }, { - "type": "method", - "signature": "public {Number} magnitude();", + "type": "example", "contents": [ { - "type": "return", - "value": "{Number} the magnitude of this vector" + "type": "raw", + "value": "```\nthis.unflip(\"X\")\n```" } ] } ], - "name": ".magnitude", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".unflip", + "comp": "2D" }, { - "file": "src/math.js", - "startLine": 460, - "endLine": 470, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 861, + "endLine": 866, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nCalculates the square of the magnitude of this vector.\nThis function avoids calculating the square root, thus being slightly faster than .magnitude( ).\n" - }, + "value": "Setter method for all 2D properties including\nx, y, w, h, alpha, rotation and visible." + } + ], + "name": "._attr", + "comp": "2D" + }, + { + "file": "src/spatial/2d.js", + "startLine": 935, + "endLine": 944, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { - "type": "method", - "signature": "public {Number} magnitudeSq();", - "contents": [ + "type": "triggers", + "events": [ { - "type": "return", - "value": "{Number} the square of the magnitude of this vector" + "type": "trigger", + "event": "LandedOnGround", + "description": "When entity has landed. This event is triggered with the object the entity landed on.", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "LiftedOffGround", + "description": "When entity has lifted off. This event is triggered with the object the entity stood on before lift-off.", + "objName": "Data", + "objProp": null + }, + { + "type": "trigger", + "event": "CheckLanding", + "description": "When entity is about to land. This event is triggered with the object the entity is about to land on. Third parties can respond to this event and prevent the entity from being able to land.", + "objName": "Data", + "objProp": null } ] }, { - "type": "xref", - "xrefs": [ - ".magnitude" - ] + "type": "raw", + "value": "Component that detects if the entity collides with the ground. This component is automatically added and managed by the Gravity component.\nThe appropriate events are fired when the entity state changes (lands on ground / lifts off ground). The current ground entity can also be accessed with `.ground`." } ], - "name": ".magnitudeSq", - "comp": "Crafty.math.Vector2D", - "public": true + "name": "Supportable", + "categories": [ + "2D" + ] }, { - "file": "src/math.js", - "startLine": 476, - "endLine": 485, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 946, + "endLine": 952, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nMultiplies this vector by the passed vector\n" - }, - { - "type": "method", - "signature": "public {Vector2D} multiply(Vector2D);", - "contents": [ - { - "type": "param", - "name": "{Vector2D} vecRH", - "description": "" - }, - { - "type": "return", - "value": "{Vector2D} this vector after multiplying" - } - ] + "value": "Access the ground entity (which may be the actual ground entity if it exists, or `null` if it doesn't exist) and thus whether this entity is currently on the ground or not.\nThe ground entity is also available through the events, when the ground entity changes." } ], - "name": ".multiply", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".ground", + "comp": "Supportable" }, { - "file": "src/math.js", - "startLine": 493, - "endLine": 501, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 956, + "endLine": 973, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nNegates this vector (ie. <-x,-y>)\n" + "value": "The canLand boolean determines if the entity is allowed to land or not (e.g. perhaps the entity should not land if it's not falling).\nThe Supportable component will trigger a \"CheckLanding\" event.\nInterested parties can listen to this event and prevent the entity from landing by setting `canLand` to false.\n" }, { - "type": "method", - "signature": "public {Vector2D} negate();", + "type": "example", "contents": [ { - "type": "return", - "value": "{Vector2D} this vector after negation" + "type": "raw", + "value": "```\nvar player = Crafty.e(\"2D, Gravity\");\nplayer.bind(\"CheckLanding\", function(ground) {\n if (player.y + player.h > ground.y + player.dy) { // forbid landing, if player's feet are not above ground\n player.canLand = false;\n }\n});\n```" } ] } ], - "name": ".negate", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".canLand", + "comp": "Supportable" }, { - "file": "src/math.js", - "startLine": 509, - "endLine": 518, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1078, + "endLine": 1092, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nNormalizes this vector (scales the vector so that its new magnitude is 1)\nFor vectors where magnitude is 0, <1,0> is returned.\n" + "value": "Component that attaches the entity to the ground when it lands. Useful for platformers with moving platforms.\nRemove the component to disable the functionality.\n" }, { - "type": "method", - "signature": "public {Vector2D} normalize();", + "type": "xref", + "xrefs": [ + "Supportable", + "Gravity" + ] + }, + { + "type": "example", "contents": [ { - "type": "return", - "value": "{Vector2D} this vector after normalization" + "type": "raw", + "value": "```\nCrafty.e(\"2D, Gravity, GroundAttacher\")\n .gravity(\"Platform\"); // entity will land on and move with entites that have the \"Platform\" component\n```" } ] } ], - "name": ".normalize", - "comp": "Crafty.math.Vector2D", - "public": true + "name": "GroundAttacher", + "categories": [ + "2D" + ] }, { - "file": "src/math.js", - "startLine": 535, - "endLine": 546, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1114, + "endLine": 1123, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "\nScales this vector by the passed amount(s)\nIf scalarY is omitted, scalarX is used for both axes\n" - }, - { - "type": "method", - "signature": "public {Vector2D} scale(Number[, Number]);", - "contents": [ - { - "type": "param", - "name": "{Number} scalarX", - "description": "" - }, + "type": "triggers", + "events": [ { - "type": "param", - "name": "{Number} [scalarY]", - "description": "" + "type": "trigger", + "event": "Moved", + "description": "When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.", + "objName": "Old position", + "objProp": "{ axis: 'x' | 'y', oldValue: Number }" }, { - "type": "return", - "value": "{Vector2D} this after scaling" + "type": "trigger", + "event": "NewDirection", + "description": "When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.", + "objName": "New direction", + "objProp": "{ x: -1 | 0 | 1, y: -1 | 0 | 1 }" } ] + }, + { + "type": "raw", + "value": "Adds gravitational pull to the entity.\n" + }, + { + "type": "xref", + "xrefs": [ + "Supportable", + "Motion" + ] } ], - "name": ".scale", - "comp": "Crafty.math.Vector2D", - "public": true + "name": "Gravity", + "categories": [ + "2D" + ] }, { - "file": "src/math.js", - "startLine": 558, - "endLine": 567, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1143, + "endLine": 1164, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nScales this vector such that its new magnitude is equal to the passed value.\n" - }, { "type": "method", - "signature": "public {Vector2D} scaleToMagnitude(Number);", + "signature": "public this .gravity([comp])", "contents": [ { "type": "param", - "name": "{Number} mag", - "description": "" - }, + "name": "comp", + "description": "The name of a component that will stop this entity from falling" + } + ] + }, + { + "type": "raw", + "value": "Enable gravity for this entity no matter whether comp parameter is specified or not.\nIf comp parameter is specified all entities with that component will stop this entity from falling.\nFor a player entity in a platform game this would be a component that is added to all entities\nthat the player should be able to walk on.\nSee the Supportable component documentation for additional methods & events that are available.\n" + }, + { + "type": "example", + "contents": [ { - "type": "return", - "value": "{Vector2D} this vector after scaling" + "type": "raw", + "value": "```\nCrafty.e(\"2D, DOM, Color, Gravity\")\n .color(\"red\")\n .attr({ w: 100, h: 100 })\n .gravity(\"platform\");\n```\n" } ] + }, + { + "type": "xref", + "xrefs": [ + "Supportable", + "Motion" + ] } ], - "name": ".scaleToMagnitude", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".gravity", + "comp": "Gravity" }, { - "file": "src/math.js", - "startLine": 576, - "endLine": 587, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1172, + "endLine": 1177, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nSets the values of this vector using a passed vector or pair of numbers.\n" - }, { "type": "method", - "signature": "public {Vector2D} setValues(Vector2D);", + "signature": "public this .antigravity()", "contents": [] }, + { + "type": "raw", + "value": "Disable gravity for this component. It can be reenabled by calling .gravity()" + } + ], + "name": ".antigravity", + "comp": "Gravity" + }, + { + "file": "src/spatial/2d.js", + "startLine": 1186, + "endLine": 1202, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public {Vector2D} setValues(Number, Number);", + "signature": "public this .gravityConst(g)", "contents": [ { "type": "param", - "name": "{Number|Vector2D} x", - "description": "" - }, - { - "type": "param", - "name": "{Number} y", - "description": "" - }, + "name": "g", + "description": "gravitational constant in pixels per second squared" + } + ] + }, + { + "type": "raw", + "value": "Set the gravitational constant to g for this entity. The default is 500. The greater g, the stronger the downwards acceleration.\n" + }, + { + "type": "example", + "contents": [ { - "type": "return", - "value": "{Vector2D} this vector after setting of values" + "type": "raw", + "value": "```\nCrafty.e(\"2D, DOM, Color, Gravity\")\n .color(\"red\")\n .attr({ w: 100, h: 100 })\n .gravityConst(5)\n .gravity(\"platform\");\n```" } ] } ], - "name": ".setValues", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".gravityConst", + "comp": "Gravity" }, { - "file": "src/math.js", - "startLine": 601, - "endLine": 610, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1280, + "endLine": 1289, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "\nSubtracts the passed vector from this vector.\n" - }, - { - "type": "method", - "signature": "public {Vector2D} subtract(Vector2D);", - "contents": [ + "type": "triggers", + "events": [ { - "type": "param", - "name": "{Vector2D} vecRH", - "description": "" + "type": "trigger", + "event": "Rotated", + "description": "When entity has rotated due to angular velocity/acceleration a Rotated event is triggered.", + "objName": "Old rotation", + "objProp": "Number" }, { - "type": "return", - "value": "{vector2D} this vector after subtracting" + "type": "trigger", + "event": "NewRotationDirection", + "description": "When entity has changed rotational direction due to rotational velocity a NewRotationDirection event is triggered. The event is triggered once, if direction is different from last frame.", + "objName": "New direction", + "objProp": "-1 | 0 | 1" + }, + { + "type": "trigger", + "event": "MotionChange", + "description": "When a motion property has changed a MotionChange event is triggered.", + "objName": "Motion property name and old value", + "objProp": "{ key: String, oldValue: Number }" } ] + }, + { + "type": "raw", + "value": "Component that allows rotating an entity by applying angular velocity and acceleration.\nAll angular motion values are expressed in degrees per second (e.g. an entity with `vrotation` of 10 will rotate 10 degrees each second)." } ], - "name": ".subtract", - "comp": "Crafty.math.Vector2D", - "public": true + "name": "AngularMotion", + "categories": [ + "2D" + ] }, { - "file": "src/math.js", - "startLine": 618, - "endLine": 626, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1291, + "endLine": 1306, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nReturns a string representation of this vector.\n" + "value": "A property for accessing/modifying the angular(rotational) velocity.\nThe velocity remains constant over time, unless the acceleration increases the velocity.\n" }, { - "type": "method", - "signature": "public {String} toString();", + "type": "example", "contents": [ { - "type": "return", - "value": "{String}" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, AngularMotion\");\n\nvar vrotation = ent.vrotation; // retrieve the angular velocity\nent.vrotation += 1; // increase the angular velocity\nent.vrotation = 0; // reset the angular velocity\n```" } ] } ], - "name": ".toString", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".vrotation", + "comp": "AngularMotion" }, { - "file": "src/math.js", - "startLine": 632, - "endLine": 643, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1309, + "endLine": 1324, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nTranslates (moves) this vector by the passed amounts.\nIf dy is omitted, dx is used for both axes.\n" + "value": "A property for accessing/modifying the angular(rotational) acceleration.\nThe acceleration increases the velocity over time, resulting in ever increasing speed.\n" }, { - "type": "method", - "signature": "public {Vector2D} translate(Number[, Number]);", + "type": "example", "contents": [ { - "type": "param", - "name": "{Number} dx", - "description": "" - }, - { - "type": "param", - "name": "{Number} [dy]", - "description": "" - }, - { - "type": "return", - "value": "{Vector2D} this vector after translating" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, AngularMotion\");\n\nvar arotation = ent.arotation; // retrieve the angular acceleration\nent.arotation += 1; // increase the angular acceleration\nent.arotation = 0; // reset the angular acceleration\n```" } ] } ], - "name": ".translate", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".arotation", + "comp": "AngularMotion" }, { - "file": "src/math.js", - "startLine": 655, - "endLine": 669, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1327, + "endLine": 1339, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nCalculates the triple product of three vectors.\ntriple vector product = b(a•c) - a(b•c)\n" + "value": "A number that reflects the change in rotation (difference between the old & new rotation) that was applied in the last frame.\n" }, { - "type": "method", - "signature": "public {Vector2D} tripleProduct(Vector2D, Vector2D, Vector2D, [Vector2D]);", + "type": "example", "contents": [ { - "type": "param", - "name": "{Vector2D} a", - "description": "" - }, - { - "type": "param", - "name": "{Vector2D} b", - "description": "" - }, - { - "type": "param", - "name": "{Vector2D} c", - "description": "" - }, - { - "type": "param", - "name": "{Vector2D} [result]", - "description": "An optional parameter to save the result in" - }, - { - "type": "return", - "value": "{Vector2D} the triple product as a new vector" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, AngularMotion\");\n\nvar drotation = ent.drotation; // the change of rotation in the last frame\n```" } ] } ], - "name": ".tripleProduct", - "comp": "Crafty.math.Vector2D", - "public": true + "name": ".drotation", + "comp": "AngularMotion" }, { - "file": "src/math.js", - "startLine": 682, - "endLine": 703, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1357, + "endLine": 1363, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "" - }, - { - "type": "raw", - "value": "The third row is always assumed to be [0, 0, 1].\n\nMatrix2D uses the following form, as per the whatwg.org specifications for canvas.transform():\n[a, c, e]\n[b, d, f]\n[0, 0, 1]\n" - }, { "type": "method", - "signature": "public {Matrix2D} new Matrix2D();", + "signature": "public this .resetAngularMotion()", "contents": [] }, { - "type": "method", - "signature": "public {Matrix2D} new Matrix2D(Matrix2D);", - "contents": [] - }, + "type": "raw", + "value": "Reset all motion (resets velocity, acceleration, motionDelta)." + } + ], + "name": ".resetAngularMotion", + "comp": "AngularMotion" + }, + { + "file": "src/spatial/2d.js", + "startLine": 1404, + "endLine": 1415, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { - "type": "method", - "signature": "public {Matrix2D} new Matrix2D(Number, Number, Number, Number, Number, Number);", - "contents": [ - { - "type": "param", - "name": "{Matrix2D|Number=1} a", - "description": "" - }, - { - "type": "param", - "name": "{Number=0} b", - "description": "" - }, - { - "type": "param", - "name": "{Number=0} c", - "description": "" - }, + "type": "triggers", + "events": [ { - "type": "param", - "name": "{Number=1} d", - "description": "" + "type": "trigger", + "event": "Moved", + "description": "When entity has moved due to velocity/acceleration on either x or y axis a Moved event is triggered. If the entity has moved on both axes for diagonal movement the event is triggered twice.", + "objName": "Old position", + "objProp": "{ axis: 'x' | 'y', oldValue: Number }" }, { - "type": "param", - "name": "{Number=0} e", - "description": "" + "type": "trigger", + "event": "NewDirection", + "description": "When entity has changed direction due to velocity on either x or y axis a NewDirection event is triggered. The event is triggered once, if direction is different from last frame.", + "objName": "New direction", + "objProp": "{ x: -1 | 0 | 1, y: -1 | 0 | 1 }" }, { - "type": "param", - "name": "{Number=0} f", - "description": "" + "type": "trigger", + "event": "MotionChange", + "description": "When a motion property has changed a MotionChange event is triggered.", + "objName": "Motion property name and old value", + "objProp": "{ key: String, oldValue: Number }" } ] + }, + { + "type": "raw", + "value": "Component that allows moving an entity by applying linear velocity and acceleration.\nAll linear motion values are expressed in pixels per second (e.g. an entity with `vx` of 1 will move 1px on the x axis each second).\n" + }, + { + "type": "note", + "value": "Several methods return Vector2D objects that dynamically reflect the entity's underlying properties. If you want a static copy instead, use the vector's `clone()` method." } ], - "name": "Crafty.math.Matrix2D", + "name": "Motion", "categories": [ "2D" - ], - "class": "This is a 2D Matrix2D class. It is 3x3 to allow for affine transformations in 2D space.", - "public": true + ] }, { - "file": "src/math.js", - "startLine": 731, - "endLine": 740, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1417, + "endLine": 1432, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nApplies the matrix transformations to the passed object\n" + "value": "A property for accessing/modifying the linear velocity in the x axis.\nThe velocity remains constant over time, unless the acceleration changes the velocity.\n" }, { - "type": "method", - "signature": "public {Vector2D} apply(Vector2D);", + "type": "example", "contents": [ { - "type": "param", - "name": "{Vector2D} vecRH", - "description": "vector to be transformed" - }, - { - "type": "return", - "value": "{Vector2D} the passed vector object after transforming" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, Motion\");\n\nvar vx = ent.vx; // retrieve the linear velocity in the x axis\nent.vx += 1; // increase the linear velocity in the x axis\nent.vx = 0; // reset the linear velocity in the x axis\n```" } ] } ], - "name": ".apply", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".vx", + "comp": "Motion" }, { - "file": "src/math.js", - "startLine": 756, - "endLine": 764, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1435, + "endLine": 1450, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nCreates an exact, numeric copy of the current matrix\n" + "value": "A property for accessing/modifying the linear velocity in the y axis.\nThe velocity remains constant over time, unless the acceleration changes the velocity.\n" }, { - "type": "method", - "signature": "public {Matrix2D} clone();", + "type": "example", "contents": [ { - "type": "return", - "value": "{Matrix2D}" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, Motion\");\n\nvar vy = ent.vy; // retrieve the linear velocity in the y axis\nent.vy += 1; // increase the linear velocity in the y axis\nent.vy = 0; // reset the linear velocity in the y axis\n```" } ] } ], - "name": ".clone", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".vy", + "comp": "Motion" }, { - "file": "src/math.js", - "startLine": 770, - "endLine": 780, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1453, + "endLine": 1468, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nMultiplies this matrix with another, overriding the values of this matrix.\nThe passed matrix is assumed to be on the right-hand side.\n" + "value": "A property for accessing/modifying the linear acceleration in the x axis.\nThe acceleration changes the velocity over time.\n" }, { - "type": "method", - "signature": "public {Matrix2D} combine(Matrix2D);", + "type": "example", "contents": [ { - "type": "param", - "name": "{Matrix2D} mtrxRH", - "description": "" - }, - { - "type": "return", - "value": "{Matrix2D} this matrix after combination" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, Motion\");\n\nvar ax = ent.ax; // retrieve the linear acceleration in the x axis\nent.ax += 1; // increase the linear acceleration in the x axis\nent.ax = 0; // reset the linear acceleration in the x axis\n```" } ] } ], - "name": ".combine", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".ax", + "comp": "Motion" }, { - "file": "src/math.js", - "startLine": 795, - "endLine": 804, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1471, + "endLine": 1486, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nChecks for the numeric equality of this matrix versus another.\n" + "value": "A property for accessing/modifying the linear acceleration in the y axis.\nThe acceleration changes the velocity over time.\n" }, { - "type": "method", - "signature": "public {Boolean} equals(Matrix2D);", + "type": "example", "contents": [ { - "type": "param", - "name": "{Matrix2D} mtrxRH", - "description": "" - }, - { - "type": "return", - "value": "{Boolean} true if the two matrices are numerically equal" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, Motion\");\n\nvar ay = ent.ay; // retrieve the linear acceleration in the y axis\nent.ay += 1; // increase the linear acceleration in the y axis\nent.ay = 0; // reset the linear acceleration in the y axis\n```" } ] } ], - "name": ".equals", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".ay", + "comp": "Motion" }, { - "file": "src/math.js", - "startLine": 812, - "endLine": 820, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1489, + "endLine": 1501, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nCalculates the determinant of this matrix\n" + "value": "A number that reflects the change in x (difference between the old & new x) that was applied in the last frame.\n" }, { - "type": "method", - "signature": "public {Number} determinant();", + "type": "example", "contents": [ { - "type": "return", - "value": "{Number} det(this matrix)" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, Motion\");\n\nvar dx = ent.dx; // the change of x in the last frame\n```" } ] } ], - "name": ".determinant", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".dx", + "comp": "Motion" }, { - "file": "src/math.js", - "startLine": 826, - "endLine": 835, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1504, + "endLine": 1516, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nInverts this matrix if possible\n" + "value": "A number that reflects the change in y (difference between the old & new y) that was applied in the last frame.\n" }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, Motion\");\n\nvar dy = ent.dy; // the change of y in the last frame\n```" + } + ] + } + ], + "name": ".dy", + "comp": "Motion" + }, + { + "file": "src/spatial/2d.js", + "startLine": 1541, + "endLine": 1548, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public {Matrix2D} invert();", + "signature": "public this .resetMotion()", "contents": [ { "type": "return", - "value": "{Matrix2D} this inverted matrix or the original matrix on failure" + "value": "this" } ] }, { - "type": "xref", - "xrefs": [ - ".isInvertible" - ] + "type": "raw", + "value": "Reset all linear motion (resets velocity, acceleration, motionDelta)." } ], - "name": ".invert", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".resetMotion", + "comp": "Motion" }, { - "file": "src/math.js", - "startLine": 861, - "endLine": 869, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nReturns true if this matrix is the identity matrix\n" - }, + "file": "src/spatial/2d.js", + "startLine": 1557, + "endLine": 1572, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public {Boolean} isIdentity();", + "signature": "public Vector2D .motionDelta()", "contents": [ { "type": "return", - "value": "{Boolean}" + "value": "A Vector2D with the properties {x, y} that reflect the change in x & y." } ] - } - ], - "name": ".isIdentity", - "comp": "Crafty.math.Matrix2D", - "public": true - }, - { - "file": "src/math.js", - "startLine": 875, - "endLine": 884, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "raw", - "value": "\nDetermines is this matrix is invertible.\n" + "value": "Returns the difference between the old & new position that was applied in the last frame.\n" }, { - "type": "method", - "signature": "public {Boolean} isInvertible();", + "type": "example", "contents": [ { - "type": "return", - "value": "{Boolean} true if this matrix is invertible" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, Motion\");\n\nvar deltaY = ent.motionDelta().y; // the change of y in the last frame\n```" } ] }, { "type": "xref", "xrefs": [ - ".invert" + "Crafty.math.Vector2D" ] } ], - "name": ".isInvertible", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".motionDelta", + "comp": "Motion" }, { - "file": "src/math.js", - "startLine": 890, - "endLine": 899, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1577, + "endLine": 1598, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nApplies a counter-clockwise pre-rotation to this matrix\n" + "value": "Method for accessing/modifying the linear(x,y) velocity.\nThe velocity remains constant over time, unless the acceleration increases the velocity.\n" }, { "type": "method", - "signature": "public {Matrix2D} preRotate(Number);", + "signature": "public Vector2D .velocity()", "contents": [ - { - "type": "param", - "name": "{number} rads", - "description": "angle to rotate in radians" - }, { "type": "return", - "value": "{Matrix2D} this matrix after pre-rotation" + "value": "The velocity Vector2D with the properties {x, y} that reflect the velocities in the direction of the entity." } ] - } - ], - "name": ".preRotate", - "comp": "Crafty.math.Matrix2D", - "public": true - }, - { - "file": "src/math.js", - "startLine": 915, - "endLine": 925, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "raw", - "value": "\nApplies a pre-scaling to this matrix\n" + "value": "Returns the current velocity. You can access/modify the properties in order to retrieve/change the velocity.\n" }, { - "type": "method", - "signature": "public {Matrix2D} preScale(Number[, Number]);", + "type": "example", "contents": [ { - "type": "param", - "name": "{Number} scalarX", - "description": "" - }, - { - "type": "param", - "name": "{Number} [scalarY] scalarX is used if scalarY is undefined", - "description": "" - }, - { - "type": "return", - "value": "{Matrix2D} this after pre-scaling" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, Motion\");\n\nvar vel = ent.velocity(); //returns the velocity vector\nvel.x; // retrieve the velocity in the x direction\nvel.x = 0; // set the velocity in the x direction\nvel.x += 4 // add to the velocity in the x direction\n```" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.math.Vector2D" + ] } ], - "name": ".preScale", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".velocity", + "comp": "Motion" }, { - "file": "src/math.js", - "startLine": 939, - "endLine": 950, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1604, + "endLine": 1625, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nApplies a pre-translation to this matrix\n" - }, - { - "type": "method", - "signature": "public {Matrix2D} preTranslate(Vector2D);", - "contents": [] + "value": "Method for accessing/modifying the linear(x,y) acceleration.\nThe acceleration increases the velocity over time, resulting in ever increasing speed.\n" }, { "type": "method", - "signature": "public {Matrix2D} preTranslate(Number, Number);", + "signature": "public Vector2D .acceleration()", "contents": [ - { - "type": "param", - "name": "{Number|Vector2D} dx", - "description": "" - }, - { - "type": "param", - "name": "{Number} dy", - "description": "" - }, { "type": "return", - "value": "{Matrix2D} this matrix after pre-translation" + "value": "The acceleration Vector2D with the properties {x, y} that reflects the acceleration in the direction of the entity." } ] - } - ], - "name": ".preTranslate", - "comp": "Crafty.math.Matrix2D", - "public": true - }, - { - "file": "src/math.js", - "startLine": 964, - "endLine": 973, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "raw", - "value": "\nApplies a counter-clockwise post-rotation to this matrix\n" + "value": "Returns the current acceleration. You can access/modify the properties in order to retrieve/change the acceleration.\n" }, { - "type": "method", - "signature": "public {Matrix2D} rotate(Number);", + "type": "example", "contents": [ { - "type": "param", - "name": "{Number} rads", - "description": "angle to rotate in radians" - }, - { - "type": "return", - "value": "{Matrix2D} this matrix after rotation" + "type": "raw", + "value": "```\nvar ent = Crafty.e(\"2D, Motion\");\n\nvar acc = ent.acceleration(); //returns the acceleration object\nacc.x; // retrieve the acceleration in the x direction\nacc.x = 0; // set the acceleration in the x direction\nacc.x += 4 // add to the acceleration in the x direction\n```" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.math.Vector2D" + ] } ], - "name": ".rotate", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".acceleration", + "comp": "Motion" }, { - "file": "src/math.js", - "startLine": 992, - "endLine": 1002, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1676, + "endLine": 1696, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nApplies a post-scaling to this matrix\n" + "value": "The constructor for a polygon object used for hitboxes and click maps. Takes a set of points as an\nargument, giving alternately the x and y coordinates of the polygon's vertices in order.\n\nThe constructor accepts the coordinates as either a single array or as a set of individual arguments.\nIf passed an array, the current implementation will use that array internally -- do not attempt to reuse it.\n\nWhen creating a polygon for an entity, each point should be offset or relative from the entities `x` and `y`\n(don't include the absolute values as it will automatically calculate this).\n\n" }, { - "type": "method", - "signature": "public {Matrix2D} scale(Number[, Number]);", + "type": "example", "contents": [ { - "type": "param", - "name": "{Number} scalarX", - "description": "" - }, - { - "type": "param", - "name": "{Number} [scalarY] scalarX is used if scalarY is undefined", - "description": "" - }, - { - "type": "return", - "value": "{Matrix2D} this after post-scaling" + "type": "raw", + "value": "Two ways to create a triangle with vertices at `(50, 0)`, `(100, 100)` and `(0, 100)`.\n```\nnew Crafty.polygon([50, 0, 100, 100, 0, 100]);\nnew Crafty.polygon(50, 0, 100, 100, 0, 100);\n```" } ] } ], - "name": ".scale", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": "Crafty.polygon", + "categories": [ + "2D" + ] }, { - "file": "src/math.js", - "startLine": 1018, - "endLine": 1033, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1705, + "endLine": 1720, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nSets the values of this matrix\n" - }, - { - "type": "method", - "signature": "public {Matrix2D} setValues(Matrix2D);", - "contents": [] - }, { "type": "method", - "signature": "public {Matrix2D} setValues(Number, Number, Number, Number, Number, Number);", + "signature": "public Boolean .containsPoint(Number x, Number y)", "contents": [ { "type": "param", - "name": "{Matrix2D|Number} a", - "description": "" - }, - { - "type": "param", - "name": "{Number} b", - "description": "" - }, - { - "type": "param", - "name": "{Number} c", - "description": "" - }, - { - "type": "param", - "name": "{Number} d", - "description": "" - }, - { - "type": "param", - "name": "{Number} e", - "description": "" + "name": "x", + "description": "X position of the point" }, { "type": "param", - "name": "{Number} f", - "description": "" - }, - { - "type": "return", - "value": "{Matrix2D} this matrix containing the new values" + "name": "y", + "description": "Y position of the point" } ] - } - ], - "name": ".setValues", - "comp": "Crafty.math.Matrix2D", - "public": true - }, - { - "file": "src/math.js", - "startLine": 1055, - "endLine": 1063, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "raw", - "value": "\nReturns the string representation of this matrix.\n" + "value": "Method is used to determine if a given point is contained by the polygon.\n" }, { - "type": "method", - "signature": "public {String} toString();", + "type": "example", "contents": [ { - "type": "return", - "value": "{String}" + "type": "raw", + "value": "```\nvar poly = new Crafty.polygon([50, 0, 100, 100, 0, 100]);\npoly.containsPoint(50, 50); //TRUE\npoly.containsPoint(0, 0); //FALSE\n```" } ] } ], - "name": ".toString", - "comp": "Crafty.math.Matrix2D", - "public": true + "name": ".containsPoint", + "comp": "Crafty.polygon" }, { - "file": "src/math.js", - "startLine": 1070, - "endLine": 1081, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1734, + "endLine": 1749, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "raw", - "value": "\nApplies a post-translation to this matrix\n" - }, - { - "type": "method", - "signature": "public {Matrix2D} translate(Vector2D);", - "contents": [] - }, { "type": "method", - "signature": "public {Matrix2D} translate(Number, Number);", + "signature": "public void .shift(Number x, Number y)", "contents": [ { "type": "param", - "name": "{Number|Vector2D} dx", - "description": "" + "name": "x", + "description": "Amount to shift the `x` axis" }, { "type": "param", - "name": "{Number} dy", - "description": "" - }, - { - "type": "return", - "value": "{Matrix2D} this matrix after post-translation" + "name": "y", + "description": "Amount to shift the `y` axis" } ] - } - ], - "name": ".translate", - "comp": "Crafty.math.Matrix2D", - "public": true - }, - { - "file": "src/model.js", - "startLine": 4, - "endLine": 36, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + }, { "type": "raw", - "value": "Model is a component that offers new features for isolating business\nlogic in your application. It offers default values, dirty values,\nand deep events on your data.\n\nAll data should be accessed via the appropriate methods `.get`, `.set`,\nand `.data` for the proper events to be triggered. It is not encouraged\nto access them directly.\n\nDirty values make it simple to inspect a model and see what values have changed.\n\nDeep events allow you to bind to specific fields, like `name` or even deep fields\nlike `contact.email` and get notified when those specific fields are updated.\n" + "value": "Shifts every single point in the polygon by the specified amount.\n" }, { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "Change", - "description": "When any data on the model has changed.", - "objName": "Data", - "objProp": null - }, - { - "type": "trigger", - "event": "Change[key]", - "description": "When the specific key on the model has changed.", - "objName": "Data", - "objProp": null - }, + "type": "example", + "contents": [ { - "type": "trigger", - "event": "Change[key.key]", - "description": "The nested key value has changed.", - "objName": "Data", - "objProp": null + "type": "raw", + "value": "```\nvar poly = new Crafty.polygon([50, 0, 100, 100, 0, 100]);\npoly.shift(5,5);\n//[[55, 5, 105, 5, 5, 105];\n```" } ] + } + ], + "name": ".shift", + "comp": "Crafty.polygon" + }, + { + "file": "src/spatial/2d.js", + "startLine": 1759, + "endLine": 1772, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "method", + "signature": "public void .clone()", + "contents": [] + }, + { + "type": "raw", + "value": "Returns a clone of the polygon.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.c('Person', {\n name: 'Fox',\n init: function() { this.requires('Model'); }\n});\nperson = Crafty.e('Person').attr({name: 'blaine'});\nperson.bind('Change[name]', function() {\n console.log('name changed!');\n});\nperson.attr('name', 'blainesch'); // Triggers event\nperson.is_dirty('name'); // true\nperson.changed // name\n```" + "value": "```\nvar poly = new Crafty.polygon([50, 0, 100, 100, 0, 100]);\nvar shiftedpoly = poly.clone().shift(5,5);\n//[55, 5, 105, 5, 5, 105], but the original polygon is unchanged\n```" } ] } ], - "name": "Model", - "categories": [ - "Model" - ] + "name": ".clone", + "comp": "Crafty.polygon" }, { - "file": "src/model.js", - "startLine": 76, - "endLine": 92, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1794, + "endLine": 1810, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Helps determine when data or the entire component is \"dirty\" or has changed attributes.\n" + "value": "Circle object used for hitboxes and click maps. Must pass a `x`, a `y` and a `radius` value.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nperson = Crafty.e('Person').attr({name: 'Fox', age: 24})\nperson.is_dirty() // false\nperson.is_dirty('name') // false\n\nperson.attr('name', 'Lucky');\nperson.is_dirty(); // true\nperson.is_dirty('name'); // true\nperson.is_dirty('age'); // false\nperson.changed; // ['name']\n```" + "value": "```\nvar centerX = 5,\n centerY = 10,\n radius = 25;\n\nnew Crafty.circle(centerX, centerY, radius);\n```\n\nWhen creating a circle for an entity, each point should be offset or relative from the entities `x` and `y`\n(don't include the absolute values as it will automatically calculate this)." } ] } ], - "name": ".is_dirty", - "comp": "Model" + "name": "Crafty.circle", + "categories": [ + "2D" + ] }, { - "file": "src/particles.js", - "startLine": 4, - "endLine": 10, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1828, + "endLine": 1843, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ + "type": "method", + "signature": "public Boolean .containsPoint(Number x, Number y)", + "contents": [ { - "type": "trigger", - "event": "ParticleEnd", - "description": "when the particle animation has finished", - "objName": "Data", - "objProp": null + "type": "param", + "name": "x", + "description": "X position of the point" + }, + { + "type": "param", + "name": "y", + "description": "Y position of the point" } ] }, { "type": "raw", - "value": "Based on Parcycle by Mr. Speaker, licensed under the MIT, Ported by Leo Koppelkamm\n**This is canvas only & won't do anything if the browser doesn't support it!**\nTo see how this works take a look in https://github.com/craftyjs/Crafty/blob/master/src/particles.js" + "value": "Method is used to determine if a given point is contained by the circle.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nvar circle = new Crafty.circle(0, 0, 10);\ncircle.containsPoint(0, 0); //TRUE\ncircle.containsPoint(50, 50); //FALSE\n```" + } + ] } ], - "name": "Particles", - "categories": [ - "Graphics" - ] + "name": ".containsPoint", + "comp": "Crafty.circle" }, { - "file": "src/particles.js", - "startLine": 19, - "endLine": 58, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/2d.js", + "startLine": 1853, + "endLine": 1868, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this .particles(Object options)", + "signature": "public void .shift(Number x, Number y)", "contents": [ { "type": "param", - "name": "options", - "description": "Map of options that specify the behavior and look of the particles." + "name": "x", + "description": "Amount to shift the `x` axis" + }, + { + "type": "param", + "name": "y", + "description": "Amount to shift the `y` axis" } ] }, { "type": "raw", - "value": "" + "value": "Shifts the circle by the specified amount.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nvar options = {\n\tmaxParticles: 150,\n\tsize: 18,\n\tsizeRandom: 4,\n\tspeed: 1,\n\tspeedRandom: 1.2,\n\t// Lifespan in frames\n\tlifeSpan: 29,\n\tlifeSpanRandom: 7,\n\t// Angle is calculated clockwise: 12pm is 0deg, 3pm is 90deg etc.\n\tangle: 65,\n\tangleRandom: 34,\n\tstartColour: [255, 131, 0, 1],\n\tstartColourRandom: [48, 50, 45, 0],\n\tendColour: [245, 35, 0, 0],\n\tendColourRandom: [60, 60, 60, 0],\n\t// Only applies when fastMode is off, specifies how sharp the gradients are drawn\n\tsharpness: 20,\n\tsharpnessRandom: 10,\n\t// Random spread from origin\n\tspread: 10,\n\t// How many frames should this last\n\tduration: -1,\n\t// Will draw squares instead of circle gradients\n\tfastMode: false,\n\tgravity: { x: 0, y: 0.1 },\n\t// sensible values are 0-3\n\tjitter: 0\n}\n\nCrafty.e(\"2D,Canvas,Particles\").particles(options);\n```" + "value": "```\nvar circle = new Crafty.circle(0, 0, 10);\ncircle.shift(5,5);\n//{x: 5, y: 5, radius: 10};\n```" } ] } ], - "name": ".particles", - "comp": "Particles" + "name": ".shift", + "comp": "Crafty.circle" }, { - "file": "src/scenes.js", - "startLine": 8, - "endLine": 80, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/collision.js", + "startLine": 4, + "endLine": 22, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "triggers", "events": [ { "type": "trigger", - "event": "SceneChange", - "description": "just before a new scene is initialized", + "event": "HitOn", + "description": "Triggered when collisions occur. Will not trigger again until collisions of this type cease, or an event is requested once more (using `resetHitChecks(component)`).", "objName": "Data", - "objProp": "{ oldScene:String, newScene:String }" + "objProp": "{ hitData }" }, { "type": "trigger", - "event": "SceneDestroy", - "description": "just before the current scene is destroyed", - "objName": "Data", - "objProp": "{ newScene:String }" + "event": "HitOff", + "description": "Triggered when collision with a specific component type ceases", + "objName": "componentName", + "objProp": "String" } ] }, { "type": "raw", - "value": "" + "value": "Component to detect collision between any two convex polygons.\n\nIf collision checks are registered for multiple component and collisions with\nmultiple types occur simultaniously, each collision will cause an individual\nevent to fire.\n" + }, + { + "type": "note", + "value": "All data received from events is only valid for the duration of the event's callback. If you wish to preserve the data, make a copy of it." + }, + { + "type": "raw", + "value": "For a description of collision event data (hitData above), see the documentation for\n`.hit()`.\n" + } + ], + "name": "Collision", + "categories": [ + "2D" + ] + }, + { + "file": "src/spatial/collision.js", + "startLine": 38, + "endLine": 77, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "triggers", + "events": [ + { + "type": "trigger", + "event": "NewHitbox", + "description": "when a new hitbox is assigned", + "objName": "Data", + "objProp": "Crafty.polygon" + } + ] }, { "type": "method", - "signature": "public void Crafty.scene(String sceneName, Function init[, Function uninit])", + "signature": "public this .collision([Crafty.polygon polygon])", "contents": [ { "type": "param", - "name": "sceneName", - "description": "Name of the scene to add" - }, - { - "type": "param", - "name": "init", - "description": "Function to execute when scene is played" - }, - { - "type": "param", - "name": "uninit", - "description": "Function to execute before next scene is played, after entities with `2D` are destroyed" + "name": "polygon", + "description": "Optional Crafty.polygon object that will act as the hit area." } ] }, - { - "type": "raw", - "value": "This is equivalent to calling `Crafty.defineScene`.\n" - }, { "type": "method", - "signature": "public void Crafty.scene(String sceneName[, Data])", + "signature": "public this .collision([Array coordinatePairs])", "contents": [ { "type": "param", - "name": "sceneName", - "description": "Name of scene to play" - }, + "name": "coordinatePairs", + "description": "Optional array of x, y coordinate pairs to generate a hit area polygon." + } + ] + }, + { + "type": "method", + "signature": "public this .collision([x1, y1,.., xN, yN])", + "contents": [ { "type": "param", - "name": "Data", - "description": "The init function of the scene will be called with this data as its parameter. Can be of any type other than a function." + "name": "point#", + "description": "Optional list of x, y coordinate pairs to generate a hit area polygon." } ] }, { "type": "raw", - "value": "This is equivalent to calling `Crafty.enterScene`.\n\nMethod to create scenes on the stage. Pass an ID and function to register a scene.\n\nTo play a scene, just pass the ID. When a scene is played, all\npreviously-created entities with the `2D` component are destroyed. The\nviewport is also reset.\n\nYou can optionally specify an arugment that will be passed to the scene's init function.\n\nIf you want some entities to persist over scenes (as in, not be destroyed)\nsimply add the component `Persist`.\n" + "value": "Constructor that takes a polygon, an array of points or a list of points to use as the hit area,\nwith points being relative to the object's position in its unrotated state.\n\nThe hit area must be a convex shape and not concave for collision detection to work properly.\n\nIf no parameter is passed, the x, y, w, h properties of the entity will be used, and the hitbox will be resized when the entity is.\n\nIf a hitbox is set that is outside of the bounds of the entity itself, there will be a small performance penalty as it is tracked separately.\n\nIn order for your custom hitbox to have any effect, you have to add the `Collision` component to all other entities this entity needs to collide with using this custom hitbox.\nOn the contrary the collisions will be resolved using the default hitbox. See `.hit()` - `MBR` represents default hitbox collision, `SAT` represents custom hitbox collision.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.defineScene(\"loading\", function() {\n Crafty.background(\"#000\");\n Crafty.e(\"2D, DOM, Text\")\n .attr({ w: 100, h: 20, x: 150, y: 120 })\n .text(\"Loading\")\n .css({ \"text-align\": \"center\"})\n .textColor(\"#FFFFFF\");\n});\n\nCrafty.defineScene(\"UFO_dance\",\n function() {Crafty.background(\"#444\"); Crafty.e(\"UFO\");},\n function() {...send message to server...});\n\n// An example of an init function which accepts arguments, in this case an object.\nCrafty.defineScene(\"square\", function(attributes) {\n Crafty.background(\"#000\");\n Crafty.e(\"2D, DOM, Color\")\n .attr(attributes)\n .color(\"red\");\n\n});\n\n```\nThis defines (but does not play) two scenes as discussed below.\n```\nCrafty.enterScene(\"loading\");\n```\nThis command will clear the stage by destroying all `2D` entities (except\nthose with the `Persist` component). Then it will set the background to\nblack and display the text \"Loading\".\n```\nCrafty.enterScene(\"UFO_dance\");\n```\nThis command will clear the stage by destroying all `2D` entities (except\nthose with the `Persist` component). Then it will set the background to\ngray and create a UFO entity. Finally, the next time the game encounters\nanother command of the form `Crafty.scene(scene_name)` (if ever), then the\ngame will send a message to the server.\n```\nCrafty.enterScene(\"square\", {x:10, y:10, w:20, h:20});\n```\nThis will clear the stage, set the background black, and create a red square with the specified position and dimensions.\n```" + "value": "```\nCrafty.e(\"2D, Collision\").collision(\n new Crafty.polygon([50, 0, 100, 100, 0, 100])\n);\n\nCrafty.e(\"2D, Collision\").collision([50, 0, 100, 100, 0, 100]);\n\nCrafty.e(\"2D, Collision\").collision(50, 0, 100, 100, 0, 100);\n```\n" } ] + }, + { + "type": "xref", + "xrefs": [ + "Crafty.polygon" + ] } ], - "name": "Crafty.scene", - "categories": [ - "Scenes", - "Stage" - ] + "name": ".collision", + "comp": "Collision" }, { - "file": "src/sound.js", - "startLine": 5, - "endLine": 15, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/collision.js", + "startLine": 223, + "endLine": 260, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public Boolean/Array hit(String component)", + "contents": [ + { + "type": "param", + "name": "component", + "description": "Check collision with entities that have this component applied to them." + }, + { + "type": "return", + "value": "`false` if there is no collision. If a collision is detected, returns an Array of collision data objects (see below)." + } + ] + }, { "type": "raw", - "value": "\nAdd sound files and play them. Chooses best format for browser support.\nDue to the nature of HTML5 audio, three types of audio files will be\nrequired for cross-browser capabilities. These formats are MP3, Ogg and WAV.\nWhen sound was not muted on before pause, sound will be unmuted after unpause.\nWhen sound is muted Crafty.pause() does not have any effect on sound\n\nThe maximum number of sounds that can be played simultaneously is defined by Crafty.audio.maxChannels. The default value is 7." + "value": "Tests for collisions with entities that have the specified component\napplied to them.\nIf a collision is detected, data regarding the collision will be present in\nthe array returned by this method.\nIf no collisions occur, this method returns false.\n\nFollowing is a description of a collision data object that this method may\nreturn: The returned collision data will be an Array of Objects with the\ntype of collision used, the object collided and if the type used was SAT (a polygon was used as the hitbox) then an amount of overlap.\n```\n[{\n obj: [entity],\n type: [\"MBR\" or \"SAT\"],\n overlap: [number]\n}]\n```\n\n- **obj:** The entity with which the collision occured.\n- **type:** Collision detection method used. One of:\n - *MBR:* Standard axis aligned rectangle intersection (`.intersect` in the 2D component).\n - *SAT:* Collision between any two convex polygons. Used when both colliding entities have the `Collision` component applied to them.\n- **overlap:** If SAT collision was used, this will signify the overlap percentage between the colliding entities.\n\nKeep in mind that both entities need to have the `Collision` component, if you want to check for `SAT` (custom hitbox) collisions between them.\n\nIf you want more fine-grained control consider using `Crafty.map.search()`.\n" + }, + { + "type": "xref", + "xrefs": [ + "2D" + ] } ], - "name": "Crafty.audio", - "categories": [ - "Audio" - ] + "name": ".hit", + "comp": "Collision" }, { - "file": "src/sound.js", - "startLine": 53, - "endLine": 59, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/collision.js", + "startLine": 311, + "endLine": 326, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.supports(String extension)", + "signature": "public this .onHit(String component, Function callbackOn[, Function callbackOff])", "contents": [ { "type": "param", - "name": "extension", - "description": "A file extension to check audio support for" + "name": "component", + "description": "Component to check collisions for." + }, + { + "type": "param", + "name": "callbackOn", + "description": "Callback method to execute upon collision with component. Will be passed the results of the collision check in the same format documented for hit()." + }, + { + "type": "param", + "name": "callbackOff", + "description": "Callback method executed once as soon as collision stops." } ] }, { "type": "raw", - "value": "\nReturn true if the browser thinks it can play the given file type, otherwise false" + "value": "Creates an EnterFrame event calling `.hit()` each frame. When a collision is detected the `callbackOn` will be invoked.\nNote that the `callbackOn` will be invoked every frame the collision is active, not just the first time the collision occurs.\n\nIf you want more fine-grained control consider using `.checkHits()`, `.hit()` or even `Crafty.map.search()`.\n" + }, + { + "type": "xref", + "xrefs": [ + ".checkHits", + ".hit" + ] } ], - "name": "Crafty.audio.supports", - "comp": "Crafty.audio" + "name": ".onHit", + "comp": "Collision" }, { - "file": "src/sound.js", - "startLine": 80, - "endLine": 89, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/collision.js", + "startLine": 371, + "endLine": 412, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.create(String id, String url)", + "signature": "public this .checkHits(String componentList)", "contents": [ { "type": "param", - "name": "id", - "description": "A string to refer to sounds" - }, + "name": "componentList", + "description": "A comma seperated list of components to check for collisions with." + } + ] + }, + { + "type": "method", + "signature": "public this .checkHits(String component1[, .., String componentN])", + "contents": [ { "type": "param", - "name": "url", - "description": "A string pointing to the sound file" + "name": "component#", + "description": "A component to check for collisions with." + } + ] + }, + { + "type": "raw", + "value": "Performs collision checks against all entities that have at least one of\nthe components specified when calling this method. If collisions occur,\na \"HitOn\" event containing the collision information will be fired for the\nentity on which this method was invoked. See the documentation for `.hit()`\nfor a description of collision data contained in the event.\nWhen a collision that was reported ends, a corresponding \"HitOff\" event\nwill be fired.\n\nCalling this method more than once for the same component type will not\ncause redundant hit checks.\n\nIf you want more fine-grained control consider using `.hit()` or even `Crafty.map.search()`.\n" + }, + { + "type": "note", + "value": "Hit checks are performed upon entering each new frame (using the *EnterFrame* event). It is entirely possible for object to move in said frame after the checks were performed (even if the more is the result of *EnterFrame*, as handlers run in no particular order). In such a case, the hit events will not fire until the next check is performed in the following frame." + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.e(\"2D, Collision\")\n .checkHits('Solid') // check for collisions with entities that have the Solid component in each frame\n .bind(\"HitOn\", function(hitData) {\n Crafty.log(\"Collision with Solid entity occurred for the first time.\");\n })\n .bind(\"HitOff\", function(comp) {\n Crafty.log(\"Collision with Solid entity ended.\");\n });\n```\n" } ] }, { - "type": "raw", - "value": "\nCreates an audio asset with the given id and resource. `Crafty.audio.add` is a more flexible interface that allows cross-browser compatibility.\n\nIf the sound file extension is not supported, returns false; otherwise, returns the audio asset." + "type": "xref", + "xrefs": [ + ".hit" + ] } ], - "name": "Crafty.audio.create", - "comp": "Crafty.audio" + "name": ".checkHits", + "comp": "Collision" }, { - "file": "src/sound.js", - "startLine": 115, - "endLine": 155, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/collision.js", + "startLine": 439, + "endLine": 468, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.add(String id, String url)", - "contents": [ - { - "type": "param", - "name": "id", - "description": "A string to refer to sounds" - }, - { - "type": "param", - "name": "url", - "description": "A string pointing to the sound file" - } - ] + "signature": "public this .ignoreHits()", + "contents": [] }, { "type": "method", - "signature": "public this Crafty.audio.add(String id, Array urls)", + "signature": "public this .ignoreHits(String componentList)", "contents": [ { "type": "param", - "name": "urls", - "description": "Array of urls pointing to different format of the same sound, selecting the first that is playable" + "name": "componentList", + "description": "A comma separated list of components to stop checking for collisions with." } ] }, { "type": "method", - "signature": "public this Crafty.audio.add(Object map)", + "signature": "public this .ignoreHits(String component1[, .., String componentN])", "contents": [ { "type": "param", - "name": "map", - "description": "key-value pairs where the key is the `id` and the value is either a `url` or `urls`" + "name": "component#", + "description": "A component to stop checking for collisions with." } ] }, { "type": "raw", - "value": "\nLoads a sound to be played. Due to the nature of HTML5 audio,\nthree types of audio files will be required for cross-browser capabilities.\nThese formats are MP3, Ogg and WAV.\n\nPassing an array of URLs will determine which format the browser can play and select it over any other.\n\nAccepts an object where the key is the audio name and\neither a URL or an Array of URLs (to determine which type to use).\n\nThe ID you use will be how you refer to that sound when using `Crafty.audio.play`.\n" + "value": "Stops checking for collisions with all, or certain, components. If called\nwithout arguments, this method will cause all collision checks on the\nentity to cease. To disable checks for collisions with specific\ncomponents, specify the components as a comma separated string or as\na set of arguments.\n\nCalling this method with component names for which there are no collision\nchecks has no effect.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\n//adding audio from an object\nCrafty.audio.add({\n shoot: [\"sounds/shoot.wav\",\n \"sounds/shoot.mp3\",\n \"sounds/shoot.ogg\"]\n});\n\n//adding a single sound\nCrafty.audio.add(\"walk\", [\n\"sounds/walk.mp3\",\n\"sounds/walk.ogg\",\n\"sounds/walk.wav\"\n]);\n\n//only one format\nCrafty.audio.add(\"jump\", \"sounds/jump.mp3\");\n```" + "value": "```\nCrafty.e(\"2D, Collision\")\n .checkHits('Solid')\n ...\n .ignoreHits('Solid'); // stop checking for collisions with entities that have the Solid component\n```" } ] } ], - "name": "Crafty.audio.add", - "comp": "Crafty.audio" + "name": ".ignoreHits", + "comp": "Collision" }, { - "file": "src/sound.js", - "startLine": 190, - "endLine": 213, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/collision.js", + "startLine": 501, + "endLine": 532, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.play(String id)", + "signature": "public this .resetHitChecks()", "contents": [] }, { "type": "method", - "signature": "public this Crafty.audio.play(String id, Number repeatCount)", - "contents": [] + "signature": "public this .resetHitChecks(String componentList)", + "contents": [ + { + "type": "param", + "name": "componentList", + "description": "A comma seperated list of components to re-check for collisions with." + } + ] }, { "type": "method", - "signature": "public this Crafty.audio.play(String id, Number repeatCount, Number volume)", + "signature": "public this .resetHitChecks(String component1[, .., String componentN])", "contents": [ { "type": "param", - "name": "id", - "description": "A string to refer to sounds" - }, - { - "type": "param", - "name": "repeatCount", - "description": "Repeat count for the file, where -1 stands for repeat forever." - }, - { - "type": "param", - "name": "volume", - "description": "volume can be a number between 0.0 and 1.0" - }, - { - "type": "return", - "value": "The audio element used to play the sound. Null if the call failed due to a lack of open channels." + "name": "component#", + "description": "A component to re-check for collisions with." } ] }, { "type": "raw", - "value": "\nWill play a sound previously added by using the ID that was used in `Crafty.audio.add`.\nHas a default maximum of 5 channels so that the same sound can play simultaneously unless all of the channels are playing.\n\n*Note that the implementation of HTML5 Audio is buggy at best.*\n" + "value": "Causes collision events to be received for collisions that are already\ntaking place (normally, an additional event would not fire before said\ncollisions cease and happen another time).\nIf called without arguments, this method will cause all collision checks on the\nentity to fire events once more. To re-check for collisions with specific\ncomponents, specify the components as a comma separated string or as\na set of arguments.\n\nCalling this method with component names for which there are no collision\nchecks has no effect.\n" }, { "type": "example", "contents": [ { "type": "raw", - "value": "```\nCrafty.audio.play(\"walk\");\n\n//play and repeat forever\nCrafty.audio.play(\"backgroundMusic\", -1);\nCrafty.audio.play(\"explosion\",1,0.5); //play sound once with volume of 50%\n```" + "value": "```\n// this example fires the HitOn event each frame the collision with the Solid entity is active, instead of just the first time the collision occurs.\nCrafty.e(\"2D, Collision\")\n .checkHits('Solid')\n .bind(\"HitOn\", function(hitData) {\n Crafty.log(\"Collision with Solid entity was reported in this frame again!\");\n this.resetHitChecks('Solid'); // fire the HitOn event in the next frame also, if the collision is still active.\n })\n```" } ] } ], - "name": "Crafty.audio.play", - "comp": "Crafty.audio" + "name": ".resetHitChecks", + "comp": "Collision" }, { - "file": "src/sound.js", - "startLine": 260, - "endLine": 264, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 4, + "endLine": 9, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "A set of utility functions for common (and not so common) operations." + } + ], + "name": "Crafty.math", + "categories": [ + "Utilities" + ] + }, + { + "file": "src/spatial/math.js", + "startLine": 11, + "endLine": 19, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.setChannels(Number n)", + "signature": "public this Crafty.math.abs(Number n)", "contents": [ { "type": "param", "name": "n", - "description": "The maximum number of channels" + "description": "Some value." + }, + { + "type": "return", + "value": "Absolute value." } ] + }, + { + "type": "raw", + "value": "Returns the absolute value." } ], - "name": "Crafty.audio.setChannels", - "comp": "Crafty.audio" + "name": "Crafty.math.abs", + "comp": "Crafty.math" }, { - "file": "src/sound.js", - "startLine": 305, - "endLine": 319, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 24, + "endLine": 34, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.remove([String id])", + "signature": "public Number Crafty.math.amountOf(Number checkValue, Number minValue, Number maxValue)", "contents": [ { "type": "param", - "name": "id", - "description": "A string to refer to sounds" + "name": "checkValue", + "description": "Value that should checked with minimum and maximum." + }, + { + "type": "param", + "name": "minValue", + "description": "Bottom of the range" + }, + { + "type": "param", + "name": "maxValue", + "description": "Top of the range" + }, + { + "type": "return", + "value": "The position of the checked value in a coordinate system normalized such that `minValue` is 0 and `maxValue` is 1." } ] }, { "type": "raw", - "value": "\nWill stop the sound and remove all references to the audio object allowing the browser to free the memory.\nIf no id is given, all sounds will be removed.\n\nThis function uses audio path set in Crafty.path in order to remove sound from the assets object.\n" - }, + "value": "If checkValue is within the range, this will return a number between 0 and 1." + } + ], + "name": "Crafty.math.amountOf", + "comp": "Crafty.math" + }, + { + "file": "src/spatial/math.js", + "startLine": 43, + "endLine": 53, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { - "type": "example", + "type": "method", + "signature": "public Number Crafty.math.clamp(Number value, Number min, Number max)", "contents": [ { - "type": "raw", - "value": "```\nCrafty.audio.remove(\"walk\");\n```" + "type": "param", + "name": "value", + "description": "A value." + }, + { + "type": "param", + "name": "max", + "description": "Maximum that value can be." + }, + { + "type": "param", + "name": "min", + "description": "Minimum that value can be." + }, + { + "type": "return", + "value": "The value between minimum and maximum." } ] + }, + { + "type": "raw", + "value": "Restricts a value to be within a specified range." } ], - "name": "Crafty.audio.remove", - "comp": "Crafty.audio" + "name": "Crafty.math.clamp", + "comp": "Crafty.math" }, { - "file": "src/sound.js", - "startLine": 348, - "endLine": 360, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 63, + "endLine": 70, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this Crafty.audio.stop([Number ID])", - "contents": [] - }, { "type": "raw", - "value": "\nStops any playing sound. if id is not set, stop all sounds which are playing\n" + "value": "Converts angle from degree to radian." }, { - "type": "example", + "type": "method", + "signature": "public Number degToRad(angleInDeg)", "contents": [ { - "type": "raw", - "value": "```\n//all sounds stopped playing now\nCrafty.audio.stop();\n\n```" + "type": "param", + "name": "angleInDeg", + "description": "The angle in degrees." + }, + { + "type": "return", + "value": "The angle in radians." } ] } ], - "name": "Crafty.audio.stop", - "comp": "Crafty.audio" + "name": "Crafty.math.degToRad", + "comp": "Crafty.math" }, { - "file": "src/sound.js", - "startLine": 391, - "endLine": 403, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 75, + "endLine": 86, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.toggleMute()", - "contents": [] - }, - { - "type": "raw", - "value": "\nMute or unmute every Audio instance that is playing. Toggles between\npausing or playing depending on the state.\n" - }, - { - "type": "example", + "signature": "public Number Crafty.math.distance(Number x1, Number y1, Number x2, Number y2)", "contents": [ { - "type": "raw", - "value": "```\n//toggle mute and unmute depending on current state\nCrafty.audio.toggleMute();\n```" + "type": "param", + "name": "x1", + "description": "First x coordinate." + }, + { + "type": "param", + "name": "y1", + "description": "First y coordinate." + }, + { + "type": "param", + "name": "x2", + "description": "Second x coordinate." + }, + { + "type": "param", + "name": "y2", + "description": "Second y coordinate." + }, + { + "type": "return", + "value": "The distance between the two points." } ] + }, + { + "type": "raw", + "value": "Distance between two points." } ], - "name": "Crafty.audio.toggleMute", - "comp": "Crafty.audio" + "name": "Crafty.math.distance", + "comp": "Crafty.math" }, { - "file": "src/sound.js", - "startLine": 413, - "endLine": 423, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 92, + "endLine": 103, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.mute()", - "contents": [] - }, - { - "type": "raw", - "value": "\nMute every Audio instance that is playing.\n" - }, - { - "type": "example", + "signature": "public Number Crafty.math.lerp(Number value1, Number value2, Number amount)", "contents": [ { - "type": "raw", - "value": "```\nCrafty.audio.mute();\n```" + "type": "param", + "name": "value1", + "description": "One value." + }, + { + "type": "param", + "name": "value2", + "description": "Another value." + }, + { + "type": "param", + "name": "amount", + "description": "Amount of value2 to value1." + }, + { + "type": "return", + "value": "Linear interpolated value." } ] + }, + { + "type": "raw", + "value": "Linear interpolation. Passing amount with a value of 0 will cause value1 to be returned,\na value of 1 will cause value2 to be returned." } ], - "name": "Crafty.audio.mute", - "comp": "Crafty.audio" + "name": "Crafty.math.lerp", + "comp": "Crafty.math" }, { - "file": "src/sound.js", - "startLine": 428, - "endLine": 438, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 108, + "endLine": 116, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.unmute()", - "contents": [] - }, - { - "type": "raw", - "value": "\nUnmute every Audio instance that is playing.\n" - }, - { - "type": "example", + "signature": "public Number Crafty.math.negate(Number percent)", "contents": [ { - "type": "raw", - "value": "```\nCrafty.audio.unmute();\n```" + "type": "param", + "name": "percent", + "description": "The probability of returning `-1`" + }, + { + "type": "return", + "value": "1 or -1." } ] + }, + { + "type": "raw", + "value": "Returns `1` or `-1` randomly." } ], - "name": "Crafty.audio.unmute", - "comp": "Crafty.audio" + "name": "Crafty.math.negate", + "comp": "Crafty.math" }, { - "file": "src/sound.js", - "startLine": 444, - "endLine": 456, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 124, + "endLine": 132, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.pause(string ID)", + "signature": "public Number Crafty.math.radToDeg(Number angle)", "contents": [ { "type": "param", - "name": "{string} id", - "description": "The id of the audio object to pause" + "name": "angleInRad", + "description": "The angle in radian." + }, + { + "type": "return", + "value": "The angle in degree." } ] }, { "type": "raw", - "value": "\nPause the Audio instance specified by id param.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.audio.pause('music');\n```\n" - } - ] + "value": "Converts angle from radian to degree." } ], - "name": "Crafty.audio.pause", - "comp": "Crafty.audio" + "name": "Crafty.math.radToDeg", + "comp": "Crafty.math" }, { - "file": "src/sound.js", - "startLine": 470, - "endLine": 482, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 137, + "endLine": 145, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.unpause(string ID)", + "signature": "public Object Crafty.math.randomElementOfArray(Array array)", "contents": [ { "type": "param", - "name": "{string} id", - "description": "The id of the audio object to unpause" + "name": "array", + "description": "A specific array." + }, + { + "type": "return", + "value": "A random element of a specific array." } ] }, { "type": "raw", - "value": "\nResume playing the Audio instance specified by id param.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.audio.unpause('music');\n```\n" - } - ] + "value": "Returns a random element of a specific array." } ], - "name": "Crafty.audio.unpause", - "comp": "Crafty.audio" + "name": "Crafty.math.randomElementOfArray", + "comp": "Crafty.math" }, { - "file": "src/sound.js", - "startLine": 495, - "endLine": 507, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 150, + "endLine": 159, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public this Crafty.audio.togglePause(string ID)", + "signature": "public Number Crafty.math.randomInt(Number start, Number end)", "contents": [ { "type": "param", - "name": "{string} id", - "description": "The id of the audio object to pause/" + "name": "start", + "description": "Smallest int value that can be returned." + }, + { + "type": "param", + "name": "end", + "description": "Biggest int value that can be returned." + }, + { + "type": "return", + "value": "A random int." } ] }, { "type": "raw", - "value": "\nToggle the pause status of the Audio instance specified by id param.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.audio.togglePause('music');\n```\n" - } - ] + "value": "Returns a random int within a specific range." } ], - "name": "Crafty.audio.togglePause", - "comp": "Crafty.audio" + "name": "Crafty.math.randomInt", + "comp": "Crafty.math" }, { - "file": "src/sound.js", - "startLine": 525, - "endLine": 538, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 164, + "endLine": 173, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public Boolean Crafty.audio.isPlaying(string ID)", + "signature": "public Number Crafty.math.randomInt(Number start, Number end)", "contents": [ { "type": "param", - "name": "{string} id", - "description": "The id of the audio object" + "name": "start", + "description": "Smallest number value that can be returned." + }, + { + "type": "param", + "name": "end", + "description": "Biggest number value that can be returned." }, { "type": "return", - "value": "a Boolean indicating whether the audio is playing or not" + "value": "A random number." } ] }, { "type": "raw", - "value": "\nCheck if audio with the given ID is playing or not (on at least one channel).\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nvar isPlaying = Crafty.audio.isPlaying('music');\n```\n" - } - ] + "value": "Returns a random number in within a specific range." } ], - "name": "Crafty.audio.isPlaying", - "comp": "Crafty.audio" + "name": "Crafty.math.randomNumber", + "comp": "Crafty.math" }, { - "file": "src/sprite-animation.js", - "startLine": 5, - "endLine": 27, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 178, + "endLine": 189, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ + "type": "method", + "signature": "public Number Crafty.math.squaredDistance(Number x1, Number y1, Number x2, Number y2)", + "contents": [ { - "type": "trigger", - "event": "StartAnimation", - "description": "When an animation starts playing, or is resumed from the paused state", - "objName": "Data", - "objProp": "{Reel}" + "type": "param", + "name": "x1", + "description": "First x coordinate." }, { - "type": "trigger", - "event": "AnimationEnd", - "description": "When the animation finishes", - "objName": "Data", - "objProp": "{ Reel }" + "type": "param", + "name": "y1", + "description": "First y coordinate." }, { - "type": "trigger", - "event": "FrameChange", - "description": "Each time the frame of the current reel changes", - "objName": "Data", - "objProp": "{ Reel }" + "type": "param", + "name": "x2", + "description": "Second x coordinate." }, { - "type": "trigger", - "event": "ReelChange", - "description": "When the reel changes", - "objName": "Data", - "objProp": "{ Reel }" + "type": "param", + "name": "y2", + "description": "Second y coordinate." + }, + { + "type": "return", + "value": "The squared distance between the two points." } ] }, { "type": "raw", - "value": "\nUsed to animate sprites by treating a sprite map as a set of animation frames.\nMust be applied to an entity that has a sprite-map component.\n\nTo define an animation, see the `reel` method. To play an animation, see the `animate` method.\n\nA reel is an object that contains the animation frames and current state for an animation. The reel object has the following properties:" - }, - { - "type": "param", - "name": "id: (String)", - "description": "the name of the reel" - }, - { - "type": "param", - "name": "frames: (Array)", - "description": "A list of frames in the format [xpos, ypos]" - }, - { - "type": "param", - "name": "currentFrame: (Number)", - "description": "The index of the current frame" - }, - { - "type": "param", - "name": "easing: (Crafty.easing object)", - "description": "The object that handles the internal progress of the animation." - }, - { - "type": "param", - "name": "duration: (Number)", - "description": "The duration in milliseconds." - }, - { - "type": "raw", - "value": "\nMany animation related events pass a reel object as data. As typical with events, this should be treated as read only data that might be later altered by the entity. If you wish to preserve the data, make a copy of it.\n" - }, - { - "type": "xref", - "xrefs": [ - "Crafty.sprite" - ] + "value": "Squared distance between two points." } ], - "name": "SpriteAnimation", - "categories": [ - "Animation" - ] + "name": "Crafty.math.squaredDistance", + "comp": "Crafty.math" }, { - "file": "src/sprite-animation.js", - "startLine": 56, - "endLine": 60, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 194, + "endLine": 204, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public Boolean Crafty.math.withinRange(Number value, Number min, Number max)", + "contents": [ + { + "type": "param", + "name": "value", + "description": "The specific value." + }, + { + "type": "param", + "name": "min", + "description": "Minimum value." + }, + { + "type": "param", + "name": "max", + "description": "Maximum value." + }, + { + "type": "return", + "value": "Returns true if value is within a specific range." + } + ] + }, { "type": "raw", - "value": "\nThe playback rate of the animation. This property defaults to 1." + "value": "Check if a value is within a specific range." } ], - "name": ".animationSpeed", - "comp": "SpriteAnimation" + "name": "Crafty.math.withinRange", + "comp": "Crafty.math" }, { - "file": "src/sprite-animation.js", - "startLine": 69, - "endLine": 117, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 211, + "endLine": 225, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Used to define reels, to change the active reel, and to fetch the id of the active reel.\n" + "value": "Vector2D uses the following form:\n\n" }, { "type": "method", - "signature": "public this .reel(String reelId, Duration duration, Number fromX, Number fromY, Number frameCount)", + "signature": "public {Vector2D} Vector2D();", + "contents": [] + }, + { + "type": "method", + "signature": "public {Vector2D} Vector2D(Vector2D);", + "contents": [] + }, + { + "type": "method", + "signature": "public {Vector2D} Vector2D(Number, Number);", "contents": [ - { - "type": "raw", - "value": "Defines a reel by starting and ending position on the sprite sheet." - }, - { - "type": "param", - "name": "reelId", - "description": "ID of the animation reel being created" - }, - { - "type": "param", - "name": "duration", - "description": "The length of the animation in milliseconds." - }, { "type": "param", - "name": "fromX", - "description": "Starting `x` position on the sprite map (x's unit is the horizontal size of the sprite in the sprite map)." - }, - { - "type": "param", - "name": "fromY", - "description": "`y` position on the sprite map (y's unit is the horizontal size of the sprite in the sprite map). Remains constant through the animation." + "name": "{Vector2D|Number=0} x", + "description": "" }, { "type": "param", - "name": "frameCount", - "description": "The number of sequential frames in the animation. If negative, the animation will play backwards." + "name": "{Number=0} y", + "description": "" } ] - }, + } + ], + "name": "Crafty.math.Vector2D", + "categories": [ + "2D" + ], + "class": "This is a general purpose 2D vector class", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 241, + "endLine": 251, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "" + "value": "Adds the passed vector to this vector\n" }, { "type": "method", - "signature": "public this .reel(String reelId, Duration duration, Array frames)", + "signature": "public {Vector2D} add(Vector2D);", "contents": [ - { - "type": "raw", - "value": "Defines a reel by an explicit list of frames" - }, - { - "type": "param", - "name": "reelId", - "description": "ID of the animation reel being created" - }, { "type": "param", - "name": "duration", - "description": "The length of the animation in milliseconds." + "name": "{vector2D} vecRH", + "description": "" }, { - "type": "param", - "name": "frames", - "description": "An array of arrays containing the `x` and `y` values of successive frames: [[x1,y1],[x2,y2],...] (the values are in the unit of the sprite map's width/height respectively)." + "type": "return", + "value": "{Vector2D} this after adding" } ] - }, + } + ], + "name": ".add", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 258, + "endLine": 269, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "" + "value": "Calculates the angle between the passed vector and this vector, using <0,0> as the point of reference.\nAngles returned have the range (−π, π].\n" }, { "type": "method", - "signature": "public this .reel(String reelId)", + "signature": "public {Number} angleBetween(Vector2D);", "contents": [ { - "type": "raw", - "value": "Switches to the specified reel. The sprite will be updated to that reel's current frame" + "type": "param", + "name": "{Vector2D} vecRH", + "description": "" }, { - "type": "param", - "name": "reelID", - "description": "the ID to switch to" + "type": "return", + "value": "{Number} the angle between the two vectors in radians" } ] - }, + } + ], + "name": ".angleBetween", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 274, + "endLine": 284, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "" + "value": "Calculates the angle to the passed vector from this vector, using this vector as the point of reference.\n" }, { "type": "method", - "signature": "public Reel .reel()", + "signature": "public {Number} angleTo(Vector2D);", "contents": [ + { + "type": "param", + "name": "{Vector2D} vecRH", + "description": "" + }, { "type": "return", - "value": "The id of the current reel" + "value": "{Number} the angle to the passed vector in radians" } ] - }, + } + ], + "name": ".angleTo", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 289, + "endLine": 298, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\n\nA method to handle animation reels. Only works for sprites built with the Crafty.sprite methods.\nSee the Tween component for animation of 2D properties.\n\nTo setup an animation reel, pass the name of the reel (used to identify the reel later), and either an\narray of absolute sprite positions or the start x on the sprite map, the y on the sprite map and then the end x on the sprite map.\n\n" + "value": "Creates and exact, numeric copy of this vector\n" }, { - "type": "example", + "type": "method", + "signature": "public {Vector2D} clone();", "contents": [ { - "type": "raw", - "value": "```\n// Define a sprite-map component\nCrafty.sprite(16, \"images/sprite.png\", {\n PlayerSprite: [0,0]\n});\n\n// Define an animation on the second row of the sprite map (fromY = 1)\n// from the left most sprite (fromX = 0) to the fourth sprite\n// on that row (frameCount = 4), with a duration of 1 second\nCrafty.e(\"2D, DOM, SpriteAnimation, PlayerSprite\").reel('PlayerRunning', 1000, 0, 1, 4);\n\n// This is the same animation definition, but using the alternative method\nCrafty.e(\"2D, DOM, SpriteAnimation, PlayerSprite\").reel('PlayerRunning', 1000, [[0, 1], [1, 1], [2, 1], [3, 1]]);\n```" + "type": "return", + "value": "{Vector2D} the new vector" } ] } ], - "name": ".reel", - "comp": "SpriteAnimation" + "name": ".clone", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite-animation.js", - "startLine": 181, - "endLine": 210, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 303, + "endLine": 313, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Calculates the distance from this vector to the passed vector.\n" + }, { "type": "method", - "signature": "public this .animate([String reelId] [, Number loopCount])", + "signature": "public {Number} distance(Vector2D);", "contents": [ { "type": "param", - "name": "reelId", - "description": "ID of the animation reel to play. Defaults to the current reel if none is specified." + "name": "{Vector2D} vecRH", + "description": "" }, { - "type": "param", - "name": "loopCount", - "description": "Number of times to repeat the animation. Use -1 to repeat indefinitely. Defaults to 1." + "type": "return", + "value": "{Number} the distance between the two vectors" } ] - }, + } + ], + "name": ".distance", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 318, + "endLine": 330, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nPlay one of the reels previously defined through `.reel(...)`. Simply pass the name of the reel. If you wish the\nanimation to play multiple times in succession, pass in the amount of times as an additional parameter.\nTo have the animation repeat indefinitely, pass in `-1`.\n\nIf another animation is currently playing, it will be paused.\n\nThis will always play an animation from the beginning. If you wish to resume from the current state of a reel, use `resumeAnimation()`.\n\nOnce an animation ends, it will remain at its last frame.\n\n" + "value": "Calculates the squared distance from this vector to the passed vector.\nThis function avoids calculating the square root, thus being slightly faster than .distance( ).\n" }, { - "type": "example", + "type": "method", + "signature": "public {Number} distanceSq(Vector2D);", "contents": [ { - "type": "raw", - "value": "```\n// Define a sprite-map component\nCrafty.sprite(16, \"images/sprite.png\", {\n PlayerSprite: [0,0]\n});\n\n// Play the animation across 20 frames (so each sprite in the 4 sprite animation should be seen for 5 frames) and repeat indefinitely\nCrafty.e(\"2D, DOM, SpriteAnimation, PlayerSprite\")\n .reel('PlayerRunning', 20, 0, 0, 3) // setup animation\n .animate('PlayerRunning', -1); // start animation\n```" + "type": "param", + "name": "{Vector2D} vecRH", + "description": "" + }, + { + "type": "return", + "value": "{Number} the squared distance between the two vectors" } ] + }, + { + "type": "xref", + "xrefs": [ + ".distance" + ] } ], - "name": ".animate", - "comp": "SpriteAnimation" + "name": ".distanceSq", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite-animation.js", - "startLine": 253, - "endLine": 259, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 335, + "endLine": 345, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this .resumeAnimation()", - "contents": [] + "type": "raw", + "value": "Divides this vector by the passed vector.\n" }, { - "type": "raw", - "value": "\nThis will resume animation of the current reel from its current state.\nIf a reel is already playing, or there is no current reel, there will be no effect." + "type": "method", + "signature": "public {Vector2D} divide(Vector2D);", + "contents": [ + { + "type": "param", + "name": "{Vector2D} vecRH", + "description": "" + }, + { + "type": "return", + "value": "{Vector2D} this vector after dividing" + } + ] } ], - "name": ".resumeAnimation", - "comp": "SpriteAnimation" + "name": ".divide", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite-animation.js", - "startLine": 271, - "endLine": 276, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 352, + "endLine": 362, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this .pauseAnimation(void)", - "contents": [] + "type": "raw", + "value": "Calculates the dot product of this and the passed vectors\n" }, { - "type": "raw", - "value": "\nPauses the currently playing animation, or does nothing if no animation is playing." + "type": "method", + "signature": "public {Number} dotProduct(Vector2D);", + "contents": [ + { + "type": "param", + "name": "{Vector2D} vecRH", + "description": "" + }, + { + "type": "return", + "value": "{Number} the resultant dot product" + } + ] } ], - "name": ".pauseAnimation", - "comp": "SpriteAnimation" + "name": ".dotProduct", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite-animation.js", - "startLine": 287, - "endLine": 294, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 367, + "endLine": 377, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this .resetAnimation()", - "contents": [] + "type": "raw", + "value": "Calculates the z component of the cross product of the two vectors augmented to 3D.\n" }, { - "type": "raw", - "value": "\nResets the current animation to its initial state. Resets the number of loops to the last specified value, which defaults to 1.\n\nNeither pauses nor resumes the current animation." + "type": "method", + "signature": "public {Number} crossProduct(Vector2D);", + "contents": [ + { + "type": "param", + "name": "{Vector2D} vecRH", + "description": "" + }, + { + "type": "return", + "value": "{Number} the resultant cross product" + } + ] } ], - "name": ".resetAnimation", - "comp": "SpriteAnimation" + "name": ".crossProduct", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite-animation.js", - "startLine": 306, - "endLine": 316, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 382, + "endLine": 392, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Determines if this vector is numerically equivalent to the passed vector.\n" + }, { "type": "method", - "signature": "public this .loops(Number loopCount)", + "signature": "public {Boolean} equals(Vector2D);", "contents": [ { "type": "param", - "name": "loopCount", - "description": "The number of times to play the animation" + "name": "{Vector2D} vecRH", + "description": "" + }, + { + "type": "return", + "value": "{Boolean} true if the vectors are equivalent" } ] - }, + } + ], + "name": ".equals", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 398, + "endLine": 409, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nSets the number of times the animation will loop for.\nIf called while an animation is in progress, the current state will be considered the first loop.\n" + "value": "Calculates a new vector that is perpendicular to this vector.\nThe perpendicular vector has the same magnitude as this vector and is obtained by a counter-clockwise rotation of 90° of this vector.\n" }, { "type": "method", - "signature": "public Number .loops()", + "signature": "public {Vector2D} perpendicular([Vector2D]);", "contents": [ + { + "type": "param", + "name": "{Vector2D} [result]", + "description": "An optional parameter to save the result in" + }, { "type": "return", - "value": "The number of loops left. Returns 0 if no reel is active." + "value": "{Vector2D} the perpendicular vector" } ] } ], - "name": ".loops", - "comp": "SpriteAnimation" + "name": ".perpendicular", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite-animation.js", - "startLine": 336, - "endLine": 353, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 415, + "endLine": 426, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "" + "value": "Calculates a new right-handed unit vector that is perpendicular to the line created by this and the passed vector.\n" }, { "type": "method", - "signature": "public this .reelPosition(Integer position)", + "signature": "public {Vector2D} getNormal(Vector2D[, Vector2D]);", "contents": [ { - "type": "raw", - "value": "Sets the position of the current reel by frame number." + "type": "param", + "name": "{Vector2D} vecRH", + "description": "" }, { "type": "param", - "name": "position", - "description": "the frame to jump to. This is zero-indexed. A negative values counts back from the last frame." + "name": "{Vector2D} [result]", + "description": "An optional parameter to save the result in" + }, + { + "type": "return", + "value": "{Vector2D} the new normal vector" } ] - }, + } + ], + "name": ".getNormal", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 432, + "endLine": 441, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "" + "value": "Determines if this vector is equal to <0,0>\n" }, { "type": "method", - "signature": "public this .reelPosition(Number position)", + "signature": "public {Boolean} isZero();", "contents": [ { - "type": "raw", - "value": "Sets the position of the current reel by percent progress." - }, - { - "type": "param", - "name": "position", - "description": "a non-integer number between 0 and 1" + "type": "return", + "value": "{Boolean} true if this vector is equal to <0,0>" } ] - }, + } + ], + "name": ".isZero", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 446, + "endLine": 456, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "" + "value": "Calculates the magnitude of this vector.\nNote: Function objects in JavaScript already have a 'length' member, hence the use of magnitude instead.\n" }, { "type": "method", - "signature": "public this .reelPosition(String position)", - "contents": [] - }, + "signature": "public {Number} magnitude();", + "contents": [ + { + "type": "return", + "value": "{Number} the magnitude of this vector" + } + ] + } + ], + "name": ".magnitude", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 461, + "endLine": 472, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "Jumps to the specified position. The only currently accepted value is \"end\", which will jump to the end of the reel.\n" + "value": "Calculates the square of the magnitude of this vector.\nThis function avoids calculating the square root, thus being slightly faster than .magnitude( ).\n" }, { "type": "method", - "signature": "public Number .reelPosition()", + "signature": "public {Number} magnitudeSq();", "contents": [ { "type": "return", - "value": "The current frame number" + "value": "{Number} the square of the magnitude of this vector" } ] }, { - "type": "raw", - "value": "" + "type": "xref", + "xrefs": [ + ".magnitude" + ] } ], - "name": ".reelPosition", - "comp": "SpriteAnimation" + "name": ".magnitudeSq", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite-animation.js", - "startLine": 435, - "endLine": 449, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 477, + "endLine": 487, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Multiplies this vector by the passed vector\n" + }, { "type": "method", - "signature": "public Boolean .isPlaying([String reelId])", + "signature": "public {Vector2D} multiply(Vector2D);", "contents": [ { "type": "param", - "name": "reelId", - "description": "The reelId of the reel we wish to examine" + "name": "{Vector2D} vecRH", + "description": "" }, { "type": "return", - "value": "The current animation state" + "value": "{Vector2D} this vector after multiplying" } ] - }, + } + ], + "name": ".multiply", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 494, + "endLine": 503, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nDetermines if the specified animation is currently playing. If no reelId is specified,\nchecks if any animation is playing.\n" + "value": "Negates this vector (ie. <-x,-y>)\n" }, { - "type": "example", + "type": "method", + "signature": "public {Vector2D} negate();", "contents": [ { - "type": "raw", - "value": "```\nmyEntity.isPlaying() // is any animation playing\nmyEntity.isPlaying('PlayerRunning') // is the PlayerRunning animation playing\n```" + "type": "return", + "value": "{Vector2D} this vector after negation" } ] } ], - "name": ".isPlaying", - "comp": "SpriteAnimation" + "name": ".negate", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite-animation.js", - "startLine": 458, - "endLine": 467, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 510, + "endLine": 520, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Normalizes this vector (scales the vector so that its new magnitude is 1)\nFor vectors where magnitude is 0, <1,0> is returned.\n" + }, { "type": "method", - "signature": "public Reel .getReel()", + "signature": "public {Vector2D} normalize();", "contents": [ { "type": "return", - "value": "The current reel, or null if there is no active reel" + "value": "{Vector2D} this vector after normalization" } ] - }, + } + ], + "name": ".normalize", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 536, + "endLine": 548, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "" + "value": "Scales this vector by the passed amount(s)\nIf scalarY is omitted, scalarX is used for both axes\n" }, { "type": "method", - "signature": "public Reel .getReel(reelId)", + "signature": "public {Vector2D} scale(Number[, Number]);", "contents": [ { "type": "param", - "name": "reelId", - "description": "The id of the reel to fetch." + "name": "{Number} scalarX", + "description": "" + }, + { + "type": "param", + "name": "{Number} [scalarY]", + "description": "" }, { "type": "return", - "value": "The specified reel, or `undefined` if no such reel exists." + "value": "{Vector2D} this after scaling" } ] - }, - { - "type": "raw", - "value": "" } ], - "name": ".getReel", - "comp": "SpriteAnimation" + "name": ".scale", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite.js", - "startLine": 6, - "endLine": 55, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 559, + "endLine": 569, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Scales this vector such that its new magnitude is equal to the passed value.\n" + }, { "type": "method", - "signature": "public this Crafty.sprite([Number tile, [Number tileh]], String url, Object map[, Number paddingX[, Number paddingY[, Boolean paddingAroundBorder]]])", + "signature": "public {Vector2D} scaleToMagnitude(Number);", "contents": [ { "type": "param", - "name": "tile", - "description": "Tile size of the sprite map, defaults to 1" - }, - { - "type": "param", - "name": "tileh", - "description": "Height of the tile; if provided, tile is interpreted as the width" - }, - { - "type": "param", - "name": "url", - "description": "URL of the sprite image" + "name": "{Number} mag", + "description": "" }, { - "type": "param", - "name": "map", - "description": "Object where the key is what becomes a new component and the value points to a position on the sprite map" - }, + "type": "return", + "value": "{Vector2D} this vector after scaling" + } + ] + } + ], + "name": ".scaleToMagnitude", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 577, + "endLine": 589, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Sets the values of this vector using a passed vector or pair of numbers.\n" + }, + { + "type": "method", + "signature": "public {Vector2D} setValues(Vector2D);", + "contents": [] + }, + { + "type": "method", + "signature": "public {Vector2D} setValues(Number, Number);", + "contents": [ { "type": "param", - "name": "paddingX", - "description": "Horizontal space in between tiles. Defaults to 0." + "name": "{Number|Vector2D} x", + "description": "" }, { "type": "param", - "name": "paddingY", - "description": "Vertical space in between tiles. Defaults to paddingX." + "name": "{Number} y", + "description": "" }, { - "type": "param", - "name": "paddingAroundBorder", - "description": "If padding should be applied around the border of the sprite sheet. If enabled the first tile starts at (paddingX,paddingY) instead of (0,0). Defaults to false." + "type": "return", + "value": "{Vector2D} this vector after setting of values" } ] - }, + } + ], + "name": ".setValues", + "comp": "Crafty.math.Vector2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 602, + "endLine": 612, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "Generates components based on positions in a sprite image to be applied to entities.\n\nAccepts a tile size, URL and map for the name of the sprite and its position.\n\nThe position must be an array containing the position of the sprite where index `0`\nis the `x` position, `1` is the `y` position and optionally `2` is the width and `3`\nis the height. If the sprite map has padding, pass the values for the `x` padding\nor `y` padding. If they are the same, just add one value.\n\nIf the sprite image has no consistent tile size, `1` or no argument need be\npassed for tile size.\n\nEntities that add the generated components are also given the `2D` component, and\na component called `Sprite`.\n" + "value": "Subtracts the passed vector from this vector.\n" }, { - "type": "example", + "type": "method", + "signature": "public {Vector2D} subtract(Vector2D);", "contents": [ { - "type": "raw", - "value": "```\nCrafty.sprite(\"imgs/spritemap6.png\", {flower:[0,0,20,30]});\nvar flower_entity = Crafty.e(\"2D, DOM, flower\");\n```\nThe first line creates a component called `flower` associated with the sub-image of\nspritemap6.png with top-left corner (0,0), width 20 pixels, and height 30 pixels.\nThe second line creates an entity with that image. (Note: The `2D` is not really\nnecessary here, because adding the `flower` component automatically also adds the\n`2D` component.)\n```\nCrafty.sprite(50, \"imgs/spritemap6.png\", {flower:[0,0], grass:[0,1,3,1]});\n```\nIn this case, the `flower` component is pixels 0 <= x < 50, 0 <= y < 50, and the\n`grass` component is pixels 0 <= x < 150, 50 <= y < 100. (The `3` means grass has a\nwidth of 3 tiles, i.e. 150 pixels.)\n```\nCrafty.sprite(50, 100, \"imgs/spritemap6.png\", {flower:[0,0], grass:[0,1]}, 10);\n```\nIn this case, each tile is 50x100, and there is a spacing of 10 pixels between\nconsecutive tiles. So `flower` is pixels 0 <= x < 50, 0 <= y < 100, and `grass` is\npixels 0 <= x < 50, 110 <= y < 210.\n" + "type": "param", + "name": "{Vector2D} vecRH", + "description": "" + }, + { + "type": "return", + "value": "{vector2D} this vector after subtracting" } ] - }, - { - "type": "xref", - "xrefs": [ - "Sprite" - ] } ], - "name": "Crafty.sprite", - "categories": [ - "Graphics" - ] + "name": ".subtract", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite.js", - "startLine": 143, - "endLine": 147, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 619, + "endLine": 628, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ + "type": "raw", + "value": "Returns a string representation of this vector.\n" + }, + { + "type": "method", + "signature": "public {String} toString();", + "contents": [ { - "type": "trigger", - "event": "Invalidate", - "description": "when the sprites change", - "objName": "Data", - "objProp": null + "type": "return", + "value": "{String}" } ] - }, - { - "type": "raw", - "value": "Component for using tiles in a sprite map." } ], - "name": "Sprite", - "categories": [ - "Graphics" - ] + "name": ".toString", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite.js", - "startLine": 212, - "endLine": 229, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 633, + "endLine": 645, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Translates (moves) this vector by the passed amounts.\nIf dy is omitted, dx is used for both axes.\n" + }, { "type": "method", - "signature": "public this .sprite(Number x, Number y[, Number w, Number h])", + "signature": "public {Vector2D} translate(Number[, Number]);", "contents": [ { "type": "param", - "name": "x", - "description": "X cell position" - }, - { - "type": "param", - "name": "y", - "description": "Y cell position" + "name": "{Number} dx", + "description": "" }, { "type": "param", - "name": "w", - "description": "Width in cells. Optional." + "name": "{Number} [dy]", + "description": "" }, { - "type": "param", - "name": "h", - "description": "Height in cells. Optional." - } - ] - }, - { - "type": "raw", - "value": "\nUses a new location on the sprite map as its sprite. If w or h are ommitted, the width and height are not changed.\n\nValues should be in tiles or cells (not pixels).\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Sprite\")\n .sprite(0, 0, 2, 2);\n```" + "type": "return", + "value": "{Vector2D} this vector after translating" } ] } ], - "name": ".sprite", - "comp": "Sprite" + "name": ".translate", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/sprite.js", - "startLine": 232, - "endLine": 236, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 656, + "endLine": 671, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nThe coordinate of the slide within the sprite in the format of [x, y, w, h]." - } - ], - "name": ".__coord", - "comp": "Sprite" - }, - { - "file": "src/sprite.js", - "startLine": 252, - "endLine": 269, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "value": "Calculates the triple product of three vectors.\ntriple vector product = b(a•c) - a(b•c)\n" + }, { "type": "method", - "signature": "public this .crop(Number x, Number y, Number w, Number h)", + "signature": "public {Vector2D} tripleProduct(Vector2D, Vector2D, Vector2D, [Vector2D]);", "contents": [ { "type": "param", - "name": "x", - "description": "Offset x position" + "name": "{Vector2D} a", + "description": "" }, { "type": "param", - "name": "y", - "description": "Offset y position" + "name": "{Vector2D} b", + "description": "" }, { "type": "param", - "name": "w", - "description": "New width" + "name": "{Vector2D} c", + "description": "" }, { "type": "param", - "name": "h", - "description": "New height" - } - ] - }, - { - "type": "raw", - "value": "\nIf the entity needs to be smaller than the tile size, use this method to crop it.\n\nThe values should be in pixels rather than tiles.\n" - }, - { - "type": "example", - "contents": [ + "name": "{Vector2D} [result]", + "description": "An optional parameter to save the result in" + }, { - "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Sprite\")\n .crop(40, 40, 22, 23);\n```" + "type": "return", + "value": "{Vector2D} the triple product as a new vector" } ] } ], - "name": ".crop", - "comp": "Sprite" + "name": ".tripleProduct", + "comp": "Crafty.math.Vector2D", + "public": true }, { - "file": "src/storage.js", - "startLine": 4, - "endLine": 7, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 683, + "endLine": 705, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "Very simple way to get and set values, which will persist when the browser is closed also. Storage wraps around HTML5 Web Storage, which is well-supported across browsers and platforms, but limited to 5MB total storage per domain." - } - ], - "name": "Storage", - "categories": [ - "Utilities" - ] - }, - { - "file": "src/storage.js", - "startLine": 9, - "endLine": 47, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "value": "Matrix2D uses the following form, as per the whatwg.org specifications for canvas.transform():\n[a, c, e]\n[b, d, f]\n[0, 0, 1]\n" + }, { "type": "method", - "signature": ".storage(String key)", - "contents": [ - { - "type": "param", - "name": "key", - "description": "a key you would like to get from the storage. It will return null if the key does not exists." - } - ] + "signature": "public {Matrix2D} new Matrix2D();", + "contents": [] + }, + { + "type": "method", + "signature": "public {Matrix2D} new Matrix2D(Matrix2D);", + "contents": [] }, { "type": "method", - "signature": ".storage(String key, String value)", + "signature": "public {Matrix2D} new Matrix2D(Number, Number, Number, Number, Number, Number);", "contents": [ { "type": "param", - "name": "key", - "description": "the key you would like to save the data under." + "name": "{Matrix2D|Number=1} a", + "description": "" }, { "type": "param", - "name": "value", - "description": "the value you would like to save." - } - ] - }, - { - "type": "method", - "signature": ".storage(String key, [Object value, Array value, Boolean value])", - "contents": [ + "name": "{Number=0} b", + "description": "" + }, { "type": "param", - "name": "key", - "description": "the key you would like to save the data under." + "name": "{Number=0} c", + "description": "" }, { "type": "param", - "name": "value", - "description": "the value you would like to save, can be an Object or an Array." + "name": "{Number=1} d", + "description": "" + }, + { + "type": "param", + "name": "{Number=0} e", + "description": "" + }, + { + "type": "param", + "name": "{Number=0} f", + "description": "" } ] - }, + } + ], + "name": "Crafty.math.Matrix2D", + "categories": [ + "2D" + ], + "class": "This is a 2D Matrix2D class. It is 3x3 to allow for affine transformations in 2D space. The third row is always assumed to be [0, 0, 1].", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 732, + "endLine": 742, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nStorage function is very simple and can be used to either get or set values.\nYou can store both booleans, strings, objects and arrays.\n\nPlease note: You should not store data, while the game is playing, as it can cause the game to slow down. You should load data when you start the game, or when the user for an example click a \"Save gameprocess\" button.\n" + "value": "Applies the matrix transformations to the passed object\n" }, { - "type": "example", + "type": "method", + "signature": "public {Vector2D} apply(Vector2D);", "contents": [ { - "type": "raw", - "value": "Get an already stored value\n```\nvar playername = Crafty.storage('playername');\n```\n" - } - ] - }, - { - "type": "example", - "contents": [ + "type": "param", + "name": "{Vector2D} vecRH", + "description": "vector to be transformed" + }, { - "type": "raw", - "value": "Save a value\n```\nCrafty.storage('playername', 'Hero');\n```\n" + "type": "return", + "value": "{Vector2D} the passed vector object after transforming" } ] + } + ], + "name": ".apply", + "comp": "Crafty.math.Matrix2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 757, + "endLine": 766, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ + { + "type": "raw", + "value": "Creates an exact, numeric copy of the current matrix\n" }, { - "type": "example", + "type": "method", + "signature": "public {Matrix2D} clone();", "contents": [ { - "type": "raw", - "value": "Test to see if a value is already there.\n```\nvar heroname = Crafty.storage('name');\nif(!heroname){\n // Maybe ask the player what their name is here\n heroname = 'Guest';\n}\n// Do something with heroname\n```" + "type": "return", + "value": "{Matrix2D}" } ] } ], - "name": ".storage", - "comp": "Storage" + "name": ".clone", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/storage.js", - "startLine": 75, - "endLine": 90, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 771, + "endLine": 782, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Multiplies this matrix with another, overriding the values of this matrix.\nThe passed matrix is assumed to be on the right-hand side.\n" + }, { "type": "method", - "signature": ".storage.remove(String key)", + "signature": "public {Matrix2D} combine(Matrix2D);", "contents": [ { "type": "param", - "name": "key", - "description": "a key where you will like to delete the value of." + "name": "{Matrix2D} mtrxRH", + "description": "" + }, + { + "type": "return", + "value": "{Matrix2D} this matrix after combination" } ] - }, + } + ], + "name": ".combine", + "comp": "Crafty.math.Matrix2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 796, + "endLine": 806, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nGenerally you do not need to remove values from localStorage, but if you do\nstore large amount of text, or want to unset something you can do that with\nthis function.\n" + "value": "Checks for the numeric equality of this matrix versus another.\n" }, { - "type": "example", + "type": "method", + "signature": "public {Boolean} equals(Matrix2D);", "contents": [ { - "type": "raw", - "value": "Get an already stored value\n```\nCrafty.storage.remove('playername');\n```\n" + "type": "param", + "name": "{Matrix2D} mtrxRH", + "description": "" + }, + { + "type": "return", + "value": "{Boolean} true if the two matrices are numerically equal" } ] } ], - "name": ".storage.remove", - "comp": "Storage" + "name": ".equals", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/text.js", - "startLine": 4, - "endLine": 25, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 813, + "endLine": 822, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ + "type": "raw", + "value": "Calculates the determinant of this matrix\n" + }, + { + "type": "method", + "signature": "public {Number} determinant();", + "contents": [ { - "type": "trigger", - "event": "Invalidate", - "description": "when the text is changed", - "objName": "Data", - "objProp": null + "type": "return", + "value": "{Number} det(this matrix)" } ] - }, - { - "type": "raw", - "value": "Component to make a text entity.\n\nBy default, text will have the style \"10px sans-serif\".\n\nNote 1: An entity with the text component is just text! If you want to write text\ninside an image, you need one entity for the text and another entity for the image.\nMore tips for writing text inside an image: (1) Use the z-index (from 2D component)\nto ensure that the text is on top of the image, not the other way around; (2)\nuse .attach() (from 2D component) to glue the text to the image so they move and\nrotate together.\n\nNote 2: For DOM (but not canvas) text entities, various font settings (like\ntext-decoration and text-align) can be set using `.css()` (see DOM component). But\nyou cannot use `.css()` to set the properties which are controlled by `.textFont()`\nor `.textColor()` -- the settings will be ignored.\n\nNote 3: If you use canvas text with glyphs that are taller than standard letters, portions of the glyphs might be cut off." } ], - "name": "Text", - "categories": [ - "Graphics" - ], - "requires": "Canvas or DOM" + "name": ".determinant", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/text.js", - "startLine": 98, - "endLine": 120, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 827, + "endLine": 837, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "method", - "signature": "public this .text(String text)", - "contents": [] + "type": "raw", + "value": "Inverts this matrix if possible\n" }, { "type": "method", - "signature": "public this .text(Function textgenerator)", + "signature": "public {Matrix2D} invert();", "contents": [ { - "type": "param", - "name": "text", - "description": "String of text that will be inserted into the DOM or Canvas element." + "type": "return", + "value": "{Matrix2D} this inverted matrix or the original matrix on failure" } ] }, { - "type": "raw", - "value": "\nThis method will update the text inside the entity.\n\nIf you need to reference attributes on the entity itself you can pass a function instead of a string.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Text\").attr({ x: 100, y: 100 }).text(\"Look at me!!\");\n\nCrafty.e(\"2D, DOM, Text\").attr({ x: 100, y: 100 })\n .text(function () { return \"My position is \" + this._x });\n\nCrafty.e(\"2D, Canvas, Text\").attr({ x: 100, y: 100 }).text(\"Look at me!!\");\n\nCrafty.e(\"2D, Canvas, Text\").attr({ x: 100, y: 100 })\n .text(function () { return \"My position is \" + this._x });\n```" - } + "type": "xref", + "xrefs": [ + ".isInvertible" ] } ], - "name": ".text", - "comp": "Text" + "name": ".invert", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/text.js", - "startLine": 152, - "endLine": 173, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 862, + "endLine": 871, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Returns true if this matrix is the identity matrix\n" + }, { "type": "method", - "signature": "public this .textColor(String color)", + "signature": "public {Boolean} isIdentity();", "contents": [ { - "type": "param", - "name": "color", - "description": "The color in name, hex, rgb or rgba" + "type": "return", + "value": "{Boolean}" } ] - }, + } + ], + "name": ".isIdentity", + "comp": "Crafty.math.Matrix2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 876, + "endLine": 886, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "\nChange the color of the text. You can use HEX, rgb and rgba colors.\n\nIf you want the text to be transparent, you should use rgba where you can define alphaChannel.\n" + "value": "Determines is this matrix is invertible.\n" }, { - "type": "example", + "type": "method", + "signature": "public {Boolean} isInvertible();", "contents": [ { - "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Text\").attr({ x: 100, y: 100 }).text(\"Look at me!!\")\n .textColor('#FF0000');\n\nCrafty.e(\"2D, Canvas, Text\").attr({ x: 100, y: 100 }).text('Look at me!!')\n .textColor('rgba(0, 255, 0, 0.5)');\n\nCrafty.e(\"2D, Canvas, Text\").attr({ x: 100, y: 100 }).text('Look at me!!')\n .textColor('white');\n```" + "type": "return", + "value": "{Boolean} true if this matrix is invertible" } ] }, { "type": "xref", "xrefs": [ - "Crafty.assignColor" + ".invert" ] } ], - "name": ".textColor", - "comp": "Text" + "name": ".isInvertible", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/text.js", - "startLine": 182, - "endLine": 204, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 891, + "endLine": 901, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "Invalidate", - "objName": "Data", - "objProp": null - } - ] + "type": "raw", + "value": "Applies a counter-clockwise pre-rotation to this matrix\n" }, { "type": "method", - "signature": "public this .textFont(String key, * value)", + "signature": "public {Matrix2D} preRotate(Number);", "contents": [ { "type": "param", - "name": "key", - "description": "Property of the entity to modify" + "name": "{number} rads", + "description": "angle to rotate in radians" }, { - "type": "param", - "name": "value", - "description": "Value to set the property to" + "type": "return", + "value": "{Matrix2D} this matrix after pre-rotation" } ] - }, + } + ], + "name": ".preRotate", + "comp": "Crafty.math.Matrix2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 916, + "endLine": 927, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "" + "value": "Applies a pre-scaling to this matrix\n" }, { "type": "method", - "signature": "public this .textFont(Object map)", + "signature": "public {Matrix2D} preScale(Number[, Number]);", "contents": [ { "type": "param", - "name": "map", - "description": "Object where the key is the property to modify and the value as the property value" - } - ] - }, - { - "type": "raw", - "value": "\nUse this method to set font property of the text entity. Possible values are: type, weight, size, family, lineHeight, and variant.\n\nWhen rendered by the canvas, lineHeight and variant will be ignored.\n" - }, - { - "type": "example", - "contents": [ + "name": "{Number} scalarX", + "description": "" + }, { - "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Text\").textFont({ type: 'italic', family: 'Arial' });\nCrafty.e(\"2D, Canvas, Text\").textFont({ size: '20px', weight: 'bold' });\n\nCrafty.e(\"2D, Canvas, Text\").textFont(\"type\", \"italic\");\nCrafty.e(\"2D, Canvas, Text\").textFont(\"type\"); // italic\n```" + "type": "param", + "name": "{Number} [scalarY] scalarX is used if scalarY is undefined", + "description": "" + }, + { + "type": "return", + "value": "{Matrix2D} this after pre-scaling" } ] } ], - "name": ".textFont", - "comp": "Text" + "name": ".preScale", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/text.js", - "startLine": 232, - "endLine": 247, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 940, + "endLine": 952, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ - { - "type": "trigger", - "event": "Invalidate", - "objName": "Data", - "objProp": null - } - ] + "type": "raw", + "value": "Applies a pre-translation to this matrix\n" }, { "type": "method", - "signature": "public this .unselectable()", + "signature": "public {Matrix2D} preTranslate(Vector2D);", "contents": [] }, - { - "type": "raw", - "value": "\nThis method sets the text so that it cannot be selected (highlighted) by dragging.\n(Canvas text can never be highlighted, so this only matters for DOM text.)\nWorks by changing the css property \"user-select\" and its variants.\n\nLikewise, this sets the mouseover cursor to be \"default\" (arrow), not \"text\" (I-beam)\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.e(\"2D, DOM, Text\").text('This text cannot be highlighted!').unselectable();\n```" - } - ] - } - ], - "name": ".unselectable", - "comp": "Text" - }, - { - "file": "src/time.js", - "startLine": 4, - "endLine": 6, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [], - "name": "Delay", - "categories": [ - "Utilities" - ] - }, - { - "file": "src/time.js", - "startLine": 37, - "endLine": 77, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ { "type": "method", - "signature": "public this.delay(Function callback, Number delay[, Number repeat[, Function callbackOff]])", + "signature": "public {Matrix2D} preTranslate(Number, Number);", "contents": [ { "type": "param", - "name": "callback", - "description": "Method to execute after given amount of milliseconds. If reference of a" - }, - { - "type": "raw", - "value": "method is passed, there's possibility to cancel the delay." - }, - { - "type": "param", - "name": "delay", - "description": "Amount of milliseconds to execute the method." - }, - { - "type": "param", - "name": "repeat", - "description": "(optional) How often to repeat the delayed function. A value of 0 triggers the delayed" + "name": "{Number|Vector2D} dx", + "description": "" }, { - "type": "raw", - "value": "function exactly once. A value n > 0 triggers the delayed function exactly n+1 times. A\nvalue of -1 triggers the delayed function indefinitely. Defaults to one execution." + "type": "param", + "name": "{Number} dy", + "description": "" }, { - "type": "param", - "name": "callbackOff", - "description": "(optional) Method to execute after delay ends(after all iterations are executed)." + "type": "return", + "value": "{Matrix2D} this matrix after pre-translation" } ] - }, + } + ], + "name": ".preTranslate", + "comp": "Crafty.math.Matrix2D", + "public": true + }, + { + "file": "src/spatial/math.js", + "startLine": 965, + "endLine": 975, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "raw", - "value": "If repeat value equals -1, callbackOff will never be triggered.\n\nThe delay method will execute a function after a given amount of time in milliseconds.\n\nIt is not a wrapper for `setTimeout`.\n\nIf Crafty is paused, the delay is interrupted with the pause and then resume when unpaused\n\nIf the entity is destroyed, the delay is also destroyed and will not have effect.\n" + "value": "Applies a counter-clockwise post-rotation to this matrix\n" }, { - "type": "example", + "type": "method", + "signature": "public {Matrix2D} rotate(Number);", "contents": [ { - "type": "raw", - "value": "\nThe simplest delay\n```\nconsole.log(\"start\");\nCrafty.e(\"Delay\").delay(function() {\n console.log(\"100ms later\");\n}, 100, 0);\n```\n\nDelay with callbackOff to be executed after all delay iterations\n```\nconsole.log(\"start\");\nCrafty.e(\"Delay\").delay(function() {\n console.log(\"100ms later\");\n}, 100, 3, function() {\n console.log(\"delay finished\");\n});\n```\n" + "type": "param", + "name": "{Number} rads", + "description": "angle to rotate in radians" + }, + { + "type": "return", + "value": "{Matrix2D} this matrix after rotation" } ] } ], - "name": ".delay", - "comp": "Delay" + "name": ".rotate", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/time.js", - "startLine": 89, - "endLine": 108, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 993, + "endLine": 1004, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ - { - "type": "method", - "signature": "public this.cancelDelay(Function callback)", - "contents": [ - { - "type": "param", - "name": "callback", - "description": "Method reference passed to .delay" - } - ] - }, { "type": "raw", - "value": "\nThe cancelDelay method will cancel a delay set previously.\n" + "value": "Applies a post-scaling to this matrix\n" }, { - "type": "example", + "type": "method", + "signature": "public {Matrix2D} scale(Number[, Number]);", "contents": [ { - "type": "raw", - "value": "```\nvar doSomething = function(){\n console.log(\"doing something\");\n};\n\n// execute doSomething each 100 miliseconds indefinetely\nvar ent = Crafty.e(\"Delay\").delay(doSomething, 100, -1);\n\n// and some time later, cancel further execution of doSomething\nent.cancelDelay(doSomething);\n```" + "type": "param", + "name": "{Number} scalarX", + "description": "" + }, + { + "type": "param", + "name": "{Number} [scalarY] scalarX is used if scalarY is undefined", + "description": "" + }, + { + "type": "return", + "value": "{Matrix2D} this after post-scaling" } ] } ], - "name": ".cancelDelay", - "comp": "Delay" + "name": ".scale", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/viewport.js", - "startLine": 5, - "endLine": 22, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 1019, + "endLine": 1035, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ + "type": "raw", + "value": "Sets the values of this matrix\n" + }, + { + "type": "method", + "signature": "public {Matrix2D} setValues(Matrix2D);", + "contents": [] + }, + { + "type": "method", + "signature": "public {Matrix2D} setValues(Number, Number, Number, Number, Number, Number);", + "contents": [ { - "type": "trigger", - "event": "ViewportScroll", - "description": "when the viewport's x or y coordinates change", - "objName": "Data", - "objProp": null + "type": "param", + "name": "{Matrix2D|Number} a", + "description": "" }, { - "type": "trigger", - "event": "ViewportScale", - "description": "when the viewport's scale changes", - "objName": "Data", - "objProp": null + "type": "param", + "name": "{Number} b", + "description": "" }, { - "type": "trigger", - "event": "ViewportResize", - "description": "when the viewport's dimension's change", - "objName": "Data", - "objProp": null + "type": "param", + "name": "{Number} c", + "description": "" }, { - "type": "trigger", - "event": "InvalidateViewport", - "description": "when the viewport changes", - "objName": "Data", - "objProp": null + "type": "param", + "name": "{Number} d", + "description": "" }, { - "type": "trigger", - "event": "StopCamera", - "description": "when any camera animations should stop, such as at the start of a new animation.", - "objName": "Data", - "objProp": null + "type": "param", + "name": "{Number} e", + "description": "" }, { - "type": "trigger", - "event": "CameraAnimationDone", - "description": "when a camera animation comes reaches completion", - "objName": "Data", - "objProp": null + "type": "param", + "name": "{Number} f", + "description": "" + }, + { + "type": "return", + "value": "{Matrix2D} this matrix containing the new values" } ] - }, - { - "type": "raw", - "value": "\nViewport is essentially a 2D camera looking at the stage. Can be moved or zoomed, which\nin turn will react just like a camera moving in that direction.\n\nTip: At any given moment, the stuff that you can see is...\n\n`x` between `(-Crafty.viewport._x)` and `(-Crafty.viewport._x + (Crafty.viewport._width / Crafty.viewport._scale))`\n\n`y` between `(-Crafty.viewport._y)` and `(-Crafty.viewport._y + (Crafty.viewport._height / Crafty.viewport._scale))`" - } - ], - "name": "Crafty.viewport", - "categories": [ - "Stage" - ] - }, - { - "file": "src/viewport.js", - "startLine": 25, - "endLine": 32, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nDecides if the viewport functions should clamp to game entities.\nWhen set to `true` functions such as Crafty.viewport.mouselook() will not allow you to move the\nviewport over areas of the game that has no entities.\nFor development it can be useful to set this to false." - } - ], - "name": "Crafty.viewport.clampToEntities", - "comp": "Crafty.viewport" - }, - { - "file": "src/viewport.js", - "startLine": 37, - "endLine": 46, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nWill move the stage and therefore every visible entity along the `x`\naxis in the opposite direction.\n\nWhen this value is set, it will shift the entire stage. This means that entity\npositions are not exactly where they are on screen. To get the exact position,\nsimply add `Crafty.viewport.x` onto the entities `x` position." - } - ], - "name": "Crafty.viewport.x", - "comp": "Crafty.viewport" - }, - { - "file": "src/viewport.js", - "startLine": 49, - "endLine": 58, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nWill move the stage and therefore every visible entity along the `y`\naxis in the opposite direction.\n\nWhen this value is set, it will shift the entire stage. This means that entity\npositions are not exactly where they are on screen. To get the exact position,\nsimply add `Crafty.viewport.y` onto the entities `y` position." - } - ], - "name": "Crafty.viewport.y", - "comp": "Crafty.viewport" - }, - { - "file": "src/viewport.js", - "startLine": 62, - "endLine": 71, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ - { - "type": "raw", - "value": "\nThis value is the current scale (zoom) of the viewport. When the value is bigger than 1, everything\nlooks bigger (zoomed in). When the value is less than 1, everything looks smaller (zoomed out). This\ndoes not alter the size of the stage itself, just the magnification of what it shows.\n\nThis is a read-only property: Do not set it directly. Instead, use `Crafty.viewport.scale(...)`\nor `Crafty.viewport.zoom(...)`" } ], - "name": "Crafty.viewport._scale", - "comp": "Crafty.viewport" + "name": ".setValues", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/viewport.js", - "startLine": 76, - "endLine": 96, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 1056, + "endLine": 1065, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "\nA rectangle which defines the bounds of the viewport.\nIt should be an object with two properties, `max` and `min`,\nwhich are each an object with `x` and `y` properties.\n\nIf this property is null, Crafty uses the bounding box of all the items\non the stage. This is the initial value. (To prevent this behavior, set `Crafty.viewport.clampToEntities` to `false`)\n\nIf you wish to bound the viewport along one axis but not the other, you can use `-Infinity` and `+Infinity` as bounds.\n" - }, - { - "type": "xref", - "xrefs": [ - "Crafty.viewport.clampToEntities" - ] - }, - { - "type": "raw", - "value": "" + "value": "Returns the string representation of this matrix.\n" }, { - "type": "example", + "type": "method", + "signature": "public {String} toString();", "contents": [ { - "type": "raw", - "value": "Set the bounds to a 500 by 500 square:\n\n```\nCrafty.viewport.bounds = {min:{x:0, y:0}, max:{x:500, y:500}};\n```" + "type": "return", + "value": "{String}" } ] } ], - "name": "Crafty.viewport.bounds", - "comp": "Crafty.viewport" + "name": ".toString", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/viewport.js", - "startLine": 100, - "endLine": 115, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/math.js", + "startLine": 1071, + "endLine": 1083, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "raw", + "value": "Applies a post-translation to this matrix\n" + }, { "type": "method", - "signature": "Crafty.viewport.scroll(String axis, Number val)", + "signature": "public {Matrix2D} translate(Vector2D);", + "contents": [] + }, + { + "type": "method", + "signature": "public {Matrix2D} translate(Number, Number);", "contents": [ { "type": "param", - "name": "axis", - "description": "'x' or 'y'" + "name": "{Number|Vector2D} dx", + "description": "" }, { "type": "param", - "name": "val", - "description": "The new absolute position on the axis" - } - ] - }, - { - "type": "raw", - "value": "\nWill move the viewport to the position given on the specified axis\n" - }, - { - "type": "example", - "contents": [ + "name": "{Number} dy", + "description": "" + }, { - "type": "raw", - "value": "Will move the camera 500 pixels right of its initial position, in effect\nshifting everything in the viewport 500 pixels to the left.\n\n```\nCrafty.viewport.scroll('_x', 500);\n```" + "type": "return", + "value": "{Matrix2D} this matrix after post-translation" } ] } ], - "name": "Crafty.viewport.scroll", - "comp": "Crafty.viewport" + "name": ".translate", + "comp": "Crafty.math.Matrix2D", + "public": true }, { - "file": "src/viewport.js", - "startLine": 133, - "endLine": 142, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/rect-manager.js", + "startLine": 4, + "endLine": 9, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "" - }, + "value": "Collection of methods for handling rectangles" + } + ], + "name": "Crafty.rectManager", + "categories": [ + "2D" + ] + }, + { + "file": "src/spatial/rect-manager.js", + "startLine": 28, + "endLine": 37, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", + "contents": [ { "type": "method", - "signature": "public void Crafty.viewport.pan(Number dx, Number dy, Number time)", + "signature": "public Boolean Crafty.rectManager.overlap(Object rectA, Object rectA)", "contents": [ { "type": "param", - "name": "Number dx", - "description": "The distance along the x axis" + "name": "rectA", + "description": "An object that must have the `_x, _y, _w, _h` values as properties" }, { "type": "param", - "name": "Number dy", - "description": "The distance along the y axis" + "name": "rectB", + "description": "An object that must have the `_x, _y, _w, _h` values as properties" }, { - "type": "param", - "name": "Number time", - "description": "The duration in ms for the entire camera movement" + "type": "return", + "value": "true if the rectangles overlap; false otherwise" } ] }, { "type": "raw", - "value": "\nPans the camera a given number of pixels over the specified time" + "value": "Checks whether two rectangles overlap." } ], - "name": "Crafty.viewport.pan", - "comp": "Crafty.viewport" + "name": "Crafty.rectManager.overlap", + "comp": "Crafty.rectManager" }, { - "file": "src/viewport.js", - "startLine": 189, - "endLine": 204, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/rect-manager.js", + "startLine": 43, + "endLine": 55, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.viewport.follow(Object target, Number offsetx, Number offsety)", + "signature": "public Object Crafty.rectManager.mergeSet(Object set)", "contents": [ { "type": "param", - "name": "Object target", - "description": "An entity with the 2D component" - }, - { - "type": "param", - "name": "Number offsetx", - "description": "Follow target should be offsetx pixels away from center" - }, - { - "type": "param", - "name": "Number offsety", - "description": "Positive puts target to the right of center" + "name": "set", + "description": "an array of rectangular regions" } ] }, { "type": "raw", - "value": "\nFollows a given entity with the 2D component. If following target will take a portion of\nthe viewport out of bounds of the world, following will stop until the target moves away.\n" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nvar ent = Crafty.e('2D, DOM').attr({w: 100, h: 100:});\nCrafty.viewport.follow(ent, 0, 0);\n```" - } - ] + "value": "Merge any consecutive, overlapping rects into each other.\nIts an optimization for the redraw regions.\n\nThe order of set isn't strictly meaningful,\nbut overlapping objects will often cause each other to change,\nand so might be consecutive." } ], - "name": "Crafty.viewport.follow", - "comp": "Crafty.viewport" + "name": "Crafty.rectManager.mergeSet", + "comp": "Crafty.rectManager" }, { - "file": "src/viewport.js", - "startLine": 236, - "endLine": 243, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/rect-manager.js", + "startLine": 76, + "endLine": 84, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.viewport.centerOn(Object target, Number time)", + "signature": "public Crafty.rectManager.boundingRect(set)", "contents": [ { "type": "param", - "name": "Object target", - "description": "An entity with the 2D component" - }, - { - "type": "param", - "name": "Number time", - "description": "The duration in ms of the camera motion" + "name": "set", + "description": "An array of rectangles" } ] }, { "type": "raw", - "value": "\nCenters the viewport on the given entity." + "value": "- Calculate the common bounding rect of multiple canvas entities.\n- Returns coords" } ], - "name": "Crafty.viewport.centerOn", - "comp": "Crafty.viewport" + "name": "Crafty.rectManager.boundingRect", + "comp": "Crafty.rectManager" }, { - "file": "src/viewport.js", - "startLine": 258, - "endLine": 269, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/spatial-grid.js", + "startLine": 10, + "endLine": 18, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.viewport.zoom(Number amt, Number cent_x, Number cent_y, Number time)", + "signature": "public void Crafty.HashMap([cellsize])", "contents": [ { "type": "param", - "name": "Number amt", - "description": "amount to zoom in on the target by (eg. 2, 4, 0.5)" - }, - { - "type": "param", - "name": "Number cent_x", - "description": "the center to zoom on" - }, - { - "type": "param", - "name": "Number cent_y", - "description": "the center to zoom on" - }, - { - "type": "param", - "name": "Number time", - "description": "the duration in ms of the entire zoom operation" + "name": "cellsize", + "description": "the cell size. If omitted, `cellsize` is 64." } ] }, { "type": "raw", - "value": "\nZooms the camera in on a given point. amt > 1 will bring the camera closer to the subject\namt < 1 will bring it farther away. amt = 0 will reset to the default zoom level\nZooming is multiplicative. To reset the zoom amount, pass 0." + "value": "Set `cellsize`.\nAnd create `this.map`." } ], - "name": "Crafty.viewport.zoom", - "comp": "Crafty.viewport" + "name": "Crafty.HashMap.constructor", + "comp": "Crafty.HashMap" }, { - "file": "src/viewport.js", - "startLine": 347, - "endLine": 367, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/spatial-grid.js", + "startLine": 30, + "endLine": 45, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.viewport.scale(Number amt)", + "signature": "public Object Crafty.map.insert(Object obj)", "contents": [ { "type": "param", - "name": "Number amt", - "description": "amount to zoom/scale in on the elements" + "name": "obj", + "description": "An entity to be inserted." + }, + { + "type": "return", + "value": "An object representing this object's entry in the HashMap" } ] }, { "type": "raw", - "value": "\nAdjusts the scale (zoom). When `amt` is 1, it is set to the normal scale,\ne.g. an entity with `this.w == 20` would appear exactly 20 pixels wide.\nWhen `amt` is 10, that same entity would appear 200 pixels wide (i.e., zoomed in\nby a factor of 10), and when `amt` is 0.1, that same entity would be 2 pixels wide\n(i.e., zoomed out by a factor of `(1 / 0.1)`).\n\nIf you pass an `amt` of 0, it is treated the same as passing 1, i.e. the scale is reset.\n\nThis method sets the absolute scale, while `Crafty.viewport.zoom` sets the scale relative to the existing value." - }, - { - "type": "xref", - "xrefs": [ - "Crafty.viewport.zoom" - ] - }, - { - "type": "raw", - "value": "" - }, - { - "type": "example", - "contents": [ - { - "type": "raw", - "value": "```\nCrafty.viewport.scale(2); // Zoom in -- all entities will appear twice as large.\n```" - } - ] + "value": "`obj` is inserted in '.map' of the corresponding broad phase cells. An object of the following fields is returned.\n```\n{\n keys: the object that keep track of cells\n obj: The inserted object\n map: the HashMap object\n}\n```" } ], - "name": "Crafty.viewport.scale", - "comp": "Crafty.viewport" + "name": "Crafty.map.insert", + "comp": "Crafty.map" }, { - "file": "src/viewport.js", - "startLine": 377, - "endLine": 387, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/spatial-grid.js", + "startLine": 66, + "endLine": 77, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.viewport.mouselook(Boolean active)", + "signature": "public Object Crafty.map.search(Object rect[, Boolean filter])", "contents": [ { "type": "param", - "name": "Boolean active", - "description": "Activate or deactivate mouselook" + "name": "rect", + "description": "the rectangular region to search for entities." + }, + { + "type": "param", + "name": "filter", + "description": "If false, only performs a broad-phase collision check. The default value is true." } ] }, { "type": "raw", - "value": "\nToggle mouselook on the current viewport.\nSimply call this function and the user will be able to\ndrag the viewport around.\n\nIf the user starts a drag, \"StopCamera\" will be triggered, which will cancel any existing camera animations." + "value": "- If `filter` is `false`, just search for all the entries in the give `rect` region by broad phase collision. Entity may be returned duplicated.\n- If `filter` is `true`, filter the above results by checking that they actually overlap `rect`.\n\nThe easier usage is with `filter == true`. For performance reason, you may use `filter == false`, and filter the result yourself. See examples in drawing.js and collision.js" } ], - "name": "Crafty.viewport.mouselook", - "comp": "Crafty.viewport" + "name": "Crafty.map.search", + "comp": "Crafty.map" }, { - "file": "src/viewport.js", - "startLine": 467, - "endLine": 480, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/spatial-grid.js", + "startLine": 122, + "endLine": 136, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "method", - "signature": "public void Crafty.viewport.init([Number width, Number height, String stage_elem])", - "contents": [] - }, - { - "type": "method", - "signature": "public void Crafty.viewport.init([Number width, Number height, HTMLElement stage_elem])", + "signature": "public void Crafty.map.remove([Object keys, ]Object obj)", "contents": [ { "type": "param", - "name": "Number width", - "description": "Width of the viewport" - }, - { - "type": "param", - "name": "Number height", - "description": "Height of the viewport" + "name": "keys", + "description": "key region. If omitted, it will be derived from obj by `Crafty.HashMap.key`." }, { "type": "param", - "name": "String or HTMLElement stage_elem", - "description": "the element to use as the stage (either its id or the actual element)." + "name": "obj", + "description": "An object to remove from the hashmap" } ] }, { "type": "raw", - "value": "\nInitialize the viewport. If the arguments 'width' or 'height' are missing, use Crafty.DOM.window.width and Crafty.DOM.window.height (full screen model).\n\nThe argument 'stage_elem' is used to specify a stage element other than the default, and can be either a string or an HTMLElement. If a string is provided, it will look for an element with that id and, if none exists, create a div. If an HTMLElement is provided, that is used directly. Omitting this argument is the same as passing an id of 'cr-stage'.\n" + "value": "Remove an entity in a broad phase map.\n- The second form is only used in Crafty.HashMap to save time for computing keys again, where keys were computed previously from obj. End users should not call this form directly.\n" }, { - "type": "xref", - "xrefs": [ - "Crafty.device", - "Crafty.DOM", - "Crafty.stage" + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.map.remove(e);\n```" + } ] } ], - "name": "Crafty.viewport.init", - "comp": "Crafty.viewport" + "name": "Crafty.map.remove", + "comp": "Crafty.map" }, { - "file": "src/viewport.js", - "startLine": 504, - "endLine": 507, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/spatial-grid.js", + "startLine": 164, + "endLine": 176, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "raw", - "value": "The stage where all the DOM entities will be placed." - } - ], - "name": "Crafty.stage", - "categories": [ - "Core" - ] - }, - { - "file": "src/viewport.js", - "startLine": 510, - "endLine": 513, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", - "contents": [ + "type": "method", + "signature": "public void Crafty.map.remove(Entry entry)", + "contents": [ + { + "type": "param", + "name": "entry", + "description": "An entry to update" + } + ] + }, { "type": "raw", - "value": "The `#cr-stage` div element." + "value": "Update an entry's keys, and its position in the broad phrase map.\n" + }, + { + "type": "example", + "contents": [ + { + "type": "raw", + "value": "```\nCrafty.map.refresh(e);\n```" + } + ] } ], - "name": "Crafty.stage.elem", - "comp": "Crafty.stage" + "name": "Crafty.map.refresh", + "comp": "Crafty.map" }, { - "file": "src/viewport.js", - "startLine": 516, - "endLine": 527, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/spatial-grid.js", + "startLine": 214, + "endLine": 232, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ + { + "type": "method", + "signature": "public Object Crafty.map.boundaries()", + "contents": [ + { + "type": "return", + "value": "An object with the following structure, which represents an MBR which contains all entities" + } + ] + }, { "type": "raw", - "value": "`Crafty.stage.inner` is a div inside the `#cr-stage` div that holds all DOM entities.\nIf you use canvas, a `canvas` element is created at the same level in the dom\nas the the `Crafty.stage.inner` div. So the hierarchy in the DOM is\n\n```\nCrafty.stage.elem\n - Crafty.stage.inner (a div HTMLElement)\n - Crafty.canvas._canvas (a canvas HTMLElement)\n```" + "value": "```\n{\n min: {\n x: val_x,\n y: val_y\n },\n max: {\n x: val_x,\n y: val_y\n }\n}\n```" } ], - "name": "Crafty.stage.inner", - "comp": "Crafty.stage" + "name": "Crafty.map.boundaries", + "comp": "Crafty.map" }, { - "file": "src/viewport.js", - "startLine": 678, - "endLine": 687, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/spatial-grid.js", + "startLine": 309, + "endLine": 317, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { "type": "raw", - "value": "" - }, - { - "type": "method", - "signature": "public Crafty.viewport.reload()", - "contents": [] + "value": "Broad-phase collision detection engine. See background information at\n\n- [N Tutorial B - Broad-Phase Collision](http://www.metanetsoftware.com/technique/tutorialB.html)\n- [Broad-Phase Collision Detection with CUDA](http://http.developer.nvidia.com/GPUGems3/gpugems3_ch32.html)" }, { - "type": "raw", - "value": "\nRecalculate and reload stage width, height and position.\nUseful when browser return wrong results on init (like safari on Ipad2).\nYou should also call this method if you insert custom DOM elements that affect Crafty's stage offset.\n" + "type": "xref", + "xrefs": [ + "Crafty.map" + ] } ], - "name": "Crafty.viewport.reload", - "comp": "Crafty.stage" + "name": "Crafty.HashMap", + "categories": [ + "2D" + ] }, { - "file": "src/viewport.js", - "startLine": 707, - "endLine": 715, - "commit": "b74c13c0cc74f8773bb2bf563009728113ac751c", + "file": "src/spatial/spatial-grid.js", + "startLine": 319, + "endLine": 329, + "commit": "5c34e4039278e39defc230858d1e83c078935f50", "contents": [ { - "type": "triggers", - "events": [ + "type": "method", + "signature": "public Object Crafty.HashMap.key(Object obj)", + "contents": [ { - "type": "trigger", - "event": "StopCamera", - "description": "called to cancel camera animations", - "objName": "Data", - "objProp": null + "type": "param", + "name": "obj", + "description": "an Object that has .mbr() or _x, _y, _w and _h." } ] }, { "type": "raw", - "value": "" - }, - { - "type": "method", - "signature": "public Crafty.viewport.reset()", - "contents": [] + "value": "Get the rectangular region (in terms of the grid, with grid size `cellsize`), where the object may fall in. This region is determined by the object's bounding box.\nThe `cellsize` is 64 by default.\n" }, { - "type": "raw", - "value": "\nResets the viewport to starting values, and cancels any existing camera animations.\nCalled when scene() is run." + "type": "xref", + "xrefs": [ + "Crafty.HashMap.constructor" + ] } ], - "name": "Crafty.viewport.reset", - "comp": "Crafty.stage" + "name": "Crafty.HashMap.key", + "comp": "Crafty.HashMap" } ] \ No newline at end of file