container
—graphics containers¶
-
class
GraphicsGroup
(x=0, y=0)[source]¶ Bases:
object
Convenience wrapper for grouping a number of graphics in a simple way.
Arguments determine the group’s position (
pos
); unlike for graphics, this may be floating-point.This is a
{graphic: rel}
mapping, wheregraphic
is aGraphic
instance andrel
is the graphic’s(x, y)
position relative to this group. Adding graphics is possible with something likegroup[graphic] = rel
(instead of usingadd()
).graphic_attrs
contains some properties of thisGraphicsGroup
which correspond to those ofGraphic
. These can be set to apply to all contained graphics.-
graphic_attrs
= ('layer', 'visible', 'blit_flags', 'anchor', 'rot_anchor', 'scale_fn', 'rotate_fn', 'rotate_threshold')¶ Attributes which are mapped to
Graphic
attributes.
-
rect
¶ The
pygame.Rect
covered by graphics in this group.The top-left of this is not necessarily the same as
pos
.
-
x
¶ x
co-ordinate of the group’s top-left corner.
-
y
¶ y
co-ordinate of the group’s top-left corner.
-
add
(*graphics)[source]¶ Add graphics.
Call either as
add(graphic, dx=0, dy=0)
for a single graphic, or pass any number of arguments which are(graphic, dx=0, dy=0)
tuples or justgraphic
. In each case:Parameters: Returns: a list of added
Graphic
instances (possibly created in this call), in the order given.If any
graphic
is already in the group, this call changes its relative position (and unspecifieddx
anddy
are unchanged, rather than set to0
).Note that graphics need not be added to a
GraphicsManager
individually —set this usingmanager
.
-
rm
(*graphics)[source]¶ Remove graphics previously added using
add()
.Raises
KeyError
for missing graphics.
-
manager
¶ The
GraphicsManager
to put graphics in.
-
-
class
GraphicsManager
(scheduler, [sfc, ]pos=(0, 0), layer=0)[source]¶ Bases:
engine.gfx.graphic.Graphic
Draws things to a surface intelligently.
Parameters: - scheduler – a
sched.Scheduler
instance this manager should use for timing. - sfc – the surface to draw to; can be a
(width, height)
tuple to create a new transparent surface of this size. If not given orNone
, nothing is drawn. This becomesorig_sfc
and can be changed using this attribute.
Other arguments are as taken by
Graphic
. Since this is aGraphic
subclass, it can be added to otherGraphicsManager
instances and supports transformations. None of this can be done until the manager has a surface, however, and transformations are only applied inGraphic.surface
, not inorig_sfc
.-
scheduler
= None¶ The
scheduler
argument passed to the constructor.
-
graphics
= None¶ {layer: graphics}
dict, wheregraphics
is a set of the graphics in layerlayer
, each as taken byadd()
.
-
layers
= None¶ A list of layers that contain graphics, lowest first.
-
orig_sfc
¶ Like
Graphic.orig_sfc
.This is the
sfc
argument passed to the constructor. Retrieving this causes all graphics to be drawn/updated first.
-
orig_size
¶ The size of the surface before any transforms.
-
overlay
¶ A
Graphic
which is always drawn on top, orNone
.There may only ever be one overlay; changing this attribute removes any previous overlay from the
GraphicsManager
.
-
add
(*graphics)[source]¶ Add graphics.
Takes any number of
Graphic
instances, and returns a list of added graphics.
-
rm
(*graphics)[source]¶ Remove graphics.
Takes any number of
Graphic
instances. Missing graphics are ignored.
-
fade_to
(t, colour=(0, 0, 0)[, resolution])[source]¶ Fade to a colour.
Parameters: - t – how many seconds to take to reach
colour
. - colour – the
(R, G, B[, A = 255])
colour to fade to. - resolution – as taken by
Scheduler.interp()
.
If already fading, the current colour is used as the initial colour; otherwise, the initial colour is taken to be
(R, G, B, 0)
for the given value ofcolour
. After fading, the overlay persists; setoverlay
toNone
to remove it.- t – how many seconds to take to reach
-
fade_from
(t[, colour][, resolution])[source]¶ Fade from a colour to no overlay.
Parameters: - t – how many seconds to take to reach transparency.
- colour – the
(R, G, B[, A = 255])
colour to fade from; if not given, the current colour is used, else(0, 0, 0)
. - resolution – as taken by
Scheduler.interp()
.
Any running fade is canceled, and the final colour is taken to be
(R, G, B, 0)
for the given value ofcolour
. After fading, the overlay is removed.
-
fade
(get_val, *args, **kw)[source]¶ Fade between colours.
Takes arguments like
Scheduler.interp()
, withset_val
omitted.Any currently running fade will be canceled. After fading, the overlay persists; set
overlay
toNone
to remove it.
-
draw
(handle_dirty=True)[source]¶ Update the display (
orig_sfc
).Parameters: handle_dirty – whether to propagate changed areas to the transformation pipeline implemented by Graphic
. PassFalse
if you don’t intend to use this manager as a graphic.Returns
True
if the entire surface changed, or a list of rects that cover changed parts of the surface, orFalse
if nothing changed.
- scheduler – a