Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Editing text in games
-
Hi everybody,
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
:) rownn
-
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
EffectNode
,SpriteNode
andLabelNode
together ndyou cn creat whtever outcome ou are looking for -
@rownn heres a quick Example for
TextView
↴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
SceneView
on botom ndTextView
on top. They can overlap but they will not share touch event. For example IfSceneView
is deper thanTextView
and you touch an area they share (overlapping) onlyTextView
recieves Touch Event. -
@rownn, years and years ago I wrote this thing called MarkdownView which lets you have nice-looking text views that are in-place editable in markdown. It is probably in need of a Python 3 overhaul.
Another relatively simple option is to have a WebView that has a single
editable
div in it – but you need some menus or text replacement in place to start lists etc. I have a working Evernote client based on this approach, but it does need quite a bit of Javascript. -
Hey guys,
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.
Thanks again
rownn -
Hey,
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.:) rownn
-
-
Hi guys,
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 🤓😎