API Docs for: 1.4.0
Show:

Kiwi.Components.Box Class

Extends Kiwi.Component
Module: Components
Parent Module: Kiwi

The Box Component is used to handle the various 'bounds' that each GameObject has. There are two main different types of bounds (Bounds and Hitbox) with each one having three variants (each one is a rectangle) depending on what you are wanting:

RawBounds: The bounding box of the GameObject before rotation/scale.

RawHitbox: The hitbox of the GameObject before rotation/scale. This can be modified to be different than the normal bounds but if not specified it will be the same as the raw bounds.

Bounds: The bounding box of the GameObject after rotation/scale.

Hitbox: The hitbox of the GameObject after rotation/scale. If you modified the raw hitbox then this one will be modified as well, otherwise it will be the same as the normal bounds.

WorldBounds: The bounding box of the Entity using its world coordinates and after rotation/scale.

WorldHitbox: The hitbox of the Entity using its world coordinates and after rotation/scale.

Constructor

Kiwi.Components.Box

(
  • parent
  • [x=0]
  • [y=0]
  • [width=0]
  • [height=0]
)
Kiwi.Components.Box

Parameters:

  • parent Kiwi.Entity

    The entity that this box belongs to.

  • [x=0] Number optional

    Its position on the x axis

  • [y=0] Number optional

    Its position on the y axis

  • [width=0] Number optional

    The width of the box.

  • [height=0] Number optional

    The height of the box.

Methods

_rotateHitbox

(
  • rect
  • [useWorldCoords=false]
)
Kiwi.Geom.Rectangle private

A private method that is used to calculate the transformed hitbox's coordinates after rotation.

Parameters:

_rotateRect

(
  • rect
  • [useWorldCoords=false]
)
Kiwi.Geom.Rectangle private

Private internal method only. Used to calculate the transformed bounds after rotation/scale.

Parameters:

destroy

() public

Inherited from Kiwi.Component but overwritten in src\components\Box.ts:501

Destroys this component and all of the links it may have to other objects.

draw

(
  • ctx
  • [camera]
)
public

Draws the various bounds on a context that is passed. Useful for debugging and using in combination with the debug canvas.

Parameters:

  • ctx CanvasRenderingContext2D

    Context of the canvas that this box component is to be rendered on top of.

  • [camera] Kiwi.Camera optional

    A camera that should be taken into account before rendered. This is the default camera by default.

extents

(
  • topLeftPoint
  • topRightPoint
  • bottomRightPoint
  • bottomLeftPoint
)

Method which takes four Points and then converts it into a Rectangle, which represents the area those points covered. The points passed can be maybe in any order, as the are checked for validity first.

Parameters:

  • topLeftPoint Kiwi.Geom.Point

    The top left Point that the Rectangle should have.

  • topRightPoint Kiwi.Geom.Point

    The top right Point that the Rectangle should have.

  • bottomRightPoint Kiwi.Geom.Point

    The bottom right Point that the Rectangle should have.

  • bottomLeftPoint Kiwi.Geom.Point

    The bottom left Point that the Rectangle should have.

Returns:

Rectangle

objType

() String public

Inherited from Kiwi.Component but overwritten in src\components\Box.ts:67

The type of object that this is.

Returns:

String:

"Box"

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.

update

() public

If the component is being added to a State rather than a Game Object then over-ride its update method to perform required tasks.

Properties

_hitboxOffset

Kiwi.Geom.Point private

Contains offset point for the hitbox

_rawBounds

Kiwi.Geom.Rectangle private

The 'raw' bounds of entity. This is its bounds before rotation/scale. This for property is only for storage of the values and should be accessed via the getter 'rawBounds' so that it can update.

_rawHitbox

Kiwi.Geom.Rectangle private

Contains the offset rectangle for the raw hitbox.

_scratchMatrix

Kiwi.Geom.Matrix private

Defined in src\components\Box.ts:290

Available since 1.3.1

Scratch matrix used in geometry calculations

_transformedBounds

Kiwi.Geom.Rectangle private

Contains the transformed or 'normal' bounds for this entity.

_transformedCenter

Kiwi.Geom.Point private

Contains the center point after the box has been transformed.

_transformedHitbox

Kiwi.Geom.Rectangle private

The transformed or 'normal' hitbox for the entity. This is its box after rotation/scale.

_worldBounds

Kiwi.Geom.Rectangle private

The 'world' transformed bounds for this entity.

_worldHitbox

Kiwi.Geom.Rectangle private

The transformed 'world' hitbox for the entity. This is its box after rotation/scale.

active

Boolean public

An active Component is one that has its update method called by its parent.

Default: true

autoUpdate

Boolean private

Controls whether the hitbox should update automatically to match the hitbox of the current cell on the entity this Box component is attached to (default behaviour). Or if the hitbox shouldn't auto update. Which will mean it will stay the same as the last value it had. This property is automatically set to 'false' when you override the hitboxes width/height, but you can set this to true afterwards.

Default: true

bounds

Kiwi.Geom.Rectangle public

Returns the 'transformed' or 'normal' bounds for this box. This is READ ONLY.

center

Kiwi.Geom.Point public

Returns the center point for the box after it has been transformed. World coordinates. This is READ ONLY.

dirty

Boolean deprecated public

Inherited from Kiwi.Component but overwritten in src\components\Box.ts:91

Deprecated: in version 1.1.0 because the box always needed updating

Indicates whether or not this component needs re-rendering/updating or not.

entity

Kiwi.Entity public

The entity that this box belongs to.

game

Kiwi.Game public

The game this Component belongs to

hitbox

Kiwi.Geom.Rectangle public

The 'normal' or transformed hitbox for the entity. This is its box after rotation/Kiwi.Geom.Rectangle.

hitboxOffset

Kiwi.Geom.Point public

Returns the offset value of the hitbox as a point for the X/Y axis for the developer to use. This is without rotation or scaling. This is a READ ONLY property.

Kiwi.Geom.Point

Kiwi.Geom.Point private

Contains the 'raw' center point for the bounds.

name

String public

The name of this component.

owner

Object public

The object that owns this entity

rawBounds

Kiwi.Geom.Rectangle public

Returns the 'raw' bounds for this entity. This is READ ONLY.

rawCenter

Kiwi.Geom.Point public

Returns the raw center point of the box. This is READ ONLY.

rawHitbox

Kiwi.Geom.Rectangle public

Returns the raw hitbox rectangle for the developer to use. 'Raw' means where it would be without rotation or scaling. This is READ ONLY.

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.

worldBounds

Kiwi.Geom.Rectangle public

Returns the 'transformed' bounds for this entity using the world coodinates. This is READ ONLY.

worldHitbox

Kiwi.Geom.Rectangle public

Returns the transformed hitbox for the entity using its 'world' coordinates. This is READ ONLY.