def __init__(self, img, x=0, y=0, blend_src=GL_SRC_ALPHA, blend_dest=GL_ONE_MINUS_SRC_ALPHA, batch=None, group=None, usage='dynamic', subpixel=False, program=None): """Create a sprite. :Parameters: `img` : `~pyglet.image.AbstractImage` or `~pyglet.image.Animation` Image or animation to display. `x` : int X coordinate of the sprite. `y` : int Y coordinate of the sprite. `blend_src` : int OpenGL blend source mode. The default is suitable for compositing sprites drawn from back-to-front. `blend_dest` : int OpenGL blend destination mode. The default is suitable for compositing sprites drawn from back-to-front. `batch` : `~pyglet.graphics.Batch` Optional batch to add the sprite to. `group` : `~pyglet.graphics.Group` Optional parent group of the sprite. `usage` : str Vertex buffer object usage hint, one of ``"none"``, ``"stream"``, ``"dynamic"`` (default) or ``"static"``. Applies only to vertex data. `subpixel` : bool Allow floating-point coordinates for the sprite. By default, coordinates are restricted to integer values. `program` : `~pyglet.graphics.shader.ShaderProgram` A custom ShaderProgram. """ self._x = x self._y = y if isinstance(img, image.Animation): self._animation = img self._texture = img.frames[0].image.get_texture() self._next_dt = img.frames[0].duration if self._next_dt: clock.schedule_once(self._animate, self._next_dt) else: self._texture = img.get_texture() if isinstance(img, image.TextureArrayRegion): program = get_default_array_shader() else: program = get_default_shader() self._batch = batch or graphics.get_default_batch() self._group = SpriteGroup(self._texture, blend_src, blend_dest, program, 0, group) self._usage = usage self._subpixel = subpixel self._create_vertex_list()
def __init__(self, img, x=0, y=0, z=0, blend_src=GL_SRC_ALPHA, blend_dest=GL_ONE_MINUS_SRC_ALPHA, batch=None, group=None, subpixel=False): """Create a sprite. :Parameters: `img` : `~pyglet.image.AbstractImage` or `~pyglet.image.Animation` Image or animation to display. `x` : int X coordinate of the sprite. `y` : int Y coordinate of the sprite. `z` : int Z coordinate of the sprite. `blend_src` : int OpenGL blend source mode. The default is suitable for compositing sprites drawn from back-to-front. `blend_dest` : int OpenGL blend destination mode. The default is suitable for compositing sprites drawn from back-to-front. `batch` : `~pyglet.graphics.Batch` Optional batch to add the sprite to. `group` : `~pyglet.graphics.Group` Optional parent group of the sprite. `subpixel` : bool Allow floating-point coordinates for the sprite. By default, coordinates are restricted to integer values. """ self._x = x self._y = y self._z = z self._img = img if isinstance(img, image.Animation): self._animation = img self._texture = img.frames[0].image.get_texture() self._next_dt = img.frames[0].duration if self._next_dt: clock.schedule_once(self._animate, self._next_dt) else: self._texture = img.get_texture() self._batch = batch or graphics.get_default_batch() self._group = self.group_class(self._texture, blend_src, blend_dest, self.program, 0, group) self._subpixel = subpixel self._create_vertex_list()
def __init__(self, img, x=0, y=0, blend_src=GL_SRC_ALPHA, blend_dest=GL_ONE_MINUS_SRC_ALPHA, batch=None, group=None, subpixel=False): """Create a sprite. :Parameters: `img` : `~pyglet.image.AbstractImage` or `~pyglet.image.Animation` Image or animation to display. `x` : int X coordinate of the sprite. `y` : int Y coordinate of the sprite. `blend_src` : int OpenGL blend source mode. The default is suitable for compositing sprites drawn from back-to-front. `blend_dest` : int OpenGL blend destination mode. The default is suitable for compositing sprites drawn from back-to-front. `batch` : `~pyglet.graphics.Batch` Optional batch to add the sprite to. `group` : `~pyglet.graphics.Group` Optional parent group of the sprite. `subpixel` : bool Allow floating-point coordinates for the sprite. By default, coordinates are restricted to integer values. """ self._x = x self._y = y if isinstance(img, image.Animation): self._animation = img self._texture = img.frames[0].image.get_texture() self._next_dt = img.frames[0].duration if self._next_dt: clock.schedule_once(self._animate, self._next_dt) else: self._texture = img.get_texture() program = get_geo_shader() self._batch = batch or graphics.get_default_batch() self._group = SpriteGroup(self._texture, blend_src, blend_dest, program, 0, group) self._subpixel = subpixel # TODO: add a property to the Texture class: tex_coords = (self._texture.tex_coords[0], self._texture.tex_coords[1], self._texture.tex_coords[3], self._texture.tex_coords[7]) self._vertex_list = self._batch.add( 1, GL_POINTS, self._group, ('position2f', (int(x) if subpixel else x, int(y) if subpixel else y)), ('size4f', (self._texture.width, self._texture.height, 1, 1)), ('rotation1f', (self._rotation, )), ('color4Bn', self._rgba), ('tex_coords4f', tex_coords))