Archived

This topic is now archived and is closed to further replies.

lpsoftware

Danged scrolling tiles

Recommended Posts

Ok, I''ve got a question that''s been bothering me for a few days now. I''ve set up a pretty basic scrolling routine for my vertically scrolling game, but it seems to draw the tiles all wrong. The tile size is 32, and there are 32 vertical tiles and 16 horizontal tiles in the map. char map[16][32] = ..... //define the map int world_camera; //the left-hand corner of screen to start //the drawing routine from. I add and subtract coordinates from the world_camera function as there are key up and key down hits, while world_camera is greater than 0, and less than 545. This is the drawing function: void draw_tiles(void) { int tile; RECT tile_area; int x, y, scroll_y; for (x = 0; x < 16; x++) { for (y = 0; y < 16; y++) { scroll_y = (world_camera / 32); tile = map[x][scroll_y]; tile_area.left = (tile - 1) * TILESIZE; tile_area.top = 0; tile_area.right = tile * TILESIZE; tile_area.bottom = TILESIZE; lpddssecondary->BltFast(x * TILESIZE, y * TILESIZE, lpddsoffscreentiles, &tile_area, DDBLTFAST_SRCCOLORKEY); } } } I hope that I explained myself correctly. Thanks for any help. Martin

Share this post


Link to post
Share on other sites
quote:
Original post by lpsoftware

char map[16][32] = ..... //define the map

int world_camera; //the left-hand corner of screen to start
//the drawing routine from.


Surely you mean the top corner to draw from? If it's a vertical scroller, whether it is the left or right makes little difference
quote:

This is the drawing function:

void draw_tiles(void)
{
int tile;
RECT tile_area;
int x, y, scroll_y;

Move tile_area.top = 0 and tile_area.bottom = TILESIZE to here: you don't need to recalculate them each time through the loop. Only the left and right values.
quote:


for (x = 0; x < 16; x++) {
for (y = 0; y < 16; y++) {

scroll_y = (world_camera / 32);

tile = map[x][scroll_y];

Ok, here you are choosing your tile based on world_camera, However, world_camera is the same throughout your loop! So although 'y' is going from 0 to 15, your tiles have nothing to do with this, and therefore I expect your map only ever draws a single row over and over. I think this needs to be: scroll_y = y + (world_camera / 32);
quote:


tile_area.left = (tile - 1) * TILESIZE;
tile_area.top = 0;
tile_area.right = tile * TILESIZE;
tile_area.bottom = TILESIZE;

lpddssecondary->BltFast(x * TILESIZE, y * TILESIZE, lpddsoffscreentiles, &tile_area, DDBLTFAST_SRCCOLORKEY);

}
}
}

I hope that I explained myself correctly. Thanks for any help.

Martin


Hope that was of some use to you.

Edited by - Kylotan on 4/8/00 1:45:47 PM

Share this post


Link to post
Share on other sites