Skip to content

Instantly share code, notes, and snippets.

@rahji
Created November 13, 2023 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahji/b48592747e1e3c6c0c895f146e3ecd8f to your computer and use it in GitHub Desktop.
Save rahji/b48592747e1e3c6c0c895f146e3ecd8f to your computer and use it in GitHub Desktop.
A way to show text in p5play
// how to show text and not have it appear
// underneath the game's sprites
let spriteToClick;
let textSpriteToShow;
function setup() {
let canvas = new Canvas("fullscreen");
spriteToClick = new Sprite(width/2,height/2,128,128,'s');
textSize(128);
// make the sprite SUPER tiny
// so that the original spriteToClick can still
// be clicked, even when the textSpriteToShow
// appears on top of it
textSpriteToShow = new Sprite(width/2,height/2,2,2,'s');
// luckily, the text shows big (128 px) no matter
// the size of the sprite
textSpriteToShow.text = "testing";
textSpriteToShow.visible = false; // <- until clicked
// make the sprite invisible, other than the text...
textSpriteToShow.strokeWeight = 0;
textSpriteToShow.fill = color(0,0);
}
function draw() {
clear();
if (spriteToClick.mouse.pressed()) {
textSpriteToShow.visible = true;
// show that the original sprite is still clickable
// even once the text is shown on top of it
console.log("clicked!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment