Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What language are you using? In Python, Pygame can do this for you. Use the RenderUpdates Group and some Sprite objects with image and rect attributes.</p> <p>For example:</p> <pre><code>#!/usr/bin/env python import pygame class DirtyRectSprite(pygame.sprite.Sprite): """Sprite with image and rect attributes.""" def __init__(self, some_image, *groups): pygame.sprite.Sprite.__init__(self, *groups) self.image = pygame.image.load(some_image).convert() self.rect = self.image.get_rect() def update(self): pass #do something here def main(): screen = pygame.display.set_mode((640, 480)) background = pygame.image.load(open("some_bg_image.png")).convert() render_group = pygame.sprite.RenderUpdates() dirty_rect_sprite = DirtyRectSprite(open("some_image.png")) render_group.add(dirty_rect_sprite) while True: dirty_rect_sprite.update() render_group.clear(screen, background) pygame.display.update(render_group.draw(screen)) </code></pre> <p>If you're not using Python+Pygame, here's what I would do:</p> <ul> <li>Make a Sprite class that's update(), move() etc. method sets a "dirty" flag.</li> <li>Keep a rect for each sprite</li> <li>If your API supports updating a list of rects, use that on the list of rects whose sprites are dirty. In SDL, this is SDL_UpdateRects.</li> <li>If your API doesn't support updating a list of rects (I've never had the chance to use anything besides SDL so I wouldn't know), test to see if it's quicker to call the blit function multiple times or once with a big rect. I doubt that any API would be faster using one big rect, but again, I haven't used anything besides SDL.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload