| Title: | An Interface to the 'Phaser.js' Game Framework |
| Version: | 0.2.0 |
| Description: | An API to build and control 2D games using the 'Phaser' 'JavaScript' engine. It enables integration with 'shiny' applications, allowing to create interactive games and simulations. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| URL: | https://github.com/maciekbanas/shinyphaser, https://maciekbanas.github.io/shinyphaser/ |
| BugReports: | https://github.com/maciekbanas/shinyphaser/issues |
| Imports: | htmltools, jsonlite, R6, rlang, shiny |
| Suggests: | knitr, later, rmarkdown, shinyalert, testthat (≥ 3.0.0), shinytest2 (≥ 0.5.1), withr |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-22 21:59:01 UTC; banas |
| Author: | Maciej Banas [aut, cre] |
| Maintainer: | Maciej Banas <banasmaciek@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-22 22:30:02 UTC |
Group
Description
Create and manage groups of sprites in the Phaser scene. Created with PhaserGame$add_group() method.
Methods
Public methods
Method new()
Create a dynamic group in the Phaser scene.
Usage
Group$new(name, session = shiny::getDefaultReactiveDomain())
Arguments
nameCharacter. Unique name of the group.
sessionShiny session object.
Method add_animation()
Add an animation that can be used by members of this group.
Usage
Group$add_animation( suffix, url, frame_width, frame_height, frame_count, frame_rate )
Arguments
suffixCharacter. Animation suffix/key.
urlCharacter. URL or path to spritesheet.
frame_widthNumeric. Width of each frame.
frame_heightNumeric. Height of each frame.
frame_countNumeric. Number of frames.
frame_rateNumeric. Frames per second.
Method create()
Create one group member at a coordinate.
Usage
Group$create(x, y)
Arguments
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
Method show()
Show all current members of this group.
Usage
Group$show()
Returns
Invisible; sends a custom message to the client.
Method hide()
Hide all current members of this group.
Usage
Group$hide()
Returns
Invisible; sends a custom message to the client.
Method clone()
The objects of this class are cloneable with this method.
Usage
Group$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Image
Description
Create and manage images in the Phaser scene. Created with PhaserGame$add_image() method.
Methods
Public methods
Method new()
Add an image object to the Phaser scene.
Usage
Image$new( name, url, x, y, visible, clickable, session = getDefaultReactiveDomain() )
Arguments
nameCharacter. Unique name of the image.
urlCharacter. URL or path to image file.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
visibleLogical. Whether image is initially visible.
clickableLogical. Whether image emits click events.
sessionShiny session object.
Method show()
Show a previously added image.
Usage
Image$show()
Method hide()
Hide a previously added image.
Usage
Image$hide()
Method follow_camera()
Make the camera follow this image as it moves through the world.
Usage
Image$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
Arguments
lerp_xNumeric. Horizontal interpolation factor from 0 to 1 (default: 1).
lerp_yNumeric. Vertical interpolation factor from 0 to 1 (default: 1).
round_pixelsLogical. Whether to round camera pixels to avoid sub-pixel rendering (default: TRUE).
Method stop_camera_follow()
Stop the camera from following this image.
Usage
Image$stop_camera_follow()
Method set_scroll_factor()
Set how much this image scrolls with the camera.
Usage
Image$set_scroll_factor(x, y = x)
Arguments
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to
x.
Method set_depth()
Set the image's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Usage
Image$set_depth(depth)
Arguments
depthNumeric. Phaser rendering depth.
Returns
This image object, invisibly, to support method chaining.
Method click()
Add a click event listener to the image that triggers an R function when clicked.
Usage
Image$click(event_fun, input)
Arguments
event_funA function.
inputShiny input object.
Method clone()
The objects of this class are cloneable with this method.
Usage
Image$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
PhaserGame
Description
R6 class to create and manage a Phaser game within a Shiny application. Provides methods for adding sprites, animations, images, sounds, backgrounds, controls, and collision handling.
Public fields
idCharacter. ID of the Game container. Used as the HTML element ID where the game canvas will be rendered.
Methods
Public methods
Method new()
Create a PhaserGame object with the given configuration.
Usage
PhaserGame$new( id = "phaser_game", width = 800, height = 600, gravity_x = 0, gravity_y = 0 )
Arguments
idCharacter. ID of the Game container (defaults to "phaser_game").
widthNumeric. Width of the Phaser canvas in pixels (defaults to 800).
heightNumeric. Height of the Phaser canvas in pixels (defaults to 600).
gravity_xNumeric. Horizontal Arcade Physics world gravity (defaults to 0).
gravity_yNumeric. Vertical Arcade Physics world gravity (defaults to 0).
Returns
A new PhaserGame object.
Examples
game <- PhaserGame$new(id = "my_game", width = 1024, height = 768)
Method set_shiny_session()
Set the Shiny session used to send Phaser custom messages.
Usage
PhaserGame$set_shiny_session(session = shiny::getDefaultReactiveDomain())
Arguments
sessionShiny session object (default: shiny::getDefaultReactiveDomain()).
Method save_game()
Save game data and Phaser object state to a JSON file on the server. Positions are read directly from Phaser immediately before the save request, avoiding stale Shiny coordinates.
Usage
PhaserGame$save_game( name, state = list(), objects = NULL, snapshot = NULL, directory = NULL )
Arguments
nameCharacter. Human-readable name of the save.
stateNamed list. Additional JSON-serializable application state.
objectsCharacter vector. Named Phaser scene objects to capture. By default all named scene objects are captured.
snapshotNamed list. Optional Phaser object snapshot already captured in the browser. Supplying it writes the save synchronously.
directoryCharacter. Server-side directory. Defaults to a game-specific folder below
tempdir().
Returns
Invisible request identifier. The disk write completes asynchronously after Phaser returns its snapshot.
Method list_saved_games()
List saves stored on the server for this game.
Usage
PhaserGame$list_saved_games(directory = NULL)
Arguments
directoryCharacter. Server-side save directory.
Returns
A list of saved game records, newest first.
Method load_game()
Load a saved game from server disk.
Usage
PhaserGame$load_game(name, restore = TRUE, directory = NULL)
Arguments
nameCharacter. Save name.
restoreLogical. Restore captured Phaser object properties.
directoryCharacter. Server-side save directory.
Returns
The additional application state stored with the save, invisibly.
Method use_phaser()
Load dependencies and initialize the Phaser game in the UI.
Usage
PhaserGame$use_phaser()
Returns
HTML tag list containing dependencies and initialization script.
Examples
game$use_phaser()
Method add_text()
Add a text object to the Phaser scene.
Usage
PhaserGame$add_text( text, id, x, y, style = list(font_size = "22px"), visible = TRUE )
Arguments
textCharacter. Text value to display.
idCharacter. Unique ID for the text object.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
styleNamed list. Styling options passed to Phaser text rendering.
visibleLogical. Whether text is initially visible.
Method add_rectangle()
Add a rectangle object to the Phaser scene.
Usage
PhaserGame$add_rectangle( name, x, y, width, height, color, visible = TRUE, clickable = FALSE )
Arguments
nameCharacter. Unique name for the rectangle.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
widthNumeric. Rectangle width in pixels.
heightNumeric. Rectangle height in pixels.
colorCharacter. Fill color in Phaser-compatible format.
visibleLogical. Whether rectangle is initially visible.
clickableLogical. Whether rectangle emits click events.
Method add_image()
Adds a static image to the Phaser scene.
Usage
PhaserGame$add_image(name, url, x, y, visible = TRUE, clickable = FALSE)
Arguments
nameCharacter. Unique key to reference this image.
urlCharacter. URL or path to the image file.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
visibleLogical. Whether the image is initially visible (default: TRUE).
clickableLogical. Whether the image should emit click events (default: FALSE).
Method add_sound()
Adds a sound to the Phaser scene.
Usage
PhaserGame$add_sound(name, url, volume = 1, loop = FALSE)
Arguments
nameCharacter. Unique key to reference this sound.
urlCharacter. URL or path to the audio file.
volumeNumeric. Initial playback volume from 0 to 1 (default: 1).
loopLogical. Whether the sound should loop by default (default: FALSE).
Method add_state()
Create browser-resident state for use in browser actions.
Usage
PhaserGame$add_state(key, initial = NULL)
Arguments
keyCharacter. Unique state key.
initialInitial JSON-serializable value.
Method add_cooldown()
Create a browser-resident cooldown for browser-action conditions.
Usage
PhaserGame$add_cooldown(key, duration)
Arguments
keyCharacter. Unique cooldown key.
durationNumeric. Cooldown duration in milliseconds.
Method add_map()
Add a background (tilemap) layer from Tiled JSON + tileset image(s).
Usage
PhaserGame$add_map(map_key, map_url, tileset_urls, tileset_names, layer_name)
Arguments
map_keyCharacter. Key for the tilemap JSON.
map_urlCharacter. URL of the Tiled JSON file (relative to www/assets/).
tileset_urlsCharacter vector. URLs of tileset image files.
tileset_namesCharacter vector. Names of tilesets as defined in Tiled.
layer_nameCharacter. Name of the layer to render from Tiled.
Returns
Invisible; sends a custom message to the client.
Method activate_map()
Activate a tilemap previously loaded with add_map().
Usage
PhaserGame$activate_map( map_key, player_name = NULL, x = NULL, y = NULL, visible_objects = character(), hidden_objects = character() )
Arguments
map_keyCharacter. Key of the tilemap to activate.
player_nameCharacter. Optional player sprite to reposition.
xNumeric. Optional player x-coordinate.
yNumeric. Optional player y-coordinate.
visible_objectsCharacter vector. Scene objects to show and enable.
hidden_objectsCharacter vector. Scene objects to hide and disable.
Returns
Invisible; sends a custom message to the client.
Method add_proximity_trigger()
Add a trigger that monitors when a scene object is near a point.
Usage
PhaserGame$add_proximity_trigger( id, object_name, x, y, radius = 180, element_id = NULL, context = NULL, input_id = NULL )
Arguments
idCharacter. Unique trigger identifier.
object_nameCharacter. Scene object whose position is monitored.
xNumeric. Target x-coordinate.
yNumeric. Target y-coordinate.
radiusNumeric. Maximum distance at which the trigger is active.
element_idCharacter or
NULL. ID of an HTML element to show while the trigger is active.contextCharacter or
NULL. Optional map key that must be active for the trigger to be evaluated.input_idCharacter or
NULL. Optional Shiny input that receives a payload whenever the trigger is entered or exited.
Returns
Invisible; sends a custom message to the client.
Method set_world_bounds()
Set the Phaser physics world and camera bounds.
Usage
PhaserGame$set_world_bounds(width, height)
Arguments
widthNumeric. World width in pixels.
heightNumeric. World height in pixels.
Returns
Invisible; sends a custom message to the client.
Method enable_terrain_collision()
Enable terrain collision for a player sprite.
Usage
PhaserGame$enable_terrain_collision(name)
Arguments
nameCharacter. Name of the player sprite (as added via add_player_sprite).
Method add_sprite()
Load a base spritesheet and create an "idle" animation.
Usage
PhaserGame$add_sprite( name, url, x, y, frame_width, frame_height, frame_count = 1, frame_rate = 1 )
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.
frame_rateNumeric. Frames per second for the idle animation.
Method add_collision_rectangle()
Add an invisible static collision rectangle to the world.
Usage
PhaserGame$add_collision_rectangle(name, x, y, width, height)
Arguments
nameCharacter. Unique name of the collision rectangle.
xNumeric. X-coordinate of its center.
yNumeric. Y-coordinate of its center.
widthNumeric. Collision width in pixels.
heightNumeric. Collision height in pixels.
Method add_group()
Adds a dynamic group from a spritesheet.
Usage
PhaserGame$add_group(name)
Arguments
nameCharacter. Unique name of the group.
Method add_static_sprite()
Adds a static sprite to the scene (non-animated).
Usage
PhaserGame$add_static_sprite(name, url, x, y)
Arguments
nameCharacter. Unique name of the sprite.
urlCharacter. URL or path to the image file.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
Method add_static_group()
Adds a static group to the scene (non-animated).
Usage
PhaserGame$add_static_group(name, url)
Arguments
nameCharacter. Unique name of the group.
urlCharacter. URL or path to the image file.
Method add_collider()
Adds a collider between two game objects.
Usage
PhaserGame$add_collider( object_one, object_two = NULL, group = NULL, browser_action = browser_actions(), input = NULL, server_action = NULL )
Arguments
object_oneCharacter. Name of the first object.
object_twoCharacter. Name of the second object.
groupCharacter. Name of the group to compare against.
browser_actionActions created with
browser_actions()that run immediately in the browser.inputShiny input list.
server_actionFunction called in R with the collision event.
Method add_overlap()
Adds a collider between two game objects.
Usage
PhaserGame$add_overlap(
object_one,
object_two = NULL,
group = NULL,
browser_action = browser_actions(),
input = NULL,
server_action = NULL,
mode = c("enter", "stay"),
interval = 0
)Arguments
object_oneCharacter. Name of the first object.
object_twoCharacter. Name of the second object.
groupCharacter. Name of the group.
browser_actionActions created with
browser_actions()that run immediately in the browser.inputShiny input list.
server_actionFunction called in R with the overlap event.
modeCharacter.
"enter"(default) runs once per contact;"stay"repeats while overlapping.intervalNumeric. Minimum milliseconds between
"stay"actions.
Method are_overlap()
Create a reactive expression for overlap state between two objects.
Usage
PhaserGame$are_overlap(object_one, object_two, input)
Arguments
object_oneCharacter. Name of the first object.
object_twoCharacter. Name of the second object.
inputShiny input list.
Method add_overlap_end()
Register a callback fired when overlap between objects ends.
Usage
PhaserGame$add_overlap_end( object_one, object_two = NULL, group = NULL, browser_action = browser_actions(), input = NULL, server_action = NULL, session = shiny::getDefaultReactiveDomain() )
Arguments
object_oneCharacter. Name of the first object.
object_twoCharacter. Name of the second object.
groupCharacter. Name of the group to compare against.
browser_actionActions created with
browser_actions()that run immediately in the browser.inputShiny input list.
server_actionFunction called in R with the overlap-end event.
sessionShiny session object.
Method add_control()
Register a callback fired when a specific key is pressed.
Usage
PhaserGame$add_control( key, browser_action = browser_actions(), input = NULL, server_action = NULL )
Arguments
keyA character, accepts Javascript key events (they need to align with event.code).
browser_actionActions created with
browser_actions()that run immediately in the browser.inputShiny input list.
server_actionFunction called in R with the keyboard event.
Method clone()
The objects of this class are cloneable with this method.
Usage
PhaserGame$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
## ------------------------------------------------
## Method `PhaserGame$new`
## ------------------------------------------------
game <- PhaserGame$new(id = "my_game", width = 1024, height = 768)
## ------------------------------------------------
## Method `PhaserGame$use_phaser`
## ------------------------------------------------
game$use_phaser()
Rectangle
Description
Create and manage rectangles in the Phaser scene. Created with PhaserGame$add_rectangle() method.
Methods
Public methods
Method new()
Add a rectangle object to the Phaser scene.
Usage
Rectangle$new( name, x, y, width, height, color, visible, clickable, session = getDefaultReactiveDomain() )
Arguments
nameCharacter. Unique name of the rectangle.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
widthNumeric. Rectangle width in pixels.
heightNumeric. Rectangle height in pixels.
colorCharacter. Fill color in Phaser-compatible format.
visibleLogical. Whether rectangle is initially visible.
clickableLogical. Whether rectangle emits click events.
sessionShiny session object.
Method show()
Show a previously added rectangle.
Usage
Rectangle$show()
Method hide()
Hide a previously added rectangle.
Usage
Rectangle$hide()
Method follow_camera()
Make the camera follow this rectangle as it moves through the world.
Usage
Rectangle$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
Arguments
lerp_xNumeric. Horizontal interpolation factor from 0 to 1 (default: 1).
lerp_yNumeric. Vertical interpolation factor from 0 to 1 (default: 1).
round_pixelsLogical. Whether to round camera pixels to avoid sub-pixel rendering (default: TRUE).
Method stop_camera_follow()
Stop the camera from following this rectangle.
Usage
Rectangle$stop_camera_follow()
Method set_scroll_factor()
Set how much this rectangle scrolls with the camera.
Usage
Rectangle$set_scroll_factor(x, y = x)
Arguments
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to
x.
Method set_depth()
Set the rectangle's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Usage
Rectangle$set_depth(depth)
Arguments
depthNumeric. Phaser rendering depth.
Returns
This rectangle object, invisibly, to support method chaining.
Method click()
Add a click event listener to the rectangle that triggers an R function when clicked.
Usage
Rectangle$click(event_fun, input)
Arguments
event_funA function.
inputShiny input object.
Method clone()
The objects of this class are cloneable with this method.
Usage
Rectangle$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Sound
Description
Create and manage audio in the Phaser scene. Created with PhaserGame$add_sound() method.
Methods
Public methods
Method new()
Load a sound file and register it with the Phaser scene.
Usage
Sound$new( name, url, volume = 1, loop = FALSE, session = shiny::getDefaultReactiveDomain() )
Arguments
nameCharacter. Unique key for the sound.
urlCharacter. URL or path to the audio file.
volumeNumeric. Initial playback volume from 0 to 1 (default: 1).
loopLogical. Whether the sound should loop by default (default: FALSE).
sessionShiny session object.
Method play()
Play the sound.
Usage
Sound$play(volume = NULL, loop = NULL)
Arguments
volumeNumeric. Optional playback volume from 0 to 1. Defaults to the sound's current/default volume.
loopLogical. Optional loop setting for this playback. Defaults to the sound's current/default loop setting.
Method pause()
Pause the sound.
Usage
Sound$pause()
Method resume()
Resume a paused sound.
Usage
Sound$resume()
Method stop()
Stop the sound.
Usage
Sound$stop()
Method set_volume()
Set the sound's volume.
Usage
Sound$set_volume(volume)
Arguments
volumeNumeric. Volume from 0 to 1.
Method set_loop()
Set whether the sound loops by default.
Usage
Sound$set_loop(loop)
Arguments
loopLogical. Whether playback should loop.
Method clone()
The objects of this class are cloneable with this method.
Usage
Sound$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Sprite
Description
Create and manage animated sprites in the Phaser scene. Created with PhaserGame$add_sprite() method.
Methods
Public 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.
Returns
Invisible; sends a custom message to the client.
Method play_animation()
Play a loaded animation for the sprite.
Usage
Sprite$play_animation(anim_name, duration = Inf)
Arguments
anim_nameCharacter. Identifier for the animation to play (e.g. " move_left").
durationNumeric. Optional duration in milliseconds to play the animation before reverting to idle (defaults to Inf, which loops indefinitely until another animation is played).
Method stop_motion()
Stop this sprite's current scripted movement.
Usage
Sprite$stop_motion()
Returns
Invisible; sends a custom message to the client.
Method show()
Show this sprite.
Usage
Sprite$show()
Returns
Invisible; sends a custom message to the client.
Method hide()
Hide this sprite.
Usage
Sprite$hide()
Returns
Invisible; sends a custom message to the client.
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
)Arguments
directionsCharacter vector. Directions to enable (defaults to c("left","right","down","up")).
speedNumeric. Movement speed in pixels/second (default: 200).
Method set_player_animation_prefix()
Choose the animation prefix used by player controls.
Usage
Sprite$set_player_animation_prefix(prefix)
Arguments
prefixCharacter. Prefix for idle and directional movement animation keys.
Returns
Invisible; sends a custom message to the client.
Method follow_camera()
Make the camera follow this sprite as it moves through the world.
Usage
Sprite$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
Arguments
lerp_xNumeric. Horizontal interpolation factor from 0 to 1 (default: 1).
lerp_yNumeric. Vertical interpolation factor from 0 to 1 (default: 1).
round_pixelsLogical. Whether to round camera pixels to avoid sub-pixel rendering (default: TRUE).
Method stop_camera_follow()
Stop the camera from following this sprite.
Usage
Sprite$stop_camera_follow()
Method set_scroll_factor()
Set how much this sprite scrolls with the camera.
Usage
Sprite$set_scroll_factor(x, y = x)
Arguments
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to
x.
Method set_depth()
Set the sprite's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Usage
Sprite$set_depth(depth)
Arguments
depthNumeric. Phaser rendering depth.
Returns
This sprite object, invisibly, to support method chaining.
Method set_body_size()
Set a collision body size and its offset within the unscaled sprite frame. Calls made before the sprite loads are queued.
Usage
Sprite$set_body_size(width, height, offset_x = 0, offset_y = 0)
Arguments
width, heightPositive numeric. Body size in frame pixels.
offset_x, offset_yNumeric. Offset from the frame's top-left corner.
Returns
This sprite, invisibly.
Method set_depth_by_y()
Continuously set drawing depth to the sprite's y-coordinate plus an offset, in the browser. Disable to retain the current depth; set_depth() also disables automatic depth sorting.
Usage
Sprite$set_depth_by_y(offset = 0, enabled = TRUE)
Arguments
offsetNumeric. Vertical distance from the sprite origin to its ground point, in world pixels (40 for the example's centered Orc).
enabledLogical. Whether to update depth each frame.
Returns
This sprite, invisibly.
Method set_velocity_x()
Set the sprite's velocity in the x direction.
Usage
Sprite$set_velocity_x(x = 100)
Arguments
xNumeric. Velocity in pixels/second (positive = right, negative = left).
Method set_velocity_y()
Set the sprite's velocity in the y direction.
Usage
Sprite$set_velocity_y(x = 100)
Arguments
xNumeric. Velocity in pixels/second (positive = down, negative = up).
Method set_gravity()
Set the sprite's velocity in both x and y directions.
Usage
Sprite$set_gravity(x = 100, y = 100)
Arguments
xNumeric. Velocity in pixels/second (positive = right, negative = left).
yNumeric. Velocity in pixels/second (positive = down, negative = up).
Method set_bounce()
Set the sprite's bounce factor.
Usage
Sprite$set_bounce(x)
Arguments
xNumeric. Bounce factor.
Method destroy()
Remove sprite from the scene.
Usage
Sprite$destroy()
Method set_in_motion()
Move sprite along a vector for a set distance.
Usage
Sprite$set_in_motion(dir_x, dir_y, speed, distance, lag = distance/speed)
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.
Method clone()
The objects of this class are cloneable with this method.
Usage
Sprite$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Static Group
Description
Create and manage groups of static sprites in the Phaser scene. Created with PhaserGame$add_static_group() method.
Methods
Public methods
Method new()
Create a static group from a base image.
Usage
StaticGroup$new(name, url, session = shiny::getDefaultReactiveDomain())
Arguments
nameCharacter. Unique name of the group.
urlCharacter. URL or path to image file.
sessionShiny session object.
Method create()
Create one static group member at a coordinate.
Usage
StaticGroup$create(x, y)
Arguments
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
Method show()
Show all current members of this static group.
Usage
StaticGroup$show()
Returns
Invisible; sends a custom message to the client.
Method hide()
Hide all current members of this static group.
Usage
StaticGroup$hide()
Returns
Invisible; sends a custom message to the client.
Method disable()
Disable a static group member body based on overlap event payload.
Usage
StaticGroup$disable(evt)
Arguments
evtList-like event payload containing x2 and y2 values.
Method clone()
The objects of this class are cloneable with this method.
Usage
StaticGroup$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Static Sprite
Description
Create and manage non-animated sprites in the Phaser scene. Created with PhaserGame$add_static_sprite() method.
Methods
Public methods
Method new()
Add a non-animated static sprite to the scene.
Usage
StaticSprite$new(name, url, x, y, session = getDefaultReactiveDomain())
Arguments
nameCharacter. Unique name of the sprite.
urlCharacter. URL or path to image file.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
sessionShiny session object.
Method destroy()
Remove static sprite from the scene.
Usage
StaticSprite$destroy()
Method show()
Show this static sprite.
Usage
StaticSprite$show()
Returns
Invisible; sends a custom message to the client.
Method hide()
Hide this static sprite.
Usage
StaticSprite$hide()
Returns
Invisible; sends a custom message to the client.
Method follow_camera()
Make the camera follow this static sprite as it moves through the world.
Usage
StaticSprite$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
Arguments
lerp_xNumeric. Horizontal interpolation factor from 0 to 1 (default: 1).
lerp_yNumeric. Vertical interpolation factor from 0 to 1 (default: 1).
round_pixelsLogical. Whether to round camera pixels to avoid sub-pixel rendering (default: TRUE).
Method stop_camera_follow()
Stop the camera from following this static sprite.
Usage
StaticSprite$stop_camera_follow()
Method set_scroll_factor()
Set how much this static sprite scrolls with the camera.
Usage
StaticSprite$set_scroll_factor(x, y = x)
Arguments
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to
x.
Method set_depth()
Set the static sprite's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Usage
StaticSprite$set_depth(depth)
Arguments
depthNumeric. Phaser rendering depth.
Returns
This static sprite object, invisibly, to support method chaining.
Method clone()
The objects of this class are cloneable with this method.
Usage
StaticSprite$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Text
Description
R6 class to represent a text object in the Phaser scene, allowing dynamic updates to its content. Created with PhaserGame$add_text() method.
Methods
Public methods
Method new()
Create a text object in the Phaser scene.
Usage
Text$new( text, id, x, y, style, visible = TRUE, session = shiny::getDefaultReactiveDomain() )
Arguments
textCharacter. Text value to display.
idCharacter. Unique ID for the text object.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
styleNamed list. Styling options passed to Phaser text rendering.
visibleLogical. Whether text is initially visible.
sessionShiny session object.
Method set()
Update the text content of this object.
Usage
Text$set(text)
Arguments
textCharacter. New text value to display.
Method show()
Show a previously added text object.
Usage
Text$show()
Method hide()
Hide a previously added text object.
Usage
Text$hide()
Method follow_camera()
Make the camera follow this text object as it moves through the world.
Usage
Text$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
Arguments
lerp_xNumeric. Horizontal interpolation factor from 0 to 1 (default: 1).
lerp_yNumeric. Vertical interpolation factor from 0 to 1 (default: 1).
round_pixelsLogical. Whether to round camera pixels to avoid sub-pixel rendering (default: TRUE).
Method stop_camera_follow()
Stop the camera from following this text object.
Usage
Text$stop_camera_follow()
Method set_scroll_factor()
Set how much this text object scrolls with the camera.
Usage
Text$set_scroll_factor(x, y = x)
Arguments
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to
x.
Method set_depth()
Set the text object's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Usage
Text$set_depth(depth)
Arguments
depthNumeric. Phaser rendering depth.
Details
Every individually renderable object wrapper supports
set_depth(). Larger values draw in front of smaller values. The
method invisibly returns its object, so it can be chained with other
object methods.
Returns
This text object, invisibly, to support method chaining.
Examples
\dontrun{
background <- game$add_image(
"background", "assets/background.png", x = 400, y = 300
)
background$set_depth(-10)
control <- game$add_rectangle(
"jump_control", x = 720, y = 540, width = 120, height = 48,
color = "0x223344"
)
control$set_depth(50)$set_scroll_factor(0)
label <- game$add_text("Jump", "jump_label", x = 690, y = 528)
label$set_depth(51)$set_scroll_factor(0)
}
Method clone()
The objects of this class are cloneable with this method.
Usage
Text$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
## ------------------------------------------------
## Method `Text$set_depth`
## ------------------------------------------------
## Not run:
background <- game$add_image(
"background", "assets/background.png", x = 400, y = 300
)
background$set_depth(-10)
control <- game$add_rectangle(
"jump_control", x = 720, y = 540, width = 120, height = 48,
color = "0x223344"
)
control$set_depth(50)$set_scroll_factor(0)
label <- game$add_text("Jump", "jump_label", x = 690, y = 528)
label$set_depth(51)$set_scroll_factor(0)
## End(Not run)
Define actions that run immediately in the browser
Description
Captures supported shinyphaser method calls without evaluating them in R.
Browser actions are compiled when passed to an event registration method.
Arbitrary R code belongs in the corresponding server_action function.
Usage
browser_actions(...)
Arguments
... |
Supported shinyphaser browser action calls. |
Value
A browser action specification.