This site requires JavaScript, please enable it in your browser!
Greenfoot back
Haylaylo11
Haylaylo11 wrote ...

2020/4/24

Shifting Text

Haylaylo11 Haylaylo11

2020/4/24

#
Hello, I was just wondering if there is a way to keep text from shifting when you add new strings to it. Currently, I'm trying to make a calculator that displays the numbers a user has inputted, but the numbers just start moving away from where I want them to start.
danpost danpost

2020/4/24

#
If using showText, you will not be able to unshift the text. If using an actor, creating the image by way of the GreenfootImage constructor with a String parameter, the you can vary its position in the world so that the left edge of its image is always at the same place. The other way would be to draw the text image in the above on another image large enough for any input string given by the user; thereby maintaining the same image size and keeping the text left-aligned. I guess a fourth way would be to draw the text image directly onto the background image (so, not using an actor at all). However, you would then have to clear the text from the background before drawing changed text. This could be done by filling the area drawn onto (or resetting the background image).
You need to login to post a reply.