Ok I think I'm on the right track.When you get stuck sometimes its best to go back to the beginning. Today I started looking at the original drawbitmap functions and tilemap functions and discovered the problem. just don't know how to correct it. Since you askedlets look at my versions of the cpp functions for tilemap.
- Code: Select all
void Grafx::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint16_t color) {
drawTilemap(x, y, tilemap, spritesheet, 0, 0, Grafx_TFTWIDTH, Grafx_TFTHEIGHT, color);
}
void Grafx::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint16_t dx, uint16_t dy, uint16_t dw, uint16_t dh, uint16_t color) {
uint16_t tilemap_width = pgm_read_byte(tilemap);
uint16_t tilemap_height = pgm_read_byte(tilemap + 1);
uint16_t tile_width = pgm_read_byte(tilemap + 2);
uint16_t tile_height = pgm_read_byte(tilemap + 3);
tilemap += 4; // now the first tiyleis at tilemap
uint16_t ddw = dw + dx;
uint16_t ddh = dh + dy;
uint16_t maxDdx = (dw - x + tile_width - 1) / tile_width;
uint16_t maxDdy = (dh - y + tile_height - 1) / tile_height;
if (tilemap_width < maxDdx) {
maxDdx = tilemap_width;
}
if (tilemap_height < maxDdy) {
maxDdy = tilemap_height;
}
int16_t startDdx = (-x) / tile_width;
int16_t startDdy = (-y) / tile_height;
if (startDdx < 0) {
startDdx = 0;
}
if (startDdy < 0) {
startDdy = 0;
}
if (flagcollision)numcolision = 0; //Line 735 - clear numcolision - ADD by Summoner123
for (uint16_t ddy = startDdy; ddy < maxDdy; ddy++) {
for (uint16_t ddx = startDdx; ddx < maxDdx; ddx++) {
int16_t drawX = ddx*tile_width + x + dx;
int16_t drawY = ddy*tile_height + y + dy;
uint16_t tile = pgm_read_byte(tilemap + ddy*tilemap_width + ddx);
if (drawX >= dx && drawY >= dy && drawX <= (ddw - tile_width) && drawY <= (ddh - tile_height)) {
drawBitmapTM1(drawX, drawY, tile_width, tile_height, spritesheet[tile], color);
if (flagcollision) {
solid[numcolision].x = drawX; //Save X coordinate - ADD by Summoner123
solid[numcolision].y = drawY; //Save Y coordinate - ADD by Summoner123
solid[numcolision].spritecol = spritesheet[tile]; //Save Sprite of tile - ADD by Summoner123
numcolision++; //Increment numcolision - ADD by Summoner123
}
}
else { // we need to draw a partial bitmap
drawBitmapTm(drawX, drawY, tile_width, tile_height, spritesheet[tile], dx, dy, dw, dh, color);
}
}
}
}
it uses two different bitmap functions. One with parameters like this.....
drawBitmapTm(drawX, drawY, tile_width, tile_height, spritesheet[tile], dx, dy, dw, dh, color);
and one that works like this.........
drawBitmapTM1(drawX, drawY, tile_width, tile_height, spritesheet[tile], color);
theres nothing wrong with the first but a lot wrong with the second. Its asking a bitmap function that has those arguments so I gave it a bitmap with those arguments. the problem is that yes its looking for those arguments but more added to it to actually do the tiles. That can be found here.......
- Code: Select all
void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h , const uint8_t *bitmap) {
#if (ENABLE_BITMAPS > 0)
/* original code
int8_t i, j, byteWidth = (w + 7) / 8;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
if (pgm_read_byte(bitmap + j * byteWidth + i / 8) & (B10000000 >> (i % 8))) {
drawPixel(x + i, y + j);
}
}
}
*/
uint8_t * buffer = getBuffer();
const uint8_t col = color;
const uint8_t bw = (w+7) / 8;
// clip
if (x >= LCDWIDTH)
return;
if (x + w <= 0)
return;
if (y >= LCDHEIGHT)
return;
if (y + h <= 0)
return;
if (y < 0)
h += y, bitmap -= bw * y, y = 0;
if (y + h > LCDHEIGHT)
h = LCDHEIGHT - y;
uint8_t x1 = max(0, x);
uint8_t x2 = min(LCDWIDTH, x + w);
#ifdef ENABLE_GRAYSCALE
uint8_t g = y ^ frameCount;
#endif
// draw
uint8_t first_bitmap_mask = 0x80 >> ((x1 - x) & 7);
const uint8_t * bitmap_line = bitmap + (x1 - x) / 8;
uint8_t screen_mask = 0x01 << (y % 8);
uint8_t * screen_row = buffer + (y / 8) * LCDWIDTH + x1;
for (uint8_t dy=0; dy<h; dy++, bitmap_line+=bw)
{
const uint8_t * bitmap_ptr = bitmap_line;
uint8_t bitmap_mask = first_bitmap_mask;
uint8_t pixels = pgm_read_byte(bitmap_ptr);
uint8_t * dst = screen_row;
if (col == BLACK)
for (uint8_t sx=x1; sx<x2; sx++, dst++)
{
if (pixels & bitmap_mask)
*dst |= screen_mask;
bitmap_mask >>= 1;
if (!bitmap_mask)
{
bitmap_mask = 0x80;
pixels = pgm_read_byte(++bitmap_ptr);
}
}
else if (col == WHITE)
{
uint8_t inv_screen_mask = ~screen_mask;
for (uint8_t sx=x1; sx<x2; sx++, dst++)
{
if (pixels & bitmap_mask)
*dst &= inv_screen_mask;
bitmap_mask >>= 1;
if (!bitmap_mask)
{
bitmap_mask = 0x80;
pixels = pgm_read_byte(++bitmap_ptr);
}
}
}
#ifdef ENABLE_GRAYSCALE
else if (col == GRAY)
{
uint8_t inv_screen_mask = ~screen_mask;
for (uint8_t sx=x1; sx<x2; sx++, dst++)
{
if (pixels & bitmap_mask)
{
if ((sx^g) & 1)
*dst |= screen_mask;
else
*dst &= inv_screen_mask;
}
bitmap_mask >>= 1;
if (!bitmap_mask)
{
bitmap_mask = 0x80;
pixels = pgm_read_byte(++bitmap_ptr);
}
}
g ^= 1;
}
#endif
else // invert
for (uint8_t sx=x1; sx<x2; sx++, dst++)
{
if (pixels & bitmap_mask)
*dst ^= screen_mask;
bitmap_mask >>= 1;
if (!bitmap_mask)
{
bitmap_mask = 0x80;
pixels = pgm_read_byte(++bitmap_ptr);
}
}
screen_mask <<= 1;
if (!screen_mask)
{
screen_mask = 1;
screen_row += LCDWIDTH;
}
}
#else
drawRect(x, y, w, h);
#endif
}
without enabling bitmaps nets you a square grid but what its looking for are these set of code lines......
- Code: Select all
uint8_t first_bitmap_mask = 0x80 >> ((x1 - x) & 7);
const uint8_t * bitmap_line = bitmap + (x1 - x) / 8;
uint8_t screen_mask = 0x01 << (y % 8);
uint8_t * screen_row = buffer + (y / 8) * LCDWIDTH + x1;
for (uint8_t dy=0; dy<h; dy++, bitmap_line+=bw)
{
const uint8_t * bitmap_ptr = bitmap_line;
uint8_t bitmap_mask = first_bitmap_mask;
uint8_t pixels = pgm_read_byte(bitmap_ptr);
uint8_t * dst = screen_row;
I worked on it a lil and can get a grid of squares but figure out how to disable the enable bitmaps part or add the needed lines to a drawbitmap function using those arguments.
The buffer and grey scale parts aren't needed we use color names in the arguments also the buffer stuff is not needed. We just need the dy dh stuff