| Title: | An Interface to the 'Phaser.js' Game Framework |
|---|---|
| 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. |
| Authors: | Maciej Banas [aut, cre] |
| Maintainer: | Maciej Banas <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9022 |
| Built: | 2026-09-28 07:22:31 UTC |
| Source: | https://github.com/maciekbanas/shinyphaser |
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.
browser_actions(...)browser_actions(...)
... |
Supported shinyphaser browser action calls. |
A browser action specification.
Create and manage groups of sprites in the Phaser scene. Created with PhaserGame$add_group() method.
new()
Create a dynamic group in the Phaser scene.
Group$new(name, session = shiny::getDefaultReactiveDomain())
nameCharacter. Unique name of the group.
sessionShiny session object.
add_animation()
Add an animation that can be used by members of this group.
Group$add_animation( suffix, url, frame_width, frame_height, frame_count, frame_rate )
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.
create()
Create one group member at a coordinate.
Group$create(x, y)
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
show()
Show all current members of this group.
Group$show()
Invisible; sends a custom message to the client.
hide()
Hide all current members of this group.
Group$hide()
Invisible; sends a custom message to the client.
clone()
The objects of this class are cloneable with this method.
Group$clone(deep = FALSE)
deepWhether to make a deep clone.
Create and manage images in the Phaser scene. Created with PhaserGame$add_image() method.
new()
Add an image object to the Phaser scene.
Image$new( name, url, x, y, visible, clickable, session = getDefaultReactiveDomain() )
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.
show()
Show a previously added image.
Image$show()
hide()
Hide a previously added image.
Image$hide()
follow_camera()
Make the camera follow this image as it moves through the world.
Image$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
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).
stop_camera_follow()
Stop the camera from following this image.
Image$stop_camera_follow()
set_scroll_factor()
Set how much this image scrolls with the camera.
Image$set_scroll_factor(x, y = x)
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to x.
set_depth()
Set the image's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Image$set_depth(depth)
depthNumeric. Phaser rendering depth.
This image object, invisibly, to support method chaining.
click()
Add a click event listener to the image that triggers an R function when clicked.
Image$click(event_fun, input)
event_funA function.
inputShiny input object.
clone()
The objects of this class are cloneable with this method.
Image$clone(deep = FALSE)
deepWhether to make a deep clone.
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.
idCharacter. ID of the Game container. Used as the HTML element ID where the game canvas will be rendered.
new()
Create a PhaserGame object with the given configuration.
PhaserGame$new( id = "phaser_game", width = 800, height = 600, gravity_x = 0, gravity_y = 0 )
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).
A new PhaserGame object.
game <- PhaserGame$new(id = "my_game", width = 1024, height = 768)
set_shiny_session()
Set the Shiny session used to send Phaser custom messages.
PhaserGame$set_shiny_session(session = shiny::getDefaultReactiveDomain())
sessionShiny session object (default: shiny::getDefaultReactiveDomain()).
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.
PhaserGame$save_game( name, state = list(), objects = NULL, snapshot = NULL, directory = NULL )
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().
Invisible request identifier. The disk write completes asynchronously after Phaser returns its snapshot.
list_saved_games()
List saves stored on the server for this game.
PhaserGame$list_saved_games(directory = NULL)
directoryCharacter. Server-side save directory.
A list of saved game records, newest first.
load_game()
Load a saved game from server disk.
PhaserGame$load_game(name, restore = TRUE, directory = NULL)
nameCharacter. Save name.
restoreLogical. Restore captured Phaser object properties.
directoryCharacter. Server-side save directory.
The additional application state stored with the save, invisibly.
use_phaser()
Load dependencies and initialize the Phaser game in the UI.
PhaserGame$use_phaser()
HTML tag list containing dependencies and initialization script.
game$use_phaser()
add_text()
Add a text object to the Phaser scene.
PhaserGame$add_text( text, id, x, y, style = list(font_size = "22px"), visible = TRUE )
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.
add_rectangle()
Add a rectangle object to the Phaser scene.
PhaserGame$add_rectangle( name, x, y, width, height, color, visible = TRUE, clickable = FALSE )
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.
add_image()
Adds a static image to the Phaser scene.
PhaserGame$add_image(name, url, x, y, visible = TRUE, clickable = FALSE)
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).
add_sound()
Adds a sound to the Phaser scene.
PhaserGame$add_sound(name, url, volume = 1, loop = FALSE)
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).
add_state()
Create browser-resident state for use in browser actions.
PhaserGame$add_state(key, initial = NULL)
keyCharacter. Unique state key.
initialInitial JSON-serializable value.
add_cooldown()
Create a browser-resident cooldown for browser-action conditions.
PhaserGame$add_cooldown(key, duration)
keyCharacter. Unique cooldown key.
durationNumeric. Cooldown duration in milliseconds.
add_map()
Add a background (tilemap) layer from Tiled JSON + tileset image(s).
PhaserGame$add_map(map_key, map_url, tileset_urls, tileset_names, layer_name)
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.
Invisible; sends a custom message to the client.
activate_map()
Activate a tilemap previously loaded with add_map().
PhaserGame$activate_map( map_key, player_name = NULL, x = NULL, y = NULL, visible_objects = character(), hidden_objects = character() )
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.
Invisible; sends a custom message to the client.
add_proximity_trigger()
Add a trigger that monitors when a scene object is near a point.
PhaserGame$add_proximity_trigger( id, object_name, x, y, radius = 180, element_id = NULL, context = NULL, input_id = NULL )
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.
Invisible; sends a custom message to the client.
set_world_bounds()
Set the Phaser physics world and camera bounds.
PhaserGame$set_world_bounds(width, height)
widthNumeric. World width in pixels.
heightNumeric. World height in pixels.
Invisible; sends a custom message to the client.
enable_terrain_collision()
Enable terrain collision for a player sprite.
PhaserGame$enable_terrain_collision(name)
nameCharacter. Name of the player sprite (as added via add_player_sprite).
add_sprite()
Load a base spritesheet and create an "idle" animation.
PhaserGame$add_sprite( name, url, x, y, frame_width, frame_height, frame_count = 1, frame_rate = 1 )
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.
add_collision_rectangle()
Add an invisible static collision rectangle to the world.
PhaserGame$add_collision_rectangle(name, x, y, width, height)
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.
add_group()
Adds a dynamic group from a spritesheet.
PhaserGame$add_group(name)
nameCharacter. Unique name of the group.
add_static_sprite()
Adds a static sprite to the scene (non-animated).
PhaserGame$add_static_sprite(name, url, x, y)
nameCharacter. Unique name of the sprite.
urlCharacter. URL or path to the image file.
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
add_static_group()
Adds a static group to the scene (non-animated).
PhaserGame$add_static_group(name, url)
nameCharacter. Unique name of the group.
urlCharacter. URL or path to the image file.
add_collider()
Adds a collider between two game objects.
PhaserGame$add_collider( object_one, object_two = NULL, group = NULL, browser_action = browser_actions(), input = NULL, server_action = NULL )
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.
add_overlap()
Adds a collider between two game objects.
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
)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.
are_overlap()
Create a reactive expression for overlap state between two objects.
PhaserGame$are_overlap(object_one, object_two, input)
object_oneCharacter. Name of the first object.
object_twoCharacter. Name of the second object.
inputShiny input list.
add_overlap_end()
Register a callback fired when overlap between objects ends.
PhaserGame$add_overlap_end( object_one, object_two = NULL, group = NULL, browser_action = browser_actions(), input = NULL, server_action = NULL, session = shiny::getDefaultReactiveDomain() )
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.
add_control()
Register a callback fired when a specific key is pressed.
PhaserGame$add_control( key, browser_action = browser_actions(), input = NULL, server_action = NULL )
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.
clone()
The objects of this class are cloneable with this method.
PhaserGame$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------ ## Method `PhaserGame$new` ## ------------------------------------------------ game <- PhaserGame$new(id = "my_game", width = 1024, height = 768) ## ------------------------------------------------ ## Method `PhaserGame$use_phaser` ## ------------------------------------------------ game$use_phaser()## ------------------------------------------------ ## Method `PhaserGame$new` ## ------------------------------------------------ game <- PhaserGame$new(id = "my_game", width = 1024, height = 768) ## ------------------------------------------------ ## Method `PhaserGame$use_phaser` ## ------------------------------------------------ game$use_phaser()
Create and manage rectangles in the Phaser scene. Created with PhaserGame$add_rectangle() method.
new()
Add a rectangle object to the Phaser scene.
Rectangle$new( name, x, y, width, height, color, visible, clickable, session = getDefaultReactiveDomain() )
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.
show()
Show a previously added rectangle.
Rectangle$show()
hide()
Hide a previously added rectangle.
Rectangle$hide()
follow_camera()
Make the camera follow this rectangle as it moves through the world.
Rectangle$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
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).
stop_camera_follow()
Stop the camera from following this rectangle.
Rectangle$stop_camera_follow()
set_scroll_factor()
Set how much this rectangle scrolls with the camera.
Rectangle$set_scroll_factor(x, y = x)
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to x.
set_depth()
Set the rectangle's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Rectangle$set_depth(depth)
depthNumeric. Phaser rendering depth.
This rectangle object, invisibly, to support method chaining.
click()
Add a click event listener to the rectangle that triggers an R function when clicked.
Rectangle$click(event_fun, input)
event_funA function.
inputShiny input object.
clone()
The objects of this class are cloneable with this method.
Rectangle$clone(deep = FALSE)
deepWhether to make a deep clone.
Launches the sample Shiny application bundled with the package.
This is a quick way to see a working shinyphaser game setup.
run_sample_app()run_sample_app()
The value returned by shiny::runApp(). This function is normally
called for its side effect of starting the application.
Launches the modular Swamps RPG Shiny application bundled with shinyphaser.
run_swamps_rpg()run_swamps_rpg()
The value returned by shiny::runApp(). This function is normally
called for its side effect of starting the application.
Create and manage audio in the Phaser scene. Created with PhaserGame$add_sound() method.
new()
Load a sound file and register it with the Phaser scene.
Sound$new( name, url, volume = 1, loop = FALSE, session = shiny::getDefaultReactiveDomain() )
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.
play()
Play the sound.
Sound$play(volume = NULL, loop = NULL)
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.
pause()
Pause the sound.
Sound$pause()
resume()
Resume a paused sound.
Sound$resume()
stop()
Stop the sound.
Sound$stop()
set_volume()
Set the sound's volume.
Sound$set_volume(volume)
volumeNumeric. Volume from 0 to 1.
set_loop()
Set whether the sound loops by default.
Sound$set_loop(loop)
loopLogical. Whether playback should loop.
clone()
The objects of this class are cloneable with this method.
Sound$clone(deep = FALSE)
deepWhether to make a deep clone.
Create and manage animated sprites in the Phaser scene. Created with PhaserGame$add_sprite() method.
new()
Sprite$new( name, url, x, y, frame_width, frame_height, frame_count = NULL, frame_rate, session = getDefaultReactiveDomain() )
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.
add_animation()
Load a custom animation for any sprite previously added.
Sprite$add_animation( suffix, url, frame_width, frame_height, frame_count = NULL, frame_rate )
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.
Invisible; sends a custom message to the client.
play_animation()
Play a loaded animation for the sprite.
Sprite$play_animation(anim_name, duration = Inf)
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).
stop_motion()
Stop this sprite's current scripted movement.
Sprite$stop_motion()
Invisible; sends a custom message to the client.
show()
Show this sprite.
Sprite$show()
Invisible; sends a custom message to the client.
hide()
Hide this sprite.
Sprite$hide()
Invisible; sends a custom message to the client.
add_player_controls()
Enable movement controls (arrow keys) for a player sprite.
Sprite$add_player_controls(
directions = c("left", "right", "down", "up"),
speed = 200
)directionsCharacter vector. Directions to enable (defaults to c("left","right","down","up")).
speedNumeric. Movement speed in pixels/second (default: 200).
set_player_animation_prefix()
Choose the animation prefix used by player controls.
Sprite$set_player_animation_prefix(prefix)
prefixCharacter. Prefix for idle and directional movement animation keys.
Invisible; sends a custom message to the client.
follow_camera()
Make the camera follow this sprite as it moves through the world.
Sprite$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
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).
stop_camera_follow()
Stop the camera from following this sprite.
Sprite$stop_camera_follow()
set_scroll_factor()
Set how much this sprite scrolls with the camera.
Sprite$set_scroll_factor(x, y = x)
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to x.
set_depth()
Set the sprite's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Sprite$set_depth(depth)
depthNumeric. Phaser rendering depth.
This sprite object, invisibly, to support method chaining.
set_velocity_x()
Set the sprite's velocity in the x direction.
Sprite$set_velocity_x(x = 100)
xNumeric. Velocity in pixels/second (positive = right, negative = left).
set_velocity_y()
Set the sprite's velocity in the y direction.
Sprite$set_velocity_y(x = 100)
xNumeric. Velocity in pixels/second (positive = down, negative = up).
set_gravity()
Set the sprite's velocity in both x and y directions.
Sprite$set_gravity(x = 100, y = 100)
xNumeric. Velocity in pixels/second (positive = right, negative = left).
yNumeric. Velocity in pixels/second (positive = down, negative = up).
set_bounce()
Set the sprite's bounce factor.
Sprite$set_bounce(x)
xNumeric. Bounce factor.
destroy()
Remove sprite from the scene.
Sprite$destroy()
set_in_motion()
Move sprite along a vector for a set distance.
Sprite$set_in_motion(dir_x, dir_y, speed, distance, lag = distance/speed)
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).
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.
Sprite$start_approach_on_sight( target_name, sight_range, speed, distance, check_interval = 250, alert_duration = 1200, wander_interval = 1500 )
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.
clone()
The objects of this class are cloneable with this method.
Sprite$clone(deep = FALSE)
deepWhether to make a deep clone.
Create and manage groups of static sprites in the Phaser scene. Created with PhaserGame$add_static_group() method.
new()
Create a static group from a base image.
StaticGroup$new(name, url, session = shiny::getDefaultReactiveDomain())
nameCharacter. Unique name of the group.
urlCharacter. URL or path to image file.
sessionShiny session object.
create()
Create one static group member at a coordinate.
StaticGroup$create(x, y)
xNumeric. X-coordinate in pixels.
yNumeric. Y-coordinate in pixels.
show()
Show all current members of this static group.
StaticGroup$show()
Invisible; sends a custom message to the client.
hide()
Hide all current members of this static group.
StaticGroup$hide()
Invisible; sends a custom message to the client.
disable()
Disable a static group member body based on overlap event payload.
StaticGroup$disable(evt)
evtList-like event payload containing x2 and y2 values.
clone()
The objects of this class are cloneable with this method.
StaticGroup$clone(deep = FALSE)
deepWhether to make a deep clone.
Create and manage non-animated sprites in the Phaser scene. Created with PhaserGame$add_static_sprite() method.
new()
Add a non-animated static sprite to the scene.
StaticSprite$new(name, url, x, y, session = getDefaultReactiveDomain())
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.
destroy()
Remove static sprite from the scene.
StaticSprite$destroy()
show()
Show this static sprite.
StaticSprite$show()
Invisible; sends a custom message to the client.
hide()
Hide this static sprite.
StaticSprite$hide()
Invisible; sends a custom message to the client.
follow_camera()
Make the camera follow this static sprite as it moves through the world.
StaticSprite$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
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).
stop_camera_follow()
Stop the camera from following this static sprite.
StaticSprite$stop_camera_follow()
set_scroll_factor()
Set how much this static sprite scrolls with the camera.
StaticSprite$set_scroll_factor(x, y = x)
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to x.
set_depth()
Set the static sprite's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
StaticSprite$set_depth(depth)
depthNumeric. Phaser rendering depth.
This static sprite object, invisibly, to support method chaining.
clone()
The objects of this class are cloneable with this method.
StaticSprite$clone(deep = FALSE)
deepWhether to make a deep clone.
R6 class to represent a text object in the Phaser scene, allowing dynamic updates to its content. Created with PhaserGame$add_text() method.
new()
Create a text object in the Phaser scene.
Text$new( text, id, x, y, style, visible = TRUE, session = shiny::getDefaultReactiveDomain() )
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.
set()
Update the text content of this object.
Text$set(text)
textCharacter. New text value to display.
show()
Show a previously added text object.
Text$show()
hide()
Hide a previously added text object.
Text$hide()
follow_camera()
Make the camera follow this text object as it moves through the world.
Text$follow_camera(lerp_x = 1, lerp_y = 1, round_pixels = TRUE)
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).
stop_camera_follow()
Stop the camera from following this text object.
Text$stop_camera_follow()
set_scroll_factor()
Set how much this text object scrolls with the camera.
Text$set_scroll_factor(x, y = x)
xNumeric. Horizontal scroll factor (0 = fixed to viewport, 1 = scrolls with world).
yNumeric. Vertical scroll factor. Defaults to x.
set_depth()
Set the text object's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller depth.
Text$set_depth(depth)
depthNumeric. Phaser rendering depth.
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.
This text object, invisibly, to support method chaining.
\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)
}
clone()
The objects of this class are cloneable with this method.
Text$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------ ## 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)## ------------------------------------------------ ## 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)