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

2017/1/19

textbox input

roinitalucian roinitalucian

2017/1/19

#
Hi. I have a basic scenario with an actor that i can move using keyboard input. It just adds or substracts a number of pixels to its coordinates. This number is stored in a variable. What I want is to have a text box in the same scene which controls that variable, so I can change the speed the actor is moving by changing the text in the text box. How can I do something like that? Thanks in advance.
Super_Hippo Super_Hippo

2017/1/19

#
What have you tried? With what do you have trouble?
roinitalucian roinitalucian

2017/1/19

#
Well I'm new to Greenfoot and I just don't know a way to do that
danpost danpost

2017/1/19

#
You probably need to create a subclass of Actor for the object; create the base image in the constructor; add a field for the text; create a method that create an image of the text, draws it on the base image and sets it to the actor; add a boolean field to represent focus state; add code to the act method to check for focus, and if focused, check keyboard input and adjust the text and update the image as needed.
You need to login to post a reply.