Ejemplo n.º 1
0
    def render(self, sprites, x=None, y=None):
        """Overrides the render method of sdl2.ext.TextureSpriteRenderSystem to
        use "SDL_RenderCopyEx" instead of "SDL_RenderCopy" to allow sprite
        rotation:
        http://wiki.libsdl.org/SDL_RenderCopyEx
        """
        r = SDL_Rect(0, 0, 0, 0)
        if isiterable(sprites):
            rcopy = SDL_RenderCopyEx
            renderer = self.sdlrenderer
            x = x or 0
            y = y or 0
            for sp in sprites:
                r.x = x + sp.x
                r.y = y + sp.y
                r.w, r.h = sp.size
                if rcopy(renderer, sp.texture, None, r, sp.angle, None,
                         SDL_FLIP_NONE) == -1:
                    raise SDLError()
        else:
            r.x = sprites.x
            r.y = sprites.y
            r.w, r.h = sprites.size
            if x is not None and y is not None:
                r.x = x
                r.y = y
            SDL_RenderCopyEx(self.sdlrenderer, sprites.texture, None, r,
                             sprites.angle, None, SDL_FLIP_NONE)

        SDL_RenderPresent(self.sdlrenderer)
Ejemplo n.º 2
0
 def draw(self, graphics):
     destRect = SDL_Rect()
     for tileX in range(0, game.SCREEN_WIDTH, BACKGROUND_SIZE):
         for tileY in range(0, game.SCREEN_HEIGHT, BACKGROUND_SIZE):
             destRect.x = units.tileToPixel(tileX)
             destRect.y = units.tileToPixel(tileY)
             destRect.w = destRect.h = units.tileToPixel(BACKGROUND_SIZE)
             graphics.blitSurface(self.surfaceId, None, destRect)
    def drawAnimation(self, x, y):
        if self._visible:
            dest_rect = SDL_Rect()
            src_rect = None

            dest_rect.x = int(x + self._offsets[self._current_animation].x)
            dest_rect.y = int(y + self._offsets[self._current_animation].y)
            dest_rect.w = int(self._src_rect.w * game_globals.SPRITE_SCALE)
            dest_rect.h = int(self._src_rect.h * game_globals.SPRITE_SCALE)

            src_rect = self._animations[self._current_animation][
                self._frame_index]
            self._graphics.blitSurface(self._sprite_sheet, src_rect, dest_rect)
Ejemplo n.º 4
0
    def process(self, world, components):
        # Processing code that will render all existing CParticle
        # components that currently exist in the world. We have a 1:1
        # mapping between the created particle entities and associated
        # particle components; that said, we render all created
        # particles here.

        # We deal with quite a set of items, so we create some shortcuts
        # to save Python the time to look things up.
        #
        # The SDL_Rect is used for the blit operation below and is used
        # as destination position for rendering the particle.
        r = SDL_Rect()

        # The SDL2 blit function to use. This will take an image
        # (SDL_Texture) as source and copies it on the target.
        dorender = SDL_RenderCopy

        # And some more shortcuts.
        sdlrenderer = self.renderer.renderer
        images = self.images
        # Before rendering all particles, make sure the old ones are
        # removed from the window by filling it with a black color.
        self.renderer.clear(0x0)

        # Render all particles.
        for particle in components:
            # Set the correct destination position for the particle
            r.x = int(particle.x)
            r.y = int(particle.y)

            # Select the correct image for the particle.
            img = images[particle.type]
            r.w, r.h = img.size
            # Render (or blit) the particle by using the designated image.
            dorender(sdlrenderer, img.texture, None, r)
        self.renderer.present()