Blurred Sprites

Hi all,

Currently playing around with Allegro and I'm having a wee problem with my first program. I have a sprite with 5 states for moving right on the screen, and it works well, only it leaves the previous state on the screen behind the sprite as it moves. Kinda like when Windows crashes and you can drag a window and it leaves loads of little ones behind it. Is there a command to remove the previous state before you increment it to the next one? Sorry if this isn't very clear, I'm not very clever. :-[


Richard Phipps

Clearing the screen sounds like it might be what you need.
Look in the manual for clear.

Arthur Kalliokoski

You have to clear out the previous sprite by blitting the background over it (dirty rectangles or the entire bitmap). There's also an xor operation that simply requires you to blit the sprite twice (which restores original background) in the exact same spot, but it'd be slower and ugly.

Check out the allegro examples.

Matthew Dalrymple

The problem is that you aren't clearing what was left on there from before. Each frame is stacking on top of eachother.

BITMAP *sprite = ...;
BITMAP *buffer = create_bitmap(SCREEN_W, SCREEN_H);
  // makes your background red (change that to black or whatever you want)
  clear_to_color(buffer, makecol(255, 0, 0));
  // blit your sprite to the buffer.. you're probably using draw_sprite
  blit(sprite, buffer, 0, 0, x, y, sprite->w, sprite->h);
  blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);

I know I'm already late on the post but :-P I gave a small uncompilable example.

Thread #590286. Printed from