|
Effective Parallax Coding or tutorial |
Kevin Epps
Member #5,856
May 2005
|
Hey Guys, My parallax scrolling code for my 2D game uses up too much memory and I'm trying to learn an effective way to code it. Here's the logic code:
Here's the drawing code:
Obviously there's some stuff that I need to change with this. I've heard using a camera is good, but I want to implement one for a 9 layer background with the middle layer a tile map that's drawn by mappy. What's the best course of action? If it's the camera method, could someone help me or at least get me started past the point where I've created a class? Thanks guys! |
gnolam
Member #2,030
March 2002
|
Gah! For the love of Chernobog and all that is unholy, use loops! Something like (typed directly into the reply box, so caveat lector):
-- |
Kevin Epps
Member #5,856
May 2005
|
hey gnolam, I already have a for loop in there. I just didn't post it. It's ok........ As far as the camera code, I'll try that out and let you know. |
Neil Walker
Member #210
April 2000
|
You do know mappy has a parallax layer and set of functions don't you? Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Kevin Epps
Member #5,856
May 2005
|
What? Really? I was looking at that tutorial and it mention parallax but really didn't elaborate on it. I'll look into that! |
Neil Walker
Member #210
April 2000
|
It is only for the bottom most single background though and you have to read it carefully as it is easy to not do it right and end up streaking your parallax graphic. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Kevin Epps
Member #5,856
May 2005
|
Ok. I have the speed a comfortable speed now(Rage 128 30FPS, Radeon 60FPS) with all all layers and also with other sprites than the player. Although I do have one question. Which bitmaps use less memory? Reg Bitmap? |
Steve++
Member #1,816
January 2002
|
All I can tell you is the System bitmaps may use more memory than the others. Otherwise just use a regular memory bitmap. Also, you may want to consider using video bitmaps, as video-to-video blits (masked and unmasked) are almost always accelerated, even on non-3D cards. If you want to get really tricky, create a memory management layer that will cache tiles in the video RAM. You can implement a tile eviction policy such as LRU (least recently used) quite easily. This is fun for some people, like me. I did this on the GBA. It worked really well. |
Tobias Dammers
Member #2,604
August 2002
|
Quote:
Reg Bitmap?
For RAM usage, it doesn't matter how you load or create a bitmap, or in what ways you copy it around. int bmp_size = bmp->w * bmp->h * (bitmap_color_depth(bmp)+7) / 8 + // bitmap data bmp->h * sizeof(char*) + // the line pointers overhead; // whatever the constant overhead is; usually negligible for larger bitmaps.
Video bitmaps consume almost no RAM at all, just the overhead, but they do consume VRAM. The actual size depends on how your graphics cards stores the data, but it is probably at least the size of a memory bitmap. Video cards tend to be pickier about memory alignment (in order to favour speed over memory usage), so they may add padding to the end of each scanline. As for disk space usage; this depends heavily on the file format you use. Plain BMP, PCX and TGA files offer almost no compression at all (except for a whimsy RLE), but they load very fast, are lossless, allegro loads them natively, and virtually all image editing programs support them. Putting them into a datafile enables you to load them all in one go, and offers moderate compression, still lossless. For a beginner's tilemap game, this is what I recommend. Other image formats (GIF, PNG, JPG) offer higher compression rates, but you need add-on libraries to read them. JPG and some PNG sub-formats are also lossy, meaning that after running through the encoding-decoding process, you lose image quality. Most GIF implementation support 256 colors max., and it's a proprietary format. For massive amounts of high-quality bitmap data, (lossless) PNG is probably the way to go; for photo-realistic images with no sharp edges, and without masking, JPG may work too. --- |
Specter Phoenix
Member #1,425
July 2001
|
I have a book that included a tutorial for parallax programming. OpenGL Game Programming.
|
axilmar
Member #1,204
April 2001
|
(I am reposting this from the other similar thread, because maybe it was not read) Dear Kevin, in order to ensure a good frame rate in a bitmap-based game, you have to do the following (assuming bitmap blitting is the issue here): 1) ensure that you use a mode like triple-buffering or page-flipping that uses vram buffers. 2) ensure your most frequently used/large bitmaps are loaded in vram. An effective way to do parallax scrolling with multiple layers is to avoid drawing blocks twice. You need a flag for each block of each layer that tells you if the block has already been covered by one of the above layers. Then you need to do two passes over your layers: a) the first pass will be from top layer to bottom in order to set the 'covered' flag; b) the second pass will be from bottom to top layer to draw those blocks at each layer that have not been covered yet. By carefully choosing block sizes (i.e. not too small, not too big) you can minimize overdraw and do many layers of scrolling (even more than 9!). |
Kevin Epps
Member #5,856
May 2005
|
Thanks all for everything!! I have it exactly where I want it now!! You guys are the greatest!! And yes, Death, I knew I had a book that talked about it, but I couldn't think of which one it was!! Thanks for that. I have that book and that helped me is well. I have sooo many books. |
|