def __init__(self, image, position=(0, 0), rotation=0, scale=1, opacity=255, color=(255, 255, 255), anchor=None, batch=None, group=None): ''' Create a sprite. :Parameters: image : string or image Name of the image resource or a pyglet image. position : tuple Position of the anchor. Defaults to (0,0). rotation : float The rotation (degrees). Defaults to 0. scale : float The zoom factor. Defaults to 1. opacity : int The opacity (0=transparent, 255=opaque). Defaults to 255. color : tuple The color to colorize the child (RGB 3-tuple). Defaults to (255,255,255). anchor : (float, float) (x,y)-point from where the image will be positions, rotated and scaled in pixels. For example (image.width/2, image.height/2) is the center (default). ''' if isinstance(image, basestring): image = load_image(image) BatmaNode.__init__(self) pyglet.sprite.Sprite.__init__(self, image, batch=batch, group=group) anchor = anchor or "center" if isinstance(self.image, (pyglet.image.Animation, list, tuple)): _anchor_animation(self.image, anchor) else: _anchor_image(self.image, anchor) self.position = position self.rotation = rotation self.scale = scale self.opacity = opacity self.color = color self.__must_update = True
def __init__(self, image, rows=None, cols=None, initial_frame=0, total_frames=None, position=(0, 0), rotation=0, scale=1, opacity=255, color=(255, 255, 255), anchor=None, batch=None, group=None): ''' Create an animated sprite. :Parameters: image : string or image Name of the atlas image resource or a list of images. rows : int Row number of atlas image. Ignore this if image is an animation. cols : int Column number of atlas image. Ignore this if image is an animation. initial_frame : int Initial frame of animation. Ignore this if image is an animation. total_frames : int How much frames starting from ``initial_frame`` the animation will have. If None, will use until end of atlas. Ignore this if image is an animation. position : tuple Position of the anchor. Defaults to (0,0). rotation : float The rotation (degrees). Defaults to 0. scale : float The zoom factor. Defaults to 1. opacity : int The opacity (0=transparent, 255=opaque). Defaults to 255. color : tuple The color to colorize the child (RGB 3-tuple). Defaults to (255,255,255). anchor : (float, float) (x,y)-point from where the image will be positions, rotated and scaled in pixels. For example (image.width/2, image.height/2) is the center (default). ''' if isinstance(image, basestring): atlas = load_atlas(image, rows, cols) else: atlas = image self.frames = atlas self._initial_frame = initial_frame if not total_frames: self._total_frames = len(atlas) - initial_frame self._frame_index = initial_frame super(AnimatedSprite, self).__init__(self.frames[initial_frame], batch=batch, group=group) anchor = anchor or "center" _anchor_animation(self.frames, anchor) self.position = position self.rotation = rotation self.scale = scale self.opacity = opacity self.color = color