Class

GameObject

GameObject(x, y, width, height)

Class representing an object in your game.
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

View Source lib.js, line 507

Members

# Collider

The collider that is currently used on this GameObject

View Source lib.js, line 564

# 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

View Source lib.js, line 581

# Debug

When debug is set to true, debug values are shown on screen. (e.g. render-depth, collisionbox, ...)

View Source lib.js, line 614

# Depth

The depth value determines the rendering order of each GameObject. GameObjects with identical depth values have no predetermined rendering order.

View Source lib.js, line 622

# Depth

The depth value determines the rendering order of each GameObject. GameObjects with identical depth values have no predetermined rendering order.

View Source lib.js, line 630

# Direction

The angle of direction of the velocity vector in radians.

View Source lib.js, line 720

# Height

The height of the GameObject on screen in pixels.

View Source lib.js, line 662

# Height

The height of the GameObject on screen in pixels.

View Source lib.js, line 670

# Hit

The location where the collider for this GameObject was hit. (left, right, top, bottom)

View Source lib.js, line 572

# Immovable

An immovable object cannot be displaced by another GameObject.

View Source lib.js, line 598

# Immovable

An immovable object cannot be displaced by another GameObject.

View Source lib.js, line 606

# 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, ...

View Source lib.js, line 638

# Life

Determines how many frames this GameObject will remain alive (before being removed automatically).

View Source lib.js, line 590

# Position

A p5.Vector (x, y) that represents the position of the current GameObject on the X and Y axis in pixels.

View Source lib.js, line 703

# Position

A p5.Vector (x, y) that represents the position of the current GameObject on the X and Y axis in pixels.

View Source lib.js, line 712

# Removed

Property to check if the GameObject was removed from the scene

View Source lib.js, line 556

# Speed

The speed of this GameObject, the same as the magnitude of the Velocity Vector.

View Source lib.js, line 695

# Velocity

A p5.Vector (x, y) representing the velocity of the GameObject on the X and Y axis.

View Source lib.js, line 678

# Velocity

A p5.Vector (x, y) representing the velocity of the GameObject on the X and Y axis.

View Source lib.js, line 686

# Width

The width of the GameObject on screen in pixels.

View Source lib.js, line 646

# Width

The width of the GameObject on screen in pixels.

View Source lib.js, line 654

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.

View Source lib.js, line 771

# 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).

View Source lib.js, line 814

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.

View Source lib.js, line 733

# Display()

Display gets called every frame, and prepares the GameObject to be drawn correctly. Do not call this directly, or override this!

View Source lib.js, line 849

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

View Source lib.js, line 743

# 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

View Source lib.js, line 825

# 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

View Source lib.js, line 807

# 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).

View Source lib.js, line 796

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.

View Source lib.js, line 830

# RemoveCollider()

Removes the currently set collider from the GameObject. If no collider was set before, this does nothing.

View Source lib.js, line 787

# SetDefaultCollider()

Creates a default collider based on the GameObject's width and height, and assigns it to the current GameObject.

View Source lib.js, line 780

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

View Source lib.js, line 760

# Update()

Update gets called every frame. Override this function to implement your own visualisations and/or frame-actions (input, movement, ...).

View Source lib.js, line 840