Kiwi.Components.ArcadePhysics Class
Arcade Physics is an Optional Component that can be used when you are wanting to do basic physics collisions. These have been ported from Flixel, so most function operate identically to the original flixel functions, though some have been split into multiple functions. Generally where functions originally accepted either groups or gameobjects within the same argument, the ported functions one or the other. http://www.flixel.org/ http://www.adamatomic.com/
Constructor
Kiwi.Components.ArcadePhysics
-
entity
-
box
Parameters:
-
entity
Kiwi.EntityThe Entity that this ArcadePhysics should be used on.
-
box
Kiwi.Components.BoxThe box component that holds the hitbox that should be used when resolving and calculating collisions.
Returns:
Item Index
Methods
- collide static
- collideGroup static
- collideGroupGroup static
- computeVelocity static
- destroy
- isTouching
- objType
- overlaps static
- overlaps static
- overlaps
- overlapsArray
- overlapsArrayGroup static
- overlapsGroup
- overlapsObjectGroup static
- overlapsTiles
- postUpdate
- preUpdate
- rotateToVelocity
- separateTiles static
- separateTilesX static
- separateTilesY static
- seperate static
- seperateX static
- seperateY static
- setCallback
- solid
- update
- updateMotion
Properties
- _callbackContext
- _callbackFunction
- _solid
- acceleration
- active
- allowCollisions
- angularAcceleration
- angularDrag
- angularVelocity
- ANY static
- box
- CEILING static
- dirty deprecated
- DOWN static
- drag
- elasticity
- FLOOR static
- game
- immovable
- last
- LEFT static
- mass
- maxAngular
- maxVelocity
- moves
- name
- NONE static
- OVERLAP_BIAS static
- owner
- parent
- RIGHT static
- state
- touching
- transform
- UP static
- updateInterval static
- velocity
- WALL static
- wasTouching
Methods
collide
-
gameObject1
-
gameObject2
-
[seperate=true]
A Static method to check to see if two objects collide or not. Returns a boolean indicating whether they overlaped or not.
Parameters:
-
gameObject1
Kiwi.EntityThe first game object.
-
gameObject2
Kiwi.EntityThe second game object.
-
[seperate=true]
Boolean optionalIf the two gameobjects should seperated when they collide.
Returns:
collideGroup
-
gameObject
-
group
-
[seperate=true]
A Static method to check to see if a single entity collides with a group of entities. Returns a boolean indicating whether they overlaped or not.
Parameters:
-
gameObject
Kiwi.EntityThe entity you would like to check against.
-
group
Kiwi.GroupThe Kiwi Group that you want to check the entity against.
-
[seperate=true]
Boolean optional
Returns:
collideGroupGroup
-
group1
-
group2
-
[seperate=true]
A Static method to check to see if a group of entities overlap with another group of entities. Returns a boolean indicating whether they overlaped or not.
Parameters:
-
group1
Kiwi.GroupThe first Kiwi Group that you want to check the entity against.
-
group2
Kiwi.GroupThe second Kiwi Group that you want to check the entity against.
-
[seperate=true]
Boolean optional
Returns:
computeVelocity
-
velocity
-
[acceleration=0]
-
[drag=0]
-
[max=10000]
Computes the velocity based on the parameters passed.
Parameters:
-
velocity
NumberThe currently velocity.
-
[acceleration=0]
Number optionalThe acceleration of the item.
-
[drag=0]
Number optionalThe amount of drag effecting the item.
-
[max=10000]
Number optionalThe maximum velocity.
Returns:
The new velocity
destroy
()
public
Removes all properties that refer to other objects or outside of this class in order to flag this object for garbage collection.
isTouching
-
value
Returns a boolean indicating whether the or not the object is currently colliding on a particular side that is passed. Use the collision constants (like LEFT, FLOOR, e.t.c) when passing sides.
Parameters:
-
value
Object[number] The collision constant of the side you want to check against.
Returns:
If the Object is currently colliding on that side or not.
objType
()
String
public
The type of object that this is.
Returns:
"ArcadePhysics"
overlaps
-
gameObject1
-
gameObject2
-
[separateObjects=true]
A Static method to that checks to see if two objects overlap. Returns a boolean indicating whether they did or not.
Parameters:
-
gameObject1
Kiwi.EntityThe first game object.
-
gameObject2
Kiwi.EntityThe second gameobject you are testing the first against.
-
[separateObjects=true]
Boolean optional
Returns:
overlaps
-
group1
-
group2
-
[seperate=true]
A Static method that checks to see if any objects in one group overlap with objects in another group.
Parameters:
-
group1
Kiwi.GroupThe first group you would like to check against.
-
group2
Kiwi.GroupThe second group you would like to check against.
-
[seperate=true]
Boolean optionalIf they overlap should the seperate or not
Returns:
overlaps
-
gameObject
-
[seperateObjects=false]
A method to check to see if the parent of this physics component overlaps with another Kiwi.Entity. If seperateObjects is true it will seperate the two entities based on their bounding box. Note: The GameObject passed must contain a box component and only if you want to separate the two objects must is ALSO contain an ArcadePhysics component. Also: Not to be used for separation from tiles.
Parameters:
-
gameObject
Kiwi.Entity -
[seperateObjects=false]
Boolean optional
Returns:
overlapsArray
-
array
-
[separateObjects=false]
A method to check to see if the parent of this physics component overlaps with any Entities that are held in an Array which is passed.
Parameters:
-
array
ArrayThe array of GameObjects you want to check.
-
[separateObjects=false]
Boolean optionalIf when the objects collide you want them to seperate outwards.
Returns:
If any overlapping occured or not.
overlapsArrayGroup
-
array
-
group
-
[seperateObjects=true]
A Static method that checks to see if any objects from an Array collide with a Kiwi Group members.
Parameters:
-
array
ArrayAn array you want to check collide.
-
group
Kiwi.GroupA group of objects you want to check overlaps.
-
[seperateObjects=true]
Boolean optionalIf when a collision is found the objects should seperate out.
Returns:
overlapsGroup
-
group
-
[seperateObjects=false]
A method to check to see if the parent of this physics component overlaps with another individual in a Kiwi Group.
Parameters:
-
group
Kiwi.Group -
[seperateObjects=false]
Boolean optional
Returns:
If any object in the group overlapped with the GameObject or not.
overlapsObjectGroup
-
gameObject
-
group
-
[seperateObjects=true]
A Static method to that checks to see if a single object overlaps with a group of entities. Returns a boolean indicating whether they did or not.
Parameters:
-
gameObject
Kiwi.Entity -
group
Kiwi.Group -
[seperateObjects=true]
Boolean optionalIf they overlap should the seperate or not
Returns:
overlapsTiles
-
gameObject
-
[separateObjects=false]
-
[collisionType=ANY]
A method to check to see if any Tiles with in this parent TileMapLayer overlaps with a GameObject passed. If seperateObjects is true it will seperate the two entities based on their bounding box. ONLY works if the parent of the ArcadePhysics component which is calling this method is a TileMapLayer. Note: The GameObject passed must contain a box component and only if you want to separate the two objects must is ALSO contain an ArcadePhysics component.
Parameters:
-
gameObject
Kiwi.EntityThe GameObject you would like to separate with this one.
-
[separateObjects=false]
Boolean optionalIf you want the GameObject to be separated from any tile it collides with.
-
[collisionType=ANY]
Number optionalIf you want the GameObject to only check for collisions from a particular side of tiles. ANY by default.
Returns:
If any gameobject overlapped.
postUpdate
()
public
Components can postUpdate, that is run an update after the parent has updated. This is to be overriden by subclasses.
preUpdate
()
public
Components can preUpdate, that is update before the parent updates. This is to be overriden by subclasses.
rotateToVelocity
()
Number
public
Sets the parent's rotation to be equal to the trajectory of the velocity of the physics component. Note that rotation 0 corresponds to pointing directly to the right.
Returns:
New rotation value
separateTiles
-
object
-
layer
-
tiles
Separates a GameObject from a series of passed Tiles that lie on a TileMapLayer. The gameobject needs to have a Box Component and an ArcadePhysics Component. This method is not recommended to be directly used but instead use the 'overlapsTiles' method instead.
Parameters:
-
object
Kiwi.EntityThe GameObject you are wanting to separate from a tile.
-
layer
Kiwi.GameObjects.Tilemap.TileMapLayerThe TileMapLayer that the tiles belong on.
-
tiles
Array
Returns:
If any separation occured.
separateTilesX
-
object
-
layer
-
tile
Separates a GameObjects from an Array of Tiles on the x-axis.
Parameters:
-
object
Kiwi.EntityThe GameObject you are wanting to separate from a tile.
-
layer
Kiwi.GameObjects.Tilemap.TileMapLayerThe TileMapLayer that the tiles belong on.
-
tile
ObjectAn Object containing the information (x/y/tiletypr) about the tile that is being overlapped.
Returns:
If any separation occured.
separateTilesY
-
object
-
layer
-
tiles
Separates a GameObject from a tiles on the y-axis.
Parameters:
-
object
Kiwi.EntityThe GameObject you are wanting to separate from a tile.
-
layer
Kiwi.GameObjects.Tilemap.TileMapLayerThe TileMapLayer that the tiles belong on.
-
tiles
ObjectAn Object representing the Tile which we are checking to see any overlaps occurs.
Returns:
If any separation occured.
seperate
-
object1
-
object2
A static method for seperating two normal GameObjects on both the X and Y Axis's. Both objects need to have both an ArcadePhysics Component and a Box component in order for the separate process to succeed. This method is not recommended to be directly used but instead use a 'collide/overlaps' method instead.
Parameters:
-
object1
Kiwi.EntityThe first GameObject you would like to seperate.
-
object2
Kiwi.EntityThe second GameObject you would like to seperate from the first.
Returns:
seperateX
-
object1
-
object2
Separates two passed GameObjects on the x-axis. Both objects need to have both an ArcadePhysics Component and a Box component in order for the separate process to succeed. This method is not recommended to be directly used but instead use a 'collide/overlaps' method instead.
Parameters:
-
object1
Kiwi.EntityThe first GameObject.
-
object2
Kiwi.EntityThe second GameObject.
Returns:
Whether the objects in fact touched and were separated along the X axis.
seperateY
-
object1
-
object2
Separates two GameObject on the y-axis. This method is executed from the 'separate' method. Both objects need to have both an ArcadePhysics Component and a Box component in order for the separate process to succeed. This method is not recommended to be directly used but instead use a 'collide/overlaps' method instead.
Parameters:
-
object1
Kiwi.EntityThe first GameObject.
-
object2
Kiwi.EntityThe second GameObject.
Returns:
Whether the objects in fact touched and were separated along the Y axis.
setCallback
-
callbackFunction
-
callbackContext
Sets up a callback function that will run when this object overlaps with another. When the method is dispatched it will have TWO arguments. One - The parent / entity of this ArcadePhysics. Two - The GameObject that the collision occured with.
Parameters:
-
callbackFunction
FunctionThe method that is to be executed whe a overlap occurs.
-
callbackContext
AnyThe context that the method is to be called in.
solid
-
[value]
Whether the object should collide with other objects or not.
For more control over what directions the object will collide from, use collision constants (like LEFT, FLOOR, etc)
and set the value of allowCollisions directly.
Parameters:
-
[value]
Boolean optionalIf left empty, this will then just toggle between ANY and NONE.
Returns:
If Object is currently solid or not.
update
()
public
The Update loop of the physics component
updateMotion
()
private
Updates the position of this object. Automatically called if the 'moves' parameter is true.
This called each frame during the update method.
Properties
_callbackContext
Any
private
The context that the callback method should have when it executes.
_callbackFunction
Function
private
A function that is to execute when this object overlaps with another.
Default: null
_solid
Boolean
private
A boolean to indicate if this object is solid or not.
acceleration
Kiwi.Geom.Point
public
How fast the speed of this object is changing. Useful for smooth movement and gravity.
active
Boolean
public
An active Component is one that has its update method called by its parent.
Default: true
allowCollisions
Number
public
Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions. Use bitwise operators to check the values stored here. Useful for things like one-way platforms (e.g. allowCollisions = UP) The accessor "solid" just flips this variable between NONE and ANY.
angularAcceleration
Number
public
How fast the spin speed should change.
angularDrag
Number
public
Like drag
but for spinning.
angularVelocity
Number
public
This is how fast you want this sprite to spin.
ANY
Number
public
static
Special-case constant meaning any direction, used mainly by allowCollisions
and touching
.
Default: 0x1111
box
Kiwi.Components.Box
public
The bounding box component that the collisions are going to be based off. You can modify the 'hitbox' of that component to modify the collision area.
CEILING
Number
public
static
Special-case constant meaning up, used mainly by allowCollisions
and touching
.
Default: 0x0100
dirty
Boolean
deprecated
public
The state of this component.
Default: false
DOWN
Number
public
static
Generic value for "down" Used by facing
, allowCollisions
, and touching
.
Default: 0x1000
drag
Kiwi.Geom.Point
public
This isn't drag exactly, more like deceleration that is only applied when acceleration is not affecting the sprite.
elasticity
Number
public
The bounciness of this object. Only affects collisions. Default value is 0, or "not bouncy at all."
FLOOR
Number
public
static
Special-case constant meaning down, used mainly by allowCollisions
and touching
.
Default: 0x1000
immovable
Boolean
public
Whether an object will move/alter position after a collision.
last
Kiwi.Geom.Point
public
Important variable for collision processing. Tracks the last location of the Entity. This is set during the time this method 'updates'.
LEFT
Number
public
static
Generic value for "left" Used by facing
, allowCollisions
, and touching
.
Default: 0x0001
mass
Number
public
The virtual mass of the object. Default value is 1.
Currently only used with elasticity
during collision resolution.
Change at your own risk; effects seem crazy unpredictable so far!
maxAngular
Number
public
Use in conjunction with angularAcceleration
for fluid spin speed control.
maxVelocity
Kiwi.Geom.Point
public
If you are using acceleration
, you can use maxVelocity
with it
to cap the speed automatically (very useful!).
moves
Boolean
public
If the Entity that this component is a part of 'moves' or not, and thus if the physics should update the motion should update each frame.
Default: true
name
String
public
The name of this component.
NONE
Number
public
static
Special-case constant meaning no collisions, used mainly by allowCollisions
and touching
.
Default: 0
OVERLAP_BIAS
Number
public
static
Handy constant used during collision resolution (see separateX()
and separateY()
).
Default: 4
owner
Object
public
The object that owns this entity
RIGHT
Number
public
static
Generic value for "right" Used by facing
, allowCollisions
, and touching
.
Default: 0x0010
touching
Number
public
Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts. Use bitwise operators to check the values stored here, or use touching(), justStartedTouching(), etc. You can even use them broadly as boolean values if you're feeling saucy!
transform
Kiwi.Geom.Transform
public
The transform component of the entity that the ArcadePhysics is a part of.
UP
Number
public
static
Generic value for "up" Used by facing
, allowCollisions
, and touching
.
Default: 0x0100
updateInterval
Number
public
static
How often the motion should be updated.
Default: 1 / 10
velocity
Kiwi.Geom.Point
public
The basic speed of this object. You can modify the values contained inside this Object to change the speed.
WALL
Number
public
static
Special-case constant meaning only the left and right sides, used mainly by allowCollisions
and touching
.
Default: 0x0011
wasTouching
Number
public
Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts from the previous game loop step. Use bitwise operators to check the values stored here, or use isTouching(). You can even use them broadly as boolean values if you're feeling saucy!