Editing text in games
I’m not sure if the title of the topic is clear. I’d like to make it possible to write and edit a text while a game is running. So I tried to use an UI text field and I saw that it is very close to what I’m looking for, but the behavior differs to usual text editing in other applications. The text field seems to be just one line without line breaks, I cannot see the curser position and selecting parts of input is possible but not visible. So is there a way to get an text editor field into games? I don’t want it to be somehow fancy. I want it just as usual.
Hope someone of you can give me a hint, happy eastern to those who are going to celebrate it and greetings to the other
brumm last edited by brumm
You might want to check the TextView. There is also a post about “search and selecting“ in this forum (i saw it a while ago).
@rownn hello can ou give an example of ht your looking or exctly? from what you have provided you are correct in the TextField not being wht you need. TextView sounds more like ht your looking for.
You sy its a game so i assume your using scene module. its more work but using
LabelNodetogether ndyou cn creat whtever outcome ou are looking for
stephen last edited by stephen
@rownn heres a quick Example for
from scene import * class GameLoop (Scene): def setup(self): self.background_color='#ceb763' def did_change_size(self): pass def update(self): pass def touch_began(self, touch): pass def touch_moved(self, touch): pass def touch_ended(self, touch): pass class GUI(ui.View): def __init__(self, *args, **kwargs): self.frame=(0, 0, w, h) self.game_loop=SceneView( scene=GameLoop(), frame=(10, h/2, w-20, h/100*50-10)) self.add_subview(self.game_loop) self.tv=ui.TextView(frame=(10, 10, w-20, h/100*50-20)) self.tv.delegate=self self.add_subview(self.tv) def textview_should_begin_editing(self, textview): return True def textview_did_begin_editing(self, textview): pass def textview_did_end_editing(self, textview): pass def textview_should_change(self, textview, range, replacement): return True def textview_did_change(self, textview): pass def textview_did_change_selection(self, textview): pass if __name__ == '__main__': GUI().present('fullscreen')
Example split screen
SceneViewon botom nd
TextViewon top. They can overlap but they will not share touch event. For example If
SceneViewis deper than
TextViewand you touch an area they share (overlapping) only
TextViewrecieves Touch Event.
mikael last edited by mikael
Another relatively simple option is to have a WebView that has a single
I’m somehow overwhelmed. Thanks for all your replies and hints. I have to go through your tips first and I will be back soon.
textView seems to be exectly what I looked for, amazing, thank you guys. @stephen thx for sharing the snippet. Took a look in the textView before, but I guess I will need a lot more snippets to feel a bit familiar with pythonista.
I feel a bit ashamed about my topic, because everything I needed to know is well descripted in the documentation. :/ But as I said I‘m not that familiar with pythonista yet, but I have learned alot in the last few days. Thanks again!
AND: pythonista rocks!
@rownn the docs were hard for myself to follow at first to even with C# experience. not a problem 🤓😎