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.


    Can Someone Turn This Script Into a ‘Node’ Tutorial, Please?

    Pythonista
    python 3.6 gamedevelopment
    5
    15
    9616
    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.
    • ccc
      ccc last edited by

      I provided a pull request that does not yet move to Nodes but removes xrange(). This allows the cards to be displayed (in the wrong places) in Python 3.

      ScriptNasty 2 Replies Last reply Reply Quote 0
      • enceladus
        enceladus last edited by enceladus

        Not tested well. Seems to work fine. Hopefully gives an idea on how to implement with nodes.
        https://gist.github.com/168e93ca05f213124f1aec4c329d9c73

        ScriptNasty 1 Reply Last reply Reply Quote 0
        • ScriptNasty
          ScriptNasty @ccc last edited by

          @ccc I’ve, too, dabbled with swapping xrange(len(images)) for range(0, len(images)) in an attempt to produce an equivalent outcome, However, the output always seems to positions the cards in somewhat of an “ascending staircase” pattern... I have no idea as to why. Hah

          1 Reply Last reply Reply Quote 0
          • ScriptNasty
            ScriptNasty @enceladus last edited by

            @enceladus Now that is a great starting point! Thank you for your timly response and contribution! I’ve definitely enjoyed looking through your scripting style and techniques. Do you know why the cards refuse to be in the center of the screen? I attempted making the cards once myself, out of Nodes, and I was unable to get them center as well. I roughly used the same exact logic that rcruz used with his Layers format of the cards, and they always seem to favor a more low-left output... No idea why...

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

              Try looking at the anchor_point -- I forget the default, but you can make the X,y refer to a corner, or center.

              ScriptNasty 1 Reply Last reply Reply Quote 0
              • ScriptNasty
                ScriptNasty @ccc last edited by

                @ccc I reviewed your PR and approved it; thank you for the pro tips and etiquette!

                1 Reply Last reply Reply Quote 0
                • ScriptNasty
                  ScriptNasty @JonB last edited by

                  @JonB The default is definitely the center of the sprite, that’s why it doesn’t make sense that the same logic to center the layer objects wouldn’t work for the node objects.

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

                    The andhor point just says what part of the node your are placung with position. But the coordinate system of the parent which you place into is always based in the corner. so, if you are trying to create a grid, using corner coordinates probably makes more sense, or else, you need to reference everything to the center, and use vector addition.

                    i.e

                    center=parent.bbox.size/2.0 #(w/2, h/2)
                    somenode.position = center + Vector2( j*colwidth, i*rowheight)
                    

                    where i,j are row/col, as measured from the center.

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

                      The puzzle is that in Python 2 the cards are all properly aligned but in Python 3 they are staggered.

                      Phuket2 1 Reply Last reply Reply Quote 0
                      • Phuket2
                        Phuket2 @ccc last edited by

                        @ccc , its the / operator , need the // version in py3.x

                        for i, front_image in enumerate(self.front_images):
                                    x, y = i%5, i//5
                        
                        ScriptNasty 1 Reply Last reply Reply Quote 0
                        • JonB
                          JonB last edited by

                          fwiw, i always forget this, but divmod lets you do both in one operation:

                          y,x = divmod(i, 5)
                          
                          1 Reply Last reply Reply Quote 2
                          • ScriptNasty
                            ScriptNasty @Phuket2 last edited by

                            @Phuket2 Wow, that definitely solved the alignment issue! But OP is still hoping someone can convert this memory card game into a “Tutorial.” Maybe in the same format as the Alien Game that Ole provided within the examples of Pythonista.

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