Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Blurred Sprites

This thread is locked; no one can reply to it. rss feed Print
Blurred Sprites
TheFlyingNun
Member #8,374
February 2007

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. :-[

Cheers,
Nun

Richard Phipps
Member #1,632
November 2001
avatar

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

Arthur Kalliokoski
Second in Command
February 2005
avatar

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.

They all watch too much MSNBC... they get ideas.

Matthew Dalrymple
Member #7,922
October 2006
avatar

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);
while(notDone)
{
  // 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.

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

Go to: