API Docs for: 1.4.0
Show:

Kiwi.Components.ArcadePhysics Class

Extends Kiwi.Component
Module: Components
Parent Module: Kiwi

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
)
Kiwi.Components.ArcadePhysics

Parameters:

  • entity Kiwi.Entity

    The Entity that this ArcadePhysics should be used on.

  • box Kiwi.Components.Box

    The box component that holds the hitbox that should be used when resolving and calculating collisions.

Methods

collide

(
  • gameObject1
  • gameObject2
  • [seperate=true]
)
Boolean public static

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.Entity

    The first game object.

  • gameObject2 Kiwi.Entity

    The second game object.

  • [seperate=true] Boolean optional

    If the two gameobjects should seperated when they collide.

Returns:

Boolean:

collideGroup

(
  • gameObject
  • group
  • [seperate=true]
)
Boolean public static

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.Entity

    The entity you would like to check against.

  • group Kiwi.Group

    The Kiwi Group that you want to check the entity against.

  • [seperate=true] Boolean optional

Returns:

Boolean:

collideGroupGroup

(
  • group1
  • group2
  • [seperate=true]
)
Boolean public static

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.Group

    The first Kiwi Group that you want to check the entity against.

  • group2 Kiwi.Group

    The second Kiwi Group that you want to check the entity against.

  • [seperate=true] Boolean optional

Returns:

Boolean:

computeVelocity

(
  • velocity
  • [acceleration=0]
  • [drag=0]
  • [max=10000]
)
Number public static

Computes the velocity based on the parameters passed.

Parameters:

  • velocity Number

    The currently velocity.

  • [acceleration=0] Number optional

    The acceleration of the item.

  • [drag=0] Number optional

    The amount of drag effecting the item.

  • [max=10000] Number optional

    The maximum velocity.

Returns:

Number:

The new velocity

destroy

() public

Inherited from Kiwi.Component but overwritten in src\components\ArcadePhysics.ts:1090

Removes all properties that refer to other objects or outside of this class in order to flag this object for garbage collection.

isTouching

(
  • value
)
Boolean public

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:

Boolean:

If the Object is currently colliding on that side or not.

objType

() String public

Inherited from Kiwi.Component but overwritten in src\components\ArcadePhysics.ts:1105

The type of object that this is.

Returns:

String:

"ArcadePhysics"

overlaps

(
  • gameObject1
  • gameObject2
  • [separateObjects=true]
)
Boolean public static

A Static method to that checks to see if two objects overlap. Returns a boolean indicating whether they did or not.

Parameters:

  • gameObject1 Kiwi.Entity

    The first game object.

  • gameObject2 Kiwi.Entity

    The second gameobject you are testing the first against.

  • [separateObjects=true] Boolean optional

Returns:

Boolean:

overlaps

(
  • group1
  • group2
  • [seperate=true]
)
Boolean public static

A Static method that checks to see if any objects in one group overlap with objects in another group.

Parameters:

  • group1 Kiwi.Group

    The first group you would like to check against.

  • group2 Kiwi.Group

    The second group you would like to check against.

  • [seperate=true] Boolean optional

    If they overlap should the seperate or not

Returns:

Boolean:

overlaps

(
  • gameObject
  • [seperateObjects=false]
)
Boolean public

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:

Boolean:

overlapsArray

(
  • array
  • [separateObjects=false]
)
Boolean public

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 Array

    The array of GameObjects you want to check.

  • [separateObjects=false] Boolean optional

    If when the objects collide you want them to seperate outwards.

Returns:

Boolean:

If any overlapping occured or not.

overlapsArrayGroup

(
  • array
  • group
  • [seperateObjects=true]
)
Boolean static

A Static method that checks to see if any objects from an Array collide with a Kiwi Group members.

Parameters:

  • array Array

    An array you want to check collide.

  • group Kiwi.Group

    A group of objects you want to check overlaps.

  • [seperateObjects=true] Boolean optional

    If when a collision is found the objects should seperate out.

Returns:

Boolean:

overlapsGroup

(
  • group
  • [seperateObjects=false]
)
Boolean public

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:

Boolean:

If any object in the group overlapped with the GameObject or not.

overlapsObjectGroup

(
  • gameObject
  • group
  • [seperateObjects=true]
)
Boolean public static

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 optional

    If they overlap should the seperate or not

Returns:

Boolean:

overlapsTiles

(
  • gameObject
  • [separateObjects=false]
  • [collisionType=ANY]
)
Boolean public

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.Entity

    The GameObject you would like to separate with this one.

  • [separateObjects=false] Boolean optional

    If you want the GameObject to be separated from any tile it collides with.

  • [collisionType=ANY] Number optional

    If you want the GameObject to only check for collisions from a particular side of tiles. ANY by default.

Returns:

Boolean:

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

Defined in src\components\ArcadePhysics.ts:329

Available since 1.3.0

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:

Number:

New rotation value

separateTiles

(
  • object
  • layer
  • tiles
)
Boolean public static

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:

Returns:

Boolean:

If any separation occured.

separateTilesX

(
  • object
  • layer
  • tile
)
Boolean public static

Separates a GameObjects from an Array of Tiles on the x-axis.

Parameters:

  • object Kiwi.Entity

    The GameObject you are wanting to separate from a tile.

  • layer Kiwi.GameObjects.Tilemap.TileMapLayer

    The TileMapLayer that the tiles belong on.

  • tile Object

    An Object containing the information (x/y/tiletypr) about the tile that is being overlapped.

Returns:

Boolean:

If any separation occured.

separateTilesY

(
  • object
  • layer
  • tiles
)
Boolean public static

Separates a GameObject from a tiles on the y-axis.

Parameters:

  • object Kiwi.Entity

    The GameObject you are wanting to separate from a tile.

  • layer Kiwi.GameObjects.Tilemap.TileMapLayer

    The TileMapLayer that the tiles belong on.

  • tiles Object

    An Object representing the Tile which we are checking to see any overlaps occurs.

Returns:

Boolean:

If any separation occured.

seperate

(
  • object1
  • object2
)
Boolean public static

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.Entity

    The first GameObject you would like to seperate.

  • object2 Kiwi.Entity

    The second GameObject you would like to seperate from the first.

Returns:

Boolean:

seperateX

(
  • object1
  • object2
)
Boolean public static

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:

Returns:

Boolean:

Whether the objects in fact touched and were separated along the X axis.

seperateY

(
  • object1
  • object2
)
Boolean public static

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:

Returns:

Boolean:

Whether the objects in fact touched and were separated along the Y axis.

setCallback

(
  • callbackFunction
  • callbackContext
)
public

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 Function

    The method that is to be executed whe a overlap occurs.

  • callbackContext Any

    The context that the method is to be called in.

solid

(
  • [value]
)
Boolean public

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 optional

    If left empty, this will then just toggle between ANY and NONE.

Returns:

Boolean:

If Object is currently solid or not.

update

() public

Inherited from Kiwi.Component but overwritten in src\components\ArcadePhysics.ts:1068

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

game

Kiwi.Game public

The game this Component belongs to

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

parent

Kiwi.Entity public

Returns the parent of this entity. Mainly used for executing callbacks.

RIGHT

Number public static

Generic value for "right" Used by facing, allowCollisions, and touching.

Default: 0x0010

state

Kiwi.State public

Inherited from Kiwi.Component: src\core\Component.ts:56

Available since 1.3.1

The state which this component's owner belongs to.

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!