Is there a way to put a label on a canvas?

Hi. Currently, I'm creating a game where a character needs to pass through the obstacles and earn scores before the timer ends. However, I'm facing an issue that I have no idea how to fix.


:arrow_up: This is the interface that I want, where the timer, the score count, and the game interface are all there, but since the labels are above the canvas, the obstacles can't be spawned at the top of the screen, which I didn't want. I wanted an interface where all the things could be put together and the obstacles could be spawned at the exact top of the screen, but not the canvas. So, I tried another way,

and then realized that we can't put labels in a canvas, I know the 'drawText' thing exists, but as in the first screenshot I uploaded, I put the timer on the top right of the screen and the score on the top middle of the screen, which can't be done using 'drawText'. Does anyone know any method to solve this problem?

You can add text everywhere in the canvas .
Why you can't in the top right or center ?

1 Like

The X and Y options of the 'drawText' block are inaccurate in my opinion, there are many versions of Android. I want to put the text at the top right and the top middle no matter how big the Android user's screen is.

There are the blocks height and width of screens that give you the right value and then you have to calculate with density of pixels too.
Probably this is the problem of accuracy of you text position.

1 Like

I don't remember if Appinventor added a block to get density of pixel , if not here there is an extension that provides it

1 Like

Also ensure you set the text alignment in the designer (default center)

1 Like

You can try this extension to put labels on top of canvas.

1 Like

Here is the screen of a tablet and an emulator using Classic Theme.

tablet

Remember if you draw on a Canvas, you must erase too using Clear to avoid typing over. :cry:

1 Like

You could try to draw the text on a small canvas, take that canvas image, and use that as a sprite image.

I have not done this.

1 Like

As @SteveJG has shown, it should simply be a matter of getting the canvas size (width) and work from that. If font size is an issue then again test the canvas width and set font size accordingly (a bit similar to using media queries in html)

1 Like

Tysm power users 🫡