Package pyzzle :: Module RelativeRect :: Class RelativeRect
[hide private]
[frames] | no frames]

Class RelativeRect

source code

A Rect style object whose coordinates are given as a fraction of another rect's width and height

Pygame uses the Rect class to store rectangular coordinates. One problem with this representation is that coordinates are measured in pixels. This presents problems in a Myst game - what if you want to adjust the resolution of your image files? Using only rect, you would have to re-adjust the rects of the Hotspots inside that slide.

The RelativeRect addresses this ploblem. It stores coordinates as a fraction of another rect's width and height. In our example, the Hotspot's coordinates would be stored as a fraction of the rect from the Slide in which it resides.

Instance Methods [hide private]
 
__init__(self, rect, reference=None)
Creates a RelativeRect
source code
Rect
absolute(self, reference)
Gets a pygame Rect that is equivalent to RelativeRect when in relation to another Rect.
source code
Method Details [hide private]

__init__(self, rect, reference=None)
(Constructor)

source code 

Creates a RelativeRect

Parameters:
  • rect (Rect or (float,float,float,float)) - The Rect that output will represent, or a tuple (left,top,width,height) representing relative coordinates of this instance.
  • reference (Rect) - the Rect that the instance will be in relation to. This parameter is required if a Rect is supplied in the previous parameter.

absolute(self, reference)

source code 

Gets a pygame Rect that is equivalent to RelativeRect when in relation to another Rect.

Parameters:
  • reference (Rect) - the Rect that output will be in relation to
Returns: Rect