Constructor
new Character()
Creates a new Character instance and initializes its base image.
Loads all animation sequences for different character states.
- Source:
Members
IMAGES_DYING :Array.<string>
Image sequence for death animation.
Type:
- Array.<string>
- Source:
IMAGES_HURT :Array.<string>
Image sequence for hurt animation.
Type:
- Array.<string>
- Source:
IMAGES_IDLE :Array.<string>
Image sequence for normal idle animation.
Type:
- Array.<string>
- Source:
IMAGES_JUMPING :Array.<string>
Image sequence for jumping animation.
Type:
- Array.<string>
- Source:
IMAGES_LONG_IDLE :Array.<string>
Image sequence for extended idle (long idle) animation.
Type:
- Array.<string>
- Source:
IMAGES_WALKING :Array.<string>
Image sequence for walking animation.
Type:
- Array.<string>
- Source:
acceleration :number
Vertical acceleration applied to the character (simulates gravity).
Type:
- number
- Source:
damage :number
The amount of damage the character can deal to enemies.
Type:
- number
- Source:
frameDelay :Object
Frame delay settings for various animation states.
Higher values result in slower animations for that state.
Type:
- Object
- Source:
health :number
The current health of the character (0–100).
Type:
- number
- Source:
height :number
The height of the character in pixels.
Type:
- number
- Source:
lastY :number
Vertical position from the previous frame.
Used for vertical movement smoothing or animation syncing.
Type:
- number
- Source:
lastY2 :number
Vertical position from two frames ago.
Supports smoother vertical transitions.
Type:
- number
- Source:
lastY3 :number
Vertical position from three frames ago.
Used for motion tracking across multiple frames.
Type:
- number
- Source:
offset :Object
Defines the collision hitbox offset for the character.
Useful for adjusting the bounding box relative to the image size.
Type:
- Object
- Source:
speed :number
Horizontal movement speed of the character.
Type:
- number
- Source:
speedY :number
Vertical movement speed (positive = falling, negative = jumping).
Type:
- number
- Source:
width :number
The width of the character in pixels.
Type:
- number
- Source:
world :World
Reference to the game world the character is part of.
Set when the character is added to a World instance.
Type:
- Source:
x :number
The horizontal position of the character.
Type:
- number
- Source:
y :number
The current vertical position of the character.
Type:
- number
- Source:
Methods
initCharacterLoops()
Initializes the character's core gameplay loops and physics.
Sets up gravity, horizontal movement, and animation cycles.
Should be called after the character is fully constructed and world is set.
- Source:
setWorld(world)
Assigns the world instance to the character.
Required for interactions with the game environment (e.g. camera, state logic).
Parameters:
Name | Type | Description |
---|---|---|
world |
World | The world object the character belongs to. |
- Source: