Need graphics Guru to help fix graphics functions ili9341

OK I'm working on a gaming feature added to sumotoys ili93xx library and ive been able to get most everything going but I'm having two different problems. Both have to do with a tile map function.

The first part has to do with the tilemap function itself. What it does is allows you store a bunch of bitmaps within the same progmem space together and assigns them an integer in RAM that can be used in array like a .json file. It only stores the bitmaps once and uses the integer array to make a tilemap made up of different bitmap tiles.

When I first tried to implement the function in the library it was only showing about a quarter of the tile map in a corner. So I asked for help and someone pointed out that the uint8_t's and int16_t's to uint16_t and int16_t. That helped a bit and now shows only half of the tilemap in a corner.

The next part has to do with the int x and placement of a particular sprite or sets of sprites. Ok so if I want to tell a bitmap where to be I would usually just use the coordinates in the function. But what this does is uses this...

 int player_x = 160;
  int player_y = 120;
  int player_direction = 2;

Then you use player_x and player_y in the bitmap function and it puts the bitmap at the starting point given above. like so......

if (tft.buttons.repeat(BTN_RIGHT,1));//{x--;}
    if (tft.buttons.repeat(BTN_LEFT,1));//{x++;}
    if (tft.buttons.repeat(BTN_DOWN,1));//{y--;}
    if (tft.buttons.repeat(BTN_UP,1));//{y++;} 
     

 if(tft.buttons.repeat(BTN_DOWN,3)){
   tft.drawBitmap1(player_x,player_y,paul_front_black,16,16,BLACK);
    tft.drawBitmap1(player_x,player_y,paul_front_blue,16,16,BLUE);
     tft.drawBitmap1(player_x,player_y,paul_front_brown,16,16,BROWN);
      tft.drawBitmap1(player_x,player_y,paul_front_pink,16,16,PINK);
       tft.drawBitmap1(player_x,player_y,paul_front_yellow,16,16,YELLOW);
        player_direction = 2;
        player_y = player_y + 1;}
        if(player_y >= 40){
      player_y = 40;}

Buuut it puts the bitmaps it puts the bitmaps being displayed at 32 and 32 instead. now the peculiar thing is that the player direction works.

void TFT_ILI93XX::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint16_t color) {
	drawTilemap(x, y, tilemap, spritesheet, 0, 0, TFT_ILI93XX_TFTWIDTH, TFT_ILI93XX_TFTHEIGHT, color);
}
void TFT_ILI93XX::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)) {
				drawBitmap1(drawX, drawY, spritesheet[tile], tile_width, tile_height, 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);
			}
		}
	}
}

void TFT_ILI93XX::drawBitmapTm(int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *bitmap, uint16_t dx, uint16_t dy, uint16_t dw, uint16_t dh, uint16_t color) {
	int8_t i, j, byteWidth = (w + 7) / 8;
	dw += dx;
	dh += dy;
	int16_t largest = 0;
	int16_t largesty = 0;
	for (j = 0; j < h; j++) {
		for (i = 0; i < w; i++) {
			if (pgm_read_byte(bitmap + j * byteWidth + i / 8) & (B10000000 >> (i % 8))) {
				int16_t drawX = x + i;
				int16_t drawY = y + j;

				if (drawX >= dx && drawX < dw && drawY >= dy && drawY < dh) {
					drawPixel(drawX, drawY, color);
				}
			}
		}
	}
}

here is the .h part notice the int x and y which are supposed to be coordinates for the bitmap.

boolean     getBitmapPixel(const uint8_t* bitmap, uint16_t x, uint16_t y);

	void        drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint16_t color);
	void        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);

	void        drawBitmapTm(int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *bitmap, uint16_t dx, uint16_t dy, uint16_t dw, uint16_t dh, uint16_t color);

	typedef struct {       //line 171 "Public Variables   - ADD by Summoner123
		int x;                    //X coordinate                 - ADD by Summoner123
		int y;                    //Y coordinate                 - ADD by Summoner123
		const byte *spritecol;    //Sprite of object             - ADD by Summoner123
	}object;
	object solid[60];         // Matriz were saved a Sprite, X and Y cordinates of all tiles on the screen - ADD by Summoner123

	byte numcolision = 0;     //count of solid objects indacat how many tiles drawed on the screen - ADD by Summoner123

	bool flagcollision = true;

here is the library and the sketch and a pic.

TFT_ILI93XX-master2.0.zip (307 KB)

basicSetup.ino (19.6 KB)

You are going to need to provide a better description of the problem.

The first code block you have included uses "tft.drawBitmap1", but then you have included other functions but not explained why they might relate to your problem...

So which function is not working?

I suspect this is nothing to do with the ILI9341 as that interface is abstracted by the library. The problem is in the sketch C code.

If you have weak coding skills then throwing together a lot of newly written functions and expecting them to work in the way you want is a bit optimistic. You will just end up solving one problem - asking for help- solving another - asking for help - and so it goes on... which appears to be what is happening and forum helpers will lose interest in offering help!

If you have hacked the library then write some simple "test" sketches to verify those functions individually work in a way consistent to how they will be used in the sketch.

Provide better description of the problem? Ummm can you not see the picture I posted, lol

Ok here's the thing I have been working on this project for a year. I have updated several libraries but when it comes to the tilemap functions I get stuck. Every single library I've updated is the same way. Now the function was OG written for a Nokia 5110 that has a resolution of 84x48.

Now all my problems stem from the tilemap functions.

The first code block shows the player start point integers which thier dependency is listed under structure in the fourth code block.

The second code block shows how I'm supposed to be able to add player_x and player_y to the bitmap function so the player starts out at the coordinates given in the first block. But that does not work. It just puts my player Sprite at some where near 32 and 32. But oddly enough I the player Sprite direction in the first code block does work. So I can choose which way the player Sprite faces at start up. Left right front rear.

Ok so the second part is the actual tilemap functions. It should print out a 2x2 Sprite map that boarders the screen but as you can see in the pics it only shows about half with pixels at ever 32.

Now both the player_x and player_y integers come from the tilemaps structure as seen in the fourth code block.

So basically I need to be able to name player Sprite start out positions and to draw the full tilemap in its entirety

update::::

Ok I can now use player_x and player_y coordinates and the buttons are working. For the buttons I had forgotten to add begin.buttons and update.buttons to begin function so now I can change direction and soon walk the player around but still no go on the tilemap.

I have no idea where "32 and 32" is on the screen; in pixel coordinates usually that is near the top left of the screen but there is nothing there. I see what looks like a little pig on the screen with a blue bow between it's ears so I assume the image is the right way up, but that coordinate is a long way from 32,32.

Add some serial debug messages to the sketch within the appropriate functions and see if it is getting the right coordinates and all the ones you expect it to get are being serviced.

Check your pointers and "pointers to pointers" are passing what is intended and the values are not running of the end of the target memory area. Note that a variable and array name is itself a pointer even though it is not declared as such.

like these poiners????

 #define pgm_read_byte(addr) (*(const unsigned char *)(addr))

#ifndef pgm_read_byte
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#endif
#ifndef pgm_read_word
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
#endif
#ifndef pgm_read_dword
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
#endif

// Pointers are a peculiar case...typically 16-bit on AVR boards,
// 32 bits elsewhere.  Try to accommodate both...

#if !defined(__INT_MAX__) || (__INT_MAX__ > 0xFFFF)
#define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
#else
#define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
#endif

#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif


#define swap(a, b) { int8_t t = a; a = b; b = t; }

Or do you mean pointers like "uint16_t cursor_x," kind of pointers.

I have the screen rotated to the other landscape so he's prolly upside down but it actually supposed to be a Paul Atreades bitmap Sprite from dune and I drew him Pokemon style. Trying to build a good game like an RPG to go with the library as both an example and a cool reason to build your own console.