omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    4
    10
    4330
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • rownn
      rownn last edited by

      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

      stephen mikael 2 Replies Last reply Reply Quote 0
      • brumm
        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).

        select

        1 Reply Last reply Reply Quote 2
        • stephen
          stephen last edited by

          @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 and LabelNode together ndyou cn creat whtever outcome ou are looking for

          1 Reply Last reply Reply Quote 0
          • stephen
            stephen @rownn last edited by stephen

            @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 nd TextView on top. They can overlap but they will not share touch event. For example If SceneView is deper than TextView and you touch an area they share (overlapping) only TextView recieves Touch Event.

            1 Reply Last reply Reply Quote 1
            • mikael
              mikael @rownn last edited by mikael

              @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.

              1 Reply Last reply Reply Quote 2
              • rownn
                rownn last edited by

                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

                1 Reply Last reply Reply Quote 0
                • rownn
                  rownn last edited by

                  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

                  stephen 1 Reply Last reply Reply Quote 0
                  • stephen
                    stephen @rownn last edited by

                    @rownn what are you trying o do exactly and ill try to hlp best i can.

                    @mikael y tried your MarkdownView a while back and i couldn't get it o work . i wa les experienced with python and ui at the time so im not sure if it was user eror or if it needed update

                    1 Reply Last reply Reply Quote 0
                    • rownn
                      rownn last edited by

                      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!

                      stephen 1 Reply Last reply Reply Quote 2
                      • stephen
                        stephen @rownn last edited by

                        @rownn the docs were hard for myself to follow at first to even with C# experience. not a problem 🤓😎

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors