LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-08-2004, 12:28 PM   #1
MadCactus
Member
 
Registered: Jul 2003
Distribution: Slackware 9.1
Posts: 195

Rep: Reputation: 30
Recommend me a sprite rectangle clearing algorithm


Hi,

I'm new to sprite animation, and was wondering: what are considered the best algorithms for clearing the sprite areas before blitting?

I had considered calculating the overlaps and clearing them only once, then clearing the remaining rectangles (to avoid flicker), but this looks pretty expensive.

Would using an auxilliary pixel area get around this problem?

Any help much appreciated.
 
Old 10-09-2004, 08:20 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
I had considered calculating the overlaps and clearing them only once, then clearing the remaining rectangles (to avoid flicker), but this looks pretty expensive.

Would using an auxilliary pixel area get around this problem?
Yes. The usual technique to avoid flicker is called "double buffering". This means blitting the bitmap pictures is done in an in-memory copy of the screen, then the entire screen (or for optimizing performance, only the "dirty" rectangles of the screen) is copied at onze to the actual display. When moving a sprite, the rectangle it originally was on is cleared (clean background blitted to it) in the in-memory picture. Then it's blitted on top of the new position, and finally update the display from the in-memory bitmap. SDL for example has a SDL_UpdateRects() function for this. It takes an array of "dirty" rectangles which should be updated to the display. The SDL engine then decides what whether it's more economic to update the entire display, or just a part of it, based on the rectangles that should be updated. When using other programming languages/libs, you may need to code more (or less) of this optimization and "double buffering" yourself.

You don't mention a programming language or libs (SDL?) you want to use, but this is a nice sprite tutorial about SDL w/ Python, which, IMHO can be helps when programming C w/ SDL, or even without SDL:

http://kai.vm.bytemark.co.uk/~piman/...tutorial.shtml

Also, google on "double buffering" (and SDL):
http://www.google.nl/search?hl=nl&q=...tnG=Zoeken&lr=
 
Old 10-09-2004, 01:11 PM   #3
MadCactus
Member
 
Registered: Jul 2003
Distribution: Slackware 9.1
Posts: 195

Original Poster
Rep: Reputation: 30
I know a little about the basic display methods, it is SDL with C++ i'm using.

I had been doing something pretty stupid I just realised, so i'm going to fix the code now without further yakking.

Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the best cryptographic algorithm? Linux.tar.gz Linux - Security 19 05-02-2006 08:54 PM
Xlib Code --- Why not Drawing Rectangle?????? pihu Programming 1 07-18-2005 01:05 PM
Which sorting algorithm? nodger Programming 6 01-28-2005 06:13 PM
Airsnort Algorithm inthefuture Linux - Security 1 08-26-2004 10:01 PM
java, rectangle size issues. exodist Programming 1 03-13-2004 04:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration