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.


    Getting the pixel dimensions of a sprite? How?

    Pythonista
    3
    4
    1952
    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.
    • themusicman
      themusicman last edited by themusicman

      Hi All

      So, is there a way of obtaining the physical pixel dimensions (x and y) of a sprite please?

      I am trying to generate a grid of circles of ROW_COUNT and COLUMN_COUNT using the self.size function to utilise the full width of the iPad screen, such that the grid is centred correctly and not closer to one side of the screen than the other - but just can't get my head around the correct formulae.

      Here's the code I am using...

      		# draw board (white circles) - eventually replace with image
      		for circles in range(COLUMN_COUNT):
      			for rows in range(ROW_COUNT):
      				new_circle = SpriteNode('shp:Circle')
      				new_circle.scale = 3
      				new_circle.position = ((circles * (x - 68) / COLUMN_COUNT) + 68, (rows * (x - 68) / ROW_COUNT) + 68)
      				self.add_child(new_circle)
      
      

      Can any experts please shed some light and help a learner in distress please, haha... thanks.

      John

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

        Taking N equal columns, with margin M between edge And adjacent cols:

        MWMWMWM

        Note for 3 columns, there will be 4 margins.

        W=(self.width-(N+1)margin)/N
        x = M+(col-1)
        (W+M)

        That assumes the anchor_point is on bottom left. Otherwise, for anchor_point at center, add a half width

        x = M+(col-1)*(W+M)+W/2

        Similarly for rows

        Anchor point what might be screwing with you.

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

          Thanks @jonB - great explanation.

          However, I think it is not knowing the width of the sprite that appears to be causing me some layout issues, and it is that width which I am trying to figure out. I have seen in Swift there is a command that allows one to ascertain the width of the bounding box of a sprite, just wondering if there is a similar command for Pythonista.

          mikael 1 Reply Last reply Reply Quote 0
          • mikael
            mikael @themusicman last edited by

            @themusicman, one idea would be to initialize a ui.Image with the same built-in image name, and check the size attribute.

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