Getting the pixel dimensions of a sprite? How?
themusicman last edited by themusicman
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.
JonB last edited by
Taking N equal columns, with margin M between edge And adjacent cols:
Note for 3 columns, there will be 4 margins.
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.
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 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.