Advertisement

tiling problems again

Started by December 20, 2000 12:22 PM
5 comments, last by alex mcandrew 24 years ago
Ok, I''ve got a problem. My tiling system takes whatever is on screen from coordinates 0,0 to 32,32 and then replicates it throughout the screen. That works just fine if I don''t clear the screen every time, however if I want animation, I will have to clear the screen. I tried drawing the first tile every cycle and then copying it, but it''s so slow that it flickers. I guess I will have to take my source tile from a different surface, but I don''t really know how. How can I do that? Any other ideas as to how I can solve this problem? Thanks.
--------------------Help Needed!Turn-based 20th century strategy wargameTitle still to be determined
so you draw a tile in the upper left corner of the screen and then you copy it throughout the screen.

Why?


I belive that you are trying to have the same tile (that tile that you draw at 0,0,32,32 ) drawn throughout the screen.

well make a loop.

don''t copy it anywhere, draw it everywhere.

if you show me the code you''re using, i may tell you how to change it.

if ( there''''s a will )
return ( there''''s a way );
Advertisement
As I said in my previous post, I did try that, but if I have to draw the image every time and then have to copy it 144 times (12*12), it gets very slow, even though I''ve got a PIII 450 with a 16MB graphics card.

Thanks anyway. Anyone else?
--------------------Help Needed!Turn-based 20th century strategy wargameTitle still to be determined
show us some code!

I don''t get what you''re trying to do.

even if you draw 500 tiles every frame it won''t give you less than 20 fps.

unless your Bliting function is using the wrong alogarithm.

if ( there''''s a will )
return ( there''''s a way );
Ok, well here's the code in the main function (note that I'm using the GPDumb engine):

DD_Fill_Surface(lpddsback, 0);
Draw_BOB(&tile_dirt,lpddsback);
Draw_Tiles();


This is the code for Draw_Tiles:


// set up rectangles
RECT source_rect, dest_rect;
int tile;

source_rect.left = 0;
source_rect.top = 0;
source_rect.right = 32;
source_rect.bottom = 32;

int tile1_left = 0;
int tile1_top = 0;
int tile1_right = 32;
int tile1_bottom = 32;

int counter_tile2;

for (int counter_tile1 = 0; counter_tile1 < 12; counter_tile1++) // y tiles
{
for (counter_tile2 = 0; counter_tile2 < 12; counter_tile2++) // the x tile drawing loop
{
tile = map[counter_tile1][counter_tile2];

switch(tile)
{
case 1: {
dest_rect.left = tile1_left;
dest_rect.top = tile1_top;
dest_rect.right = tile1_right;
dest_rect.bottom = tile1_bottom;

tile1_left = tile1_left + 32;
tile1_right = tile1_right + 32;

// set up the color key so that color 0 is transparent
DDCOLORKEY col_key;
col_key.dwColorSpaceLowValue = 0;
col_key.dwColorSpaceHighValue = 0;

// set the key
lpddsback->SetColorKey(DDCKEY_SRCBLT, &col_key);

// perform the blit from back to primary
lpddsprimary->Blt(&dest_rect, lpddsback, &source_rect, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
} break;

case 0: {
// don't do anything here

} break;
}// end


When I use this code the tiles flicker, although my other sprites don't. Thanks.

Edited by - alex mcandrew on December 20, 2000 5:31:40 PM
--------------------Help Needed!Turn-based 20th century strategy wargameTitle still to be determined

// this goes in the main function of your game console
// replace the 3 function calls for this


// clear the back buffer
DD_Fill_Surface(lpddsback, 0);

for ( int y_index = 0; y_index < 12; y_index++ )
{
for ( int x_index = 0; x_index < 12; x_index++ )
{
tile_dirt.x = 32*x_index;
tile_dirt.y = 32*y_index;
if ( map[x_index][y_index] != 0 )
Draw_Bob (&tile_dirt, lpddsback );
}
}



lpddsprimary->Flip ( NULL, DDFLIP_WAIT );





Edited by - myself on December 20, 2000 7:15:24 PM
Advertisement
Nice! Thanks a lot! I do notice a bit of ''jerkiness'' when I move a sprite around on the screen with the tiles displayed at the same time, but I can optimize the code to take care of that.

Last question (don''t want to post yet ANOTHER thread):
I''m having problems with my tile graphics. The bottom half of each tile has very unusual colours; bright ones such as pink, green, orange, etc). However, the top half is totaly normal.

Any ideas? Thanks a lot for your help!
--------------------Help Needed!Turn-based 20th century strategy wargameTitle still to be determined

This topic is closed to new replies.

Advertisement