|
Floating point position bitmaps |
SelymAI
Member #15,441
December 2013
|
Using Allegro 5.0.10. I'm trying to make a tile based map move smoothly using floats. Integers work fine, but it's a bit jagged because it only moves pixel by pixel. When I tried using floats I got artifacts along each tile's side: https://drive.google.com/file/d/0B2Uyec4JVSoKT0x5Zi10Q0JJQnM/edit?usp=sharing Drawing a layer of the map, the floats are posX and posY: 1 //DRAW
2 for (int x = 0; x < (sizeX*sizeY); x++)
3 {
4 //CHECK IF TILE IS ON SCREEN
5 if ((columnCounter * 32) + posX > -32 && (columnCounter * 32) + posX < scrnResX &&
6 (rowCounter * 32) + posY > -32 && (rowCounter * 32) + posY < scrnResY)
7 {
8 //SET COLUMN AND ROW
9 tilesetColumnNum = bgLayer.at(x) % 15; tilesetRowNum = (bgLayer.at(x)-(bgLayer.at(x) % 15))/15;
10
11 //DRAW TILE
12 al_draw_bitmap_region(tileset, 32 * tilesetColumnNum, 32 * tilesetRowNum, 32, 32, (columnCounter * 32) + posX, (rowCounter * 32) + posY, 0);
13 }
14
15 //UPDATE COLUMN AND ROW COUNTER
16 if (columnCounter == sizeX - 1){ columnCounter = 0; rowCounter++; }
17 else{ columnCounter++; }
18 }
I put this before creating a new display: 1 al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);
2 al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
3 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
4 al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);
5 al_set_new_display_flags(ALLEGRO_FULLSCREEN);
Wild assumption: It seems like the bitmap region is a bit off causing it to draw part of another tile on the tileset, although it's using a separate variable for the bitmap region. |
Kris Asick
Member #1,424
July 2001
|
Believe it or not, you don't want to do this. Floating point positioning of in-game elements will make any fine details flicker during movement and blur out when stationary. Use floating point to store the positions of everything, but when you draw to the screen, round down to the nearest pixel. Trust me on this one. --- Kris Asick (Gemini) |
SelymAI
Member #15,441
December 2013
|
Thanks |
|