Kiwi.Components.Box Class
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]
Parameters:
-
parent
Kiwi.EntityThe entity that this box belongs to.
-
[x=0]
Number optionalIts position on the x axis
-
[y=0]
Number optionalIts position on the y axis
-
[width=0]
Number optionalThe width of the box.
-
[height=0]
Number optionalThe height of the box.
Returns:
Item Index
Properties
- _hitboxOffset
- _rawBounds
- _rawHitbox
- _scratchMatrix
- _transformedBounds
- _transformedCenter
- _transformedHitbox
- _worldBounds
- _worldHitbox
- active
- autoUpdate
- bounds
- center
- dirty deprecated
- entity
- game
- hitbox
- hitboxOffset
- Kiwi.Geom.Point
- name
- owner
- rawBounds
- rawCenter
- rawHitbox
- state
- worldBounds
- worldHitbox
Methods
_rotateHitbox
-
rect
-
[useWorldCoords=false]
A private method that is used to calculate the transformed hitbox's coordinates after rotation.
Parameters:
-
rect
Kiwi.Geom.Rectangle -
[useWorldCoords=false]
Boolean optional
Returns:
_rotateRect
-
rect
-
[useWorldCoords=false]
Private internal method only. Used to calculate the transformed bounds after rotation/scale.
Parameters:
-
rect
Kiwi.Geom.Rectangle -
[useWorldCoords=false]
Boolean optional
Returns:
destroy
()
public
Destroys this component and all of the links it may have to other objects.
draw
-
ctx
-
[camera]
Draws the various bounds on a context that is passed. Useful for debugging and using in combination with the debug canvas.
Parameters:
-
ctx
CanvasRenderingContext2DContext of the canvas that this box component is to be rendered on top of.
-
[camera]
Kiwi.Camera optionalA 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.PointThe top left Point that the Rectangle should have.
-
topRightPoint
Kiwi.Geom.PointThe top right Point that the Rectangle should have.
-
bottomRightPoint
Kiwi.Geom.PointThe bottom right Point that the Rectangle should have.
-
bottomLeftPoint
Kiwi.Geom.PointThe bottom left Point that the Rectangle should have.
Returns:
Rectangle
objType
()
String
public
The type of object that this is.
Returns:
"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
_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.
_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.
_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
Indicates whether or not this component needs re-rendering/updating or not.
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.
name
String
public
The name of this component.
owner
Object
public
The object that owns this entity
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.
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.