Qbasicnews.com

Full Version: Pixel by Pixel scrolling
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When people use P*P scrolling, are the tiles on the edges of the screen actually being drawn completely going out of the screen? Or are there actually calculations being done so make sure the engine is only drawing what's showing up on the screen? This has been confusing me forever now.
I always make my engine draw the tiles that are in view (on screen) and then 1 extra tile outside the screen, to make sure there are no black lines and glitches when you scroll.

All tiles outside of that area are ignored.

Makes the engine really really fast.
Alright, thanks Z!re. Smile

I'll move on to another question then, I'm planning on making a game with a lot of sprites of different sizes, but I don't know how to save them... and how to retreive their varying sizes to use correctly in the game. Should they all be saved as separate files? Or should I save them all to a sheet? And if I do either of them, how should the engine be made?

And just for the record, I'm using Allegro and C++...
I'm trying out Allegro for my first time; I've previously used SDL, DirectDraw and OpenGL.

If you save all of your images as PCX (or whatever), using the load_pcx function will store the image width/height in the BITMAP structure.

To gather all of the files together into a nice neat package, just make a class to open/extract from .PAK files (very simple file format).

By storing them all on one sheet, I have a feeling things would become messy... you'd have to hardcode the location of each image on the grid, along with the width/height of it.

I would personally (and I am) store all of the images as separate files... later on, I'll write another PAK editor to extract files temporarily, use the Allegro load_pcx function, then delete the file. No clutter, plus you get to use the excellent image loading functions.

-shiftLynx
Once you have your sprite in a BITMAP * structure, you can look its dimensions:

Code:
BITMAP *mySprite;
PALETTE dummy;

mySprite = load_pcx ("data\sprite.pcx", dummy);

width = mySprite->w;
height = mySprite->h;
Quote:When people use P*P scrolling, are the tiles on the edges of the screen actually being drawn completely going out of the screen? Or are there actually calculations being done so make sure the engine is only drawing what's showing up on the screen? This has been confusing me forever now.

When I make ASM routines for clipping sprites, I make calculations so I only draw what's on the screen. If you do it right, it is actually faster than just drawing the whole sprite, because if you just draw what's on the screen, it's alot less to draw and takes less processing time.

What you don't want to do is individually check each pixel if it's on the screen or not. I used to do it that way, and it's really slow. What I do now is calculate the edges of the sprite first, then draw it from there, much faster. Smile
Quote:I'll move on to another question then, I'm planning on making a game with a lot of sprites of different sizes, but I don't know how to save them... and how to retreive their varying sizes to use correctly in the game. Should they all be saved as separate files? Or should I save them all to a sheet? And if I do either of them, how should the engine be made?

And just for the record, I'm using Allegro and C++...

Welcome to my world, brudda Big Grin

Whislt my game development is 'in progress' mode, I just have each sprite as a seperate bitmap image. Simplest way to create a spritebank when doing this is allocate an array of pointers to bitmaps, then set each pointer when you load each image:
Code:
// Somewhere in the header file...
define SPR_BANK_SIZE 100
..................
// Create an array of ptrs to bitmaps
BITMAP *pSpritebank[SPR_BANK_SIZE];
Code:
// Somewhere else..
........
// Sprite loader
char charbuf[80];

for (int nextElement = 0; nextElement < SPR_BANK_SIZE; nextElement++)
{
     // Do something here to set charbuf to the next filename
     .........

     // Now load the next sprite into the bank
     pSpritebank[nextElement] = load_bitmap(charbuf, NULL);
}

Then you can just draw_sprite(buffer, pSprite[4], x, y) to draw sprite 4, for example.
Erm - hang on, what was the question again.. :???:
use grabber!!! it comes with allegro. its sooo cool. im using it for a little something myself.

it puts all the bmps into one dat file, and the theres a nifty little routine that opens that file and loads the contents to an array. i dont have that routine on me but its in the docs i think, shout if you need help. I group my graphics by category, so all the hero sprites are in a dat file called hero.dat, all the bad guy sprites are in a dat called bad.dat.
then when theyre loaded they go into arrays like BITMAP *hero[9] etc.
so now theres the bitmaps hero[0], hero[1]....

you can even call the sprites names and access them like hero[walk1], hero[jump] etc.

grabber can 'grab' sound, music, graphics and more, try it.