My attempt at writing PACMAN was going smoothly but now I’ve stalled.
Not being a “games” programmer (other than 5 or 6 Tetris version), I
rarely deal with graphics as such, and I’m having a problem with the
sprites (ie. pacman and ghosties).
Basically I want to move the sprite without damaging the "underneath"
picture, as it were. I have a display which is double buffered, so I
can flip the pic etc for fast updates and I can get the effect I want
if each time I completely re-paint the maze first, but of course that
is slowwwwwww.
What I want is (I guess), to restore just the areas where the sprite
moved from, so I guess I need to take a copy of what was in that area
before I draw the sprite.
Can’t for the life of me figure out how. Help!
PS. My wife thinks my hands are glued to my new "Programming Ruby"
book because I haven’t put it down in days!!!
Cheers
G
What I want is (I guess), to restore just the areas where the sprite
moved from, so I guess I need to take a copy of what was in that area
before I draw the sprite.
Well, an idea that requires less work is to keep the whole background
unmodified all the time, and just update the area around (and under for
simplicities sake) the pac, all the time.
Glenn wrote:
What I want is (I guess), to restore just the areas where the sprite
moved from, so I guess I need to take a copy of what was in that area
before I draw the sprite.
Can’t for the life of me figure out how. Help!
This is how I do these things:
- Blit all elements of the background to a background surface. (You
only need to do this when the background changes.)
- Blit the background surface to the main surface every frame.
- Blit pacman to the main surface every frame.
Regards,
Florian Gross
This works for small numbers of moving sprites, but for larger numbers it is best to simply blit the whole background.
Blits like this should be fast, though…
I don’t normally do lower-level graphics work, but if you have slow blits, I think part of the problem could be conflicting formats in your buffers. If you have an 8-bit palettized background buffer being blitted to a 16-bit drawing buffer, but your screen resolution is 24-bit, that’s a lot of conversion going on. I think. Try making everything 32-bit and see if that speeds things up.
Chris
···
On Wed, 19 May 2004 05:18:48 +0900, Linus Sellberg wrote:
What I want is (I guess), to restore just the areas where the
sprite moved from, so I guess I need to take a copy of what was
in that area before I draw the sprite.
Well, an idea that requires less work is to keep the whole
background unmodified all the time, and just update the area around
(and under for simplicities sake) the pac, all the time.
So you blit the whole background each time - doesn’t that slow things down?
Florian Gross flgr@ccan.de wrote in message news:2gv9g8F7ad9aU1@uni-berlin.de…
···
Glenn wrote:
What I want is (I guess), to restore just the areas where the sprite
moved from, so I guess I need to take a copy of what was in that area
before I draw the sprite.
Can’t for the life of me figure out how. Help!
This is how I do these things:
- Blit all elements of the background to a background surface. (You
only need to do this when the background changes.)
- Blit the background surface to the main surface every frame.
- Blit pacman to the main surface every frame.
Regards,
Florian Gross
Glenn wrote:
So you blit the whole background each time - doesn’t that slow things down?
Works like a charm. I’m getting good frame rates. Most games actually
redraw the whole screen multiple times per second.
You could slow things up by doing exactly that (my version redraws
everything the whole time even if it’s not in the ViewPort) or by
using a system to detect what region of the Screen has actually changed
– but I’d think that the overhead added by that would actually exceed
any performance gained.
Thanks to your help, Pacman is very much now back on track! He’s
moving round that maze like a good little pacman should!
Cheers
if your bored...
look into "dirty buffering tutorials 
Alex
···
On Thu, May 20, 2004 at 05:18:48PM +0900, Glenn wrote:
Thanks to your help, Pacman is very much now back on track! He's
moving round that maze like a good little pacman should!