[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Question regarding a Rect()-object



So you want to set the topleft corner and the bottom-right corner in absolute instead of relative coordinates?
if you already know the topleft values and the bottom-right corner it's not difficult to calculate them.
I understand you were trying to find a way where you wouldn't have to calculate them, but I also can't find a way to do it.
this passage makes me think you can't: (from the pygame Rect documentation)
"Assigning to size, width or height changes the dimensions of the rectangle; all other assignments move the rectangle without resizing it. Notice that some attributes are integers and others are pairs of integers."
so
#---------
import pygame
def createRect(left,top,right=0,bottom=0):#in absolute coordinates
if right-left < 0: right = 0
else: right = right-left
if bottom-top < 0: bottom = 0
else: bottom = bottom-top
a = pygame.Rect(left,top,right,bottom)
return a
a = createRect(10,10)
b = createRect(10,10,60,60)
print "topleft = (%s,%s). bottomright = (%s,%s). width,height = (%s,%s)." \
% (a.top,a.left,a.bottom,a.right,a.width,a.height)
print "topleft = (%s,%s). bottomright = (%s,%s). width,height = (%s,%s)." \
% (b.top,b.left,b.bottom,b.right,b.width,b.height)
#---------
output:
topleft = (10,10). bottomright = (10,10). width,height = (0,0).
topleft = (10,10). bottomright = (60,60). width,height = (50,50).



HTH, Luke