R6 class to represent a text object in the Phaser scene, allowing dynamic updates to its content. Created with PhaserGame$add_text() method.
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_depth()
Set the text object's rendering depth. Objects with a larger depth are rendered in front of objects with a smaller 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.
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)
}
Examples
## ------------------------------------------------
## Method `Text$set_depth`
## ------------------------------------------------
if (FALSE) { # \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)
} # }