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.


    scene.rect

    Pythonista
    2
    3
    2069
    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.
    • misha_turnbull
      misha_turnbull last edited by

      Hello - I am still working on a chess game. It's coming along nicely, with one exception: the GUI. I've had some trouble with loading the images from files but got that to work, but now run into this problem:
      image
      As you can see, the grid is not being drawn correctly. Here is the code from the draw() method of the scene:

      def draw(self):
          background(0, 0, 0)
          fill(1, 1, 1)
          # this loop displays the pieces (works fine)
          for piece in self.game.board.pieces:
              tint(1, 1, 1, 0.5)
              pos = piece.coord.as_screen()
              img = self.img_names[piece.pythonista_gui_imgname]
              image(img, pos.x, pos.y, scale_factor, scale_factor)
              tint(1, 1, 1, 1)
          
          # this loop displays the grid (doesn't work)
          for tile in self.game.board.tiles:
      
              # this returns either (0.27462, 0.26326, 0.27367) if the piece is white
              # or (0.86174, 0.85795, 0.85417) if the piece is black
              color = tile.color.tilecolor
              color += (0.3,)  # alpha value
      
              # get the position of the tile in screen coords
              # this method DOES function correctly as shown by the above `for piece in pieces` loop
              pos = tile.coord.as_screen()
      
              # draw
              fill(*color)
              rect(scale_factor, scale_factor, pos.x, pos.y)
              fill(1, 1, 1)
      

      I think the problem is either in the fill() or rect() function, but I'm not sure which. Any ideas?

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

        It looks like you're using pos.x and pos.y as width and height of the rect. I think the order of parameters should be:

        rect(pos.x, pos.y, scale_factor, scale_factor)
        
        1 Reply Last reply Reply Quote 0
        • misha_turnbull
          misha_turnbull last edited by

          That was indeed the issue. Thank you!

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