Advertisement

DD 2d RPG question about drawing

Started by September 28, 2000 06:36 PM
2 comments, last by minerjr 24 years, 3 months ago
Hi, I am currently in grade 12 and i am learning Directx. I have programed the Nintendo gameboy and also in VB and also in c++. I am wondering about the way i draw my graphics. I have been doing basicly the same type of loop for the past 4 years. Here is my code for my current game. for(x=-11;x<11;x++) { for(y=-8;y<9;y++) { zz = Map[tx + x + mapx][ty + y + mapy].background; zz2 = Map[tx + x + mapx][ty + y + mapy].foreground; x11 = (((x+10) * 32)+INCX); y11 = (((y+7) * 32)+INCY); screen1.top = y11; screen1.bottom = y11+32; screen1.left = x11; screen1.right = x11+32; lpddsback->Blt(&screen1, tiles, &tile[zz], DDBLT_WAIT, NULL); if (zz2 > 0)lpddsback->Blt(&screen1, tiles2, &tile[zz2],DDBLT_KEYSRC | DDBLT_WAIT, NULL); //Draw foreground only if object is there else skip the tile. } } I have always used this type of loop to draw graphics using a tile map and was wondering if there is a better way of doing this. I am using 640X480x16Bit color. I redo this function every frame of my game and call this same command when i scroll at 2 pixels at a time so the game does not run to slow. I hope some one could tell me how to optimzie my code some so the game can run better on slow computers. Thx for any response.
That is pretty much how I draw my graphics. The only suggestions I can make are:

x11 = (((x+10) * 32)+INCX);
can become
x11 = (((x+10) << 5)+INCX);

Map[x][y]
can become
Map[x*y]
Not sure if this is faster, but it can easily be loaded dynamically (ie. from a file)

if (zz2 > 0)
can become
if (zz2)
but again I''m not sure if it is faster.

Also I think that BltFast is faster that Blt (or maybe I am missing something?) so if you manually clip your RECT''s you can use this function (BltFast won''t draw surfaces that are partly off the edge unless you manually clip the source and destination rectangles).

Just ask if you need any more info on that manual clipping stuff!

Advertisement
quote: Original post by wise_Guy
Map[x][y]
can become
Map[x*y]
Not sure if this is faster, but it can easily be loaded dynamically (ie. from a file)



I think you mean Map[x+y*width], and yes, it''s a littlebit faster, but not much...
quote: original post by Ksero

I think you mean Map[x+y*width], and yes, it''s a littlebit faster, but not much...


Yeah, i listed code for initialisation but forgot to tell minerj how to access it! Thanks!

This topic is closed to new replies.

Advertisement