How can I update the window, it's not working this way, This method is in a class that I'm included on my main.cpp ( Which has a main display already configured )
]]>Don't forget code tags.
void Map::build_map () { ALLEGRO_BITMAP * wall_map = al_load_bitmap(wall); for(int row = 0; row < max_lines; row++) { for(int col = 0; col < max_cols; col++) { if(this->map_form[row][col] == "#") { al_draw_bitmap_region(wall_map, row, col, width, height, 0, 0, 0); } } } al_flip_display(); }
See the function signature:
void al_draw_bitmap_region(ALLEGRO_BITMAP *bitmap, float sx, float sy, float sw, float sh, float dx, float dy, int flags)
So it should probably be:
//from al_draw_bitmap_region(wall_map, row, col, width, height, 0, 0, 0); //to al_draw_bitmap_region(wall_map, 0, 0, width, height, row, col, 0);
And are "rows" and "columns" in pixels? or do you need to multiply them by the tile height? Because it looks like you're drawing a map of walls, but each wall is say, index=5, at pixel=5. But it should be index * tile_width to go from map index coordinates to screen coordinates.
]]>Sorry, I'm a beginner here. Yeah, I'm on documentation for hours ( I'm slower so ... : [ ). I need to multiply, thanks, it worked but now the entire map it's very small :
{"name":"pZsw6tN.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/e\/de7fef6ff8f1476a4912abd18ebb2259.png","w":391,"h":490,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/e\/de7fef6ff8f1476a4912abd18ebb2259"}
Wall : 30 px
This map should be something like this :
{"name":"oSdecdi.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/0\/b066cd352942738f86dc14c4a04c6ad1.png","w":438,"h":414,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/0\/b066cd352942738f86dc14c4a04c6ad1"}
]]>Well, first, are you using al_draw_bitmap_region for a specific reason? Because I literally wrote a map drawing code like... last night... (for the umptenth time...) and it doesn't use _region anywhere. In fact, I almost never use the region version.
The simplest version is drawing the entire map (subtract an x and y offset for camera movement) by iterating two for loops, and using al_draw_bitmap. No regions needed.
One step above, is limiting the "overdraw" (drawing outside the screen) by pruning your map lookups to only map indexes that are inside the bounds of the screen.
Are you just trying to do a simple map drawing routine?
]]>Using the 'region' drawing routine is fine if you know what you're doing, and you don't want to use sub bitmaps, but generally tiling an atlas is what is done.
Like Chris said, you need to draw at dx = col*TILE_WIDTH , dy = row*TILE_HEIGHT, otherwise they will all overlap by one pixel like in your picture.
]]>Finally back on my laptop, here's a full example (in D, but it's almost the same as C++ or C#):
This one isn't using a texture atlas, that Edgar mentioned the use for using regions. A texture atlas is a single bitmap with all (or many) of your tiles on it so you draw only the relevant tile. But you can also have individual bitmaps for tiles (which I'm using here).
{"name":"figure1.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/9\/99f2fe58419e61de1b91f12f028be129.jpg","w":400,"h":400,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/9\/99f2fe58419e61de1b91f12f028be129"}
A texture atlas
Mine also supports viewports (drawing to less than the full screen, for split-screen multiplayer), and trimming the overdraw by only drawing array indexes that fit inside the screen. I might be able to remove those features if you really need it to see just the drawing portion.
But basically, if you want texture atlas, you just replace the if(data[i][j] = 0/1/2/3) that contain al_draw_bitmap(invidual_bitmap_pointers,...) with al_draw_region with the location of the tile you care about inside the atlas. But because that's an additional "thing" to deal with, I'd get the basic drawing with hand-picked tiles first, before adding the atlas. Cut the amount of failure points so you can debug and get to the source of the issue faster.
]]>