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