Create and manage animated sprites in the Phaser scene. Created with PhaserGame$add_sprite() method.
Methods
Method new()
Usage
Sprite$new(
name,
url,
x,
y,
frame_width,
frame_height,
frame_count = NULL,
frame_rate,
session = getDefaultReactiveDomain()
)Arguments
nameCharacter. Unique key for the sprite and its idle animation.
urlCharacter. URL or path to the spritesheet image.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
frame_widthNumeric. Width of each frame.
frame_heightNumeric. Height of each frame.
frame_countNumeric. Number of frames in the spritesheet. If NULL, auto-detect from spritesheet dimensions.
frame_rateNumeric. Frames per second for the idle animation.
sessionShiny session object.
Method add_animation()
Load a custom animation for any sprite previously added.
Usage
Sprite$add_animation(
suffix,
url,
frame_width,
frame_height,
frame_count = NULL,
frame_rate
)Arguments
suffixCharacter. Identifier for this animation (e.g. "move_left").
urlCharacter. URL or path to the spritesheet.
frame_widthNumeric. Width of each frame.
frame_heightNumeric. Height of each frame.
frame_countNumeric. Number of frames in the spritesheet. If NULL, auto-detect from spritesheet dimensions.
frame_rateNumeric. Frames per second for playback.
Method add_player_controls()
Enable movement controls (arrow keys) for a player sprite.
Usage
Sprite$add_player_controls(
directions = c("left", "right", "down", "up"),
speed = 200
)Method set_depth()
Set the sprite's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Method set_in_motion()
Move sprite along a vector for a set distance.
Arguments
dir_xNumeric. Horizontal direction (-1 = left, +1 = right, 0 = none).
dir_yNumeric. Vertical direction (-1 = up, +1 = down, 0 = none).
speedNumeric. Speed in pixels/second.
distanceNumeric. Distance in pixels to travel before stopping.
lagNumeric. Optional delay before sending the command (defaults to distance/speed).
Method start_approach_on_sight()
Start client-side sight checks that make this sprite alert, wander while the target is out of range, and approach the target when it is in range. This is a reusable browser-side behaviour rather than an RPG-specific rule.
Usage
Sprite$start_approach_on_sight(
target_name,
sight_range,
speed,
distance,
check_interval = 250,
alert_duration = 1200,
wander_interval = 1500
)Arguments
target_nameCharacter. Name of the target sprite to approach.
sight_rangeNumeric. Maximum distance in pixels at which the target is noticed.
speedNumeric. Approach speed in pixels/second.
distanceNumeric. Distance in pixels to travel for each approach step.
check_intervalNumeric. Milliseconds between sight checks.
alert_durationNumeric. Milliseconds to show the alert while approaching.
wander_intervalNumeric. Milliseconds between random movements while the target is out of sight.