Constructor
# new GameObject(x, y, width, height)
Create a GameObject
Parameters:
Name | Type | Description |
---|---|---|
x |
number
|
X position |
y |
number
|
Y position |
width |
number
|
The width of the GameObject |
height |
number
|
The height of the GameObject |
Members
# CollisionLayer
Changes the collision layer for this GameObject. The collision layer determines with which other GameObject this GameObject can interact.
collision layers are set in the Settings.js
# Debug
When debug is set to true, debug values are shown on screen. (e.g. render-depth, collisionbox, ...)
# Depth
The depth value determines the rendering order of each GameObject. GameObjects with identical depth values have no predetermined rendering order.
# Depth
The depth value determines the rendering order of each GameObject. GameObjects with identical depth values have no predetermined rendering order.
# Hit
The location where the collider for this GameObject was hit. (left, right, top, bottom)
# Immovable
An immovable object cannot be displaced by another GameObject.
# Immovable
An immovable object cannot be displaced by another GameObject.
# Index
The index shows in what order a GameObject was added to the game. The first GameObject that was added gets index 0, the next 1, ...
# Life
Determines how many frames this GameObject will remain alive (before being removed automatically).
# Position
A p5.Vector (x, y) that represents the position of the current GameObject on the X and Y axis in pixels.
# Position
A p5.Vector (x, y) that represents the position of the current GameObject on the X and Y axis in pixels.
# Removed
Property to check if the GameObject was removed from the scene
# Speed
The speed of this GameObject, the same as the magnitude of the Velocity Vector.
# Velocity
A p5.Vector (x, y) representing the velocity of the GameObject on the X and Y axis.
# Velocity
A p5.Vector (x, y) representing the velocity of the GameObject on the X and Y axis.
Methods
# AddSpeed(speed, angle)
Adds some speed in a certain direction.
Parameters:
Name | Type | Description |
---|---|---|
speed |
number
|
The speed that should be added to the current speed (determined by the Velocity). |
angle |
number
|
The angle of direction where the GameObject should move to. |
# Collide(…otherSprites)
Check if the current GameObject collides with any of a list of GameObjects. When it collides, OnCollide gets called.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
otherSprites |
any
|
<repeatable> |
List of GameObjects. The functions checks which of these GameObjects collides with the current GameObject (ignoring itself). |
true if a collision was found, false if not
# Displace(displacement)
Moves the GameObject according to a given displacement.
Parameters:
Name | Type | Description |
---|---|---|
displacement |
p5.Vector
|
The displacement vector that determines where and how much the current GameObject should be moved. |
# Display()
Display gets called every frame, and prepares the GameObject to be drawn correctly. Do not call this directly, or override this!
# LimitSpeed(max)
Sets a maximum size for the velocity vector. The GameObject cannot move faster than this speed.
Parameters:
Name | Type | Description |
---|---|---|
max |
number
|
The maximum speed at which the GameObject can move when using the Velocity. |
# OnCollide(spritesHit)
Function that gets called when a collision with this GameObject is detected. Override this function to check for collisions.
Parameters:
Name | Type | Description |
---|---|---|
spritesHit |
Array.<GameObject>
|
Array of GameObjects that overlap with this GameObject |
# OnOverlap(spritesHit)
Function that gets called when an overlap with this GameObject is detected. Override this function to check for overlaps.
Parameters:
Name | Type | Description |
---|---|---|
spritesHit |
Array.<GameObject>
|
Array of GameObjects that overlap with this GameObject |
# Overlap(…otherSprites)
Check if the current GameObject overlaps with any of a list of GameObjects. When it overlaps, OnOverlap gets called.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
otherSprites |
any
|
<repeatable> |
List of GameObjects. The functions checks which of these GameObjects overlaps with the current GameObject (ignoring itself). |
true if an overlap was found, false if not
# Remove()
Removes the current GameObject from the scene. The GameObject may not be removed from memory instantly, but the Removed property is set to true.
# RemoveCollider()
Removes the currently set collider from the GameObject. If no collider was set before, this does nothing.
# SetDefaultCollider()
Creates a default collider based on the GameObject's width and height, and assigns it to the current GameObject.
# SetSpeed(speed, angle)
Sets the speed and direction for the current GameObject.
Parameters:
Name | Type | Description |
---|---|---|
speed |
number
|
The speed at which the GameObject should start moving. |
angle |
number
|
The angle of direction where the GameObject should move to. |
# Update()
Update gets called every frame. Override this function to implement your own visualisations and/or frame-actions (input, movement, ...).