Package pygsear :: Module Drawable :: Class Drawable |
[show private | hide private]
[frames | no frames]

## Class Drawable

    object --+
             |
        Sprite --+
                 |
                Drawable

Known Subclasses:
  `AnimatedImage`, `Image`, `Layer`, `Multi`, `MultiImage`, `Score`, `Shape`, `SpriteButton`, `Stationary`, `String`

Things to draw on screen.

Method Summary
| ``__init__`(self, w)` Initialize Drawable sprite.
bool | ``can_see`(self, target, blocking_rects_list)` Performs a los (line of sight) check from the center of the source to the center of the target.
| ``center`(self, x, y, dx, dy)` Align the Drawable in its layer
| ``clear`(self, surface)` Erase sprite to background
`bool` | ``collide`(self, other)` return True if this sprite and other sprite overlap.
`Drawable` or `False` | ``collidelist`(self, lothers)` return True if this sprite and any in list of others collide.
`List` | ``collidelistall`(self, lothers)` return True if this sprite and any in list of others collide.
| ``direction`(self, point)` return the direction from the sprite to a point
| ``distance`(self, point)` return the distance from the sprite to a point
| ``draw`(self, surface)` Blit image to layer
| ``get_position`(self)` return a copy of the sprite's position
| ``get_size`(self)` return size of sprite's rect.
| ``move`(self)` set position to next position on path
| ``nudge`(self, dx, dy)` Move sprite.
| ``onscreen`(self, slack, **kw)` return True if image is on the screen or layer.
| ``pause`(self)` stop moving along Path
| ``runPath`(self, frames)` call move() continuously
| ``set_crect`(self, crect)` set the collision `pygame.Rect` used for collision checking.
| ``set_path`(self, path)` set which path to follow
| ``set_position`(self, location, *args)` Move sprite to location.
| ``set_positionRandom`(self, slack)` Move sprite to a random location on screen
| ``set_size`(self, size)` Set size of sprite's rect.
| ``solid`(self, other, move_both)` move sprite so that it does not overlap with other sprite
| ``stretch`(self, dx, dy, size, keepAspectRatio)` Change the size of sprite's image, and rect.
| ``uclear`(self, surface)` clear sprite and update display
| ``udraw`(self, surface)` Draw image and update display.
| ``unpause`(self)` start moving along Path
| ``_set_position`(self, location)` Move sprite to location.
Inherited from Sprite
| ``__repr__`(self)`
| ``add`(self, *groups)` add(group or list of of groups, ...) add a sprite to container
| ``add_internal`(self, group)`
| ``alive`(self)` alive() -> bool check to see if the sprite is in any groups
| ``groups`(self)` groups() -> list of groups list used sprite containers
| ``kill`(self)` kill() remove this sprite from all groups
| ``remove`(self, *groups)` remove(group or list of groups, ...) remove a sprite from container
| ``remove_internal`(self, group)`
| ``update`(self, *args)`
Inherited from object
| ``__delattr__`(...)` x.__delattr__('name') <==> del x.name
| ``__getattribute__`(...)` x.__getattribute__('name') <==> x.name
| ``__hash__`(x)` x.__hash__() <==> hash(x)
| ``__reduce__`(...)` helper for pickle
| ``__reduce_ex__`(...)` helper for pickle
| ``__setattr__`(...)` x.__setattr__('name', value) <==> x.name = value
| ``__str__`(x)` x.__str__() <==> str(x)
Inherited from type
| ``__new__`(T, S, ...)` T.__new__(S, ...) -> a new object with type S, a subtype of T

Method Details

### __init__(self, w=None) (Constructor) Initialize Drawable sprite. Parameters: `w` - Layer on which sprite lives. Overrides: `pygame.sprite.Sprite.__init__`

### can_see(self, target, blocking_rects_list) Performs a los (line of sight) check from the center of the source to the center of the target. Adapted from the Pygame Code Repository (PCR). Makes the following assumption: Both the source and target include a `pygame.Rect` attribute called `crect`. Parameters: `target` - Sprite to check for visibility. `blocking_rects_list` - List of `pygame.Rect`s which can block the visibility. Returns: True if line of sight is clear, or False if it is blocked. (type=bool)

### center(self, x=None, y=None, dx=None, dy=None) Align the Drawable in its layer If no parameters are included, the sprite will be moved to the center of its screen layer, or use the parameters to adjust where exactly the sprite should be placed. Parameters: `x` - offset from left edge if negative, offset from right edge `y` - offset from top edge if negative, offset from bottom edge `dx` - horizontal offset from center `dy` - vertical offset from center Raises: `TypeError` - Caller may include either the `x` parameter to align the sprite from the edge of the screen, or the `dx` parameter to align the sprite from the center of the screen, but not both. `TypeError` - Caller may include either the `y` parameter to align the sprite from the edge of the screen, or the `dy` parameter to align the sprite from the center of the screen, but not both.

### clear(self, surface=None) Erase sprite to background Parameters: `surface` - `pygame.Surface` to draw to, or if None, will draw to the sprite's screen. Returns: Affected `pygame.Rect` which can be passed to `pygame.display.update`.

### collide(self, other) return True if this sprite and other sprite overlap. Uses the `.crect` attribute of each sprite to check for a collision (overlap). Parameters: `other` - The other sprite to check for collision. Returns: True if the sprites overlap. (type=`bool`)

### collidelist(self, lothers) return True if this sprite and any in list of others collide. The True value is the other sprite. Note that more than one sprite in the list may be colliding with the sprite, but only one is returned. Parameters: `lothers` - List of other sprites to check for collision. Returns: Other sprite if there is a collision, or `False`. (type=`Drawable` or `False`)

### collidelistall(self, lothers) return True if this sprite and any in list of others collide. The True value is the list of colliding sprites, or if there is no collision, an empty sequence. Parameters: `lothers` - List of other sprites to check for collision. Returns: List of colliding sprites, or empty list. (type=`List`)

### direction(self, point) return the direction from the sprite to a point Parameters: `point` - Point to find the direction to.

### distance(self, point) return the distance from the sprite to a point Parameters: `point` - Point to find the distance to.

### draw(self, surface=None) Blit image to layer Parameters: `surface` - Pygame surface to draw to, or if None, will draw to the sprite's screen. Returns: Affected `pygame.Rect` which can be passed to `pygame.display.update`.

### get_position(self) return a copy of the sprite's position

### get_size(self) return size of sprite's rect. Returns: `pygame.Rect`

### move(self) set position to next position on path

### nudge(self, dx=0, dy=0) Move sprite. Parameters: `dx` - Distance to move in x-direction. `dy` - Distance to move in y-direction.

### onscreen(self, slack=None, **kw) return True if image is on the screen or layer. If `slack` is None, and keyword args are included for particular edges (ie `top` or `right`) checks only the edges passed by keyword. param left: Sprite can be this far from left edge. param right: Sprite can be this far from right edge. param top: Sprite can be this far from top edge. param bottom: Sprite can be this far from bottom edge. param layer: Use this layer instead of the sprite's screen layer. Parameters: `slack` - Distance sprite can be off screen and still return True. Use a negative number to restrict the sprite to a smaller area.

### pause(self) stop moving along Path

### runPath(self, frames=0) call move() continuously Parameters: `frames` - Number of times to call move(), or if frames is 0, call move() until `EndOfPath`.

### set_crect(self, crect=None) set the collision `pygame.Rect` used for collision checking. Parameters: `crect` - rect to use for collision checking. crect gets centered on the rect. If None, use the rect as the crect also.

### set_path(self, path) set which path to follow path: Instance of `Path.Path`.

### set_position(self, location, *args) Move sprite to location. set_position can be called as either `set_position(x, y)` or as `set_position((x, y))` which makes it a bit easier to use from an interactive session. The extra checks for whether the argument is a single 2-tuple or 2 separate numbers does make the function run a bit slower, so if speed is an issue, you should call `Drawable._set_position`. Parameters: `location` - can be a single 2-tuple `(x, y)`, or 2 numbers

### set_positionRandom(self, slack=0) Move sprite to a random location on screen Parameters: `slack` - If this is included, the sprite will be more or less constrained to the screen. Use negative numbers to restrict the sprite to a smaller area, positive numbers to allow the sprite to actually be offscreen.

### set_size(self, size) Set size of sprite's rect. Parameters: `size` - `(width, height)`

### solid(self, other, move_both=0) move sprite so that it does not overlap with other sprite Parameters: `other` - other sprite `move_both` - if set, move both sprites in the effort to get them apart, otherwise only move the original sprite.

### stretch(self, dx=None, dy=None, size=None, keepAspectRatio=1) Change the size of sprite's image, and rect. Parameters: `dx` - Number of pixels to stretch in the x direction (can be neg) `dy` - Number of pixels to stretch in the y direction (can be neg) `size` - Tuple with new overall size `(width, height)` `keepAspectRatio` - If True, the new image will be padded with transparent borders.

### uclear(self, surface=None) clear sprite and update display Parameters: `surface` - `pygame.Surface` to draw to, or if None, will draw to the sprite's screen.

### udraw(self, surface=None) Draw image and update display. This function is almost exclusively for use in an interactive session, since it updates the screen immediately after drawing the sprite instead of waiting and updating after all sprites have been drawn. Parameters: `surface` - `pygame.Surface` to draw to, or if None, will draw to the sprite's screen.

### unpause(self) start moving along Path

### _set_position(self, location) Move sprite to location. Parameters: `location` - Must be a 2-tuple `(x, y)`

Generated by Epydoc 2.0 on Fri Nov 11 14:26:39 2005 | http://epydoc.sf.net