Tilemap function only shows one pixel of each bitmap

Understanding the language, error messages, etc.

Tilemap function only shows one pixel of each bitmap

Postby Duhjoker » Sun Jan 29, 2017 6:52 am

I stuck at adding the tilemap function. I can add as many bitmaps as I want by calling them at once but when I try to use the tilemap function below all I get is a few pixels from each bitmap. a 15 x 7 tile map puts out a column. Im hoping someone can help me fix this...

here is the original from summoner123's library

.cpp
Code: Select all
void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap) {
   int8_t w = pgm_read_byte(bitmap);
   int8_t h = pgm_read_byte(bitmap + 1);
   bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
   drawBitmap(x,y,w,h,bitmap);
}

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
}

void Display::drawBitmap(int8_t x, int8_t y, int8_t w,int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh) {
    int8_t i, j, byteWidth = (w + 7) / 8;
    dw += dx;
    dh += dy;
    int8_t largest = 0;
    int8_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))) {
                int8_t drawX = x + i;
                int8_t drawY = y + j;
               
                if(drawX >= dx && drawX < dw && drawY >= dy && drawY < dh){
                    drawPixel(drawX, drawY);
                }
            }
        }
    }
}

boolean Display::getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y){
  return pgm_read_byte(bitmap+2 + y * ((pgm_read_byte(bitmap)+7)/8) + (x >> 3)) & (B10000000 >> (x % 8));
}

void Display::drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap,
        uint8_t rotation, uint8_t flip) {
    if((rotation == NOROT) && (flip == NOFLIP)){
        drawBitmap(x,y,bitmap); //use the faster algorithm
        return;
    }
    uint8_t w = pgm_read_byte(bitmap);
    uint8_t h = pgm_read_byte(bitmap + 1);
    bitmap = bitmap + 2; //add an offset to the pointer to start after the width and height
#if (ENABLE_BITMAPS > 0)
    int8_t i, j, //coordinates in the raw bitmap
            k, l, //coordinates in the rotated/flipped bitmap
            byteNum, bitNum, byteWidth = (w + 7) >> 3;

    rotation %= 4;

    for (i = 0; i < w; i++) {
        byteNum = i / 8;
        bitNum = i % 8;
        for (j = 0; j < h; j++) {
            if (pgm_read_byte(bitmap + j * byteWidth + byteNum) & (B10000000 >> bitNum)) {
                switch (rotation) {
                    case NOROT: //no rotation
                        k = i;
                        l = j;
                        break;
                    case ROTCCW: //90° counter-clockwise
                        k = j;
                        l = w - i - 1;
                        break;
                    case ROT180: //180°
                        k = w - i - 1;
                        l = h - j - 1;
                        break;
                    case ROTCW: //90° clockwise
                        k = h - j - 1;
                        l = i;
                        break;
                }
                if (flip) {
                    flip %= 4;
                    if (flip & B00000001) { //horizontal flip
                        k = w - k - 1;
                    }
                    if (flip & B00000010) { //vertical flip
                        l = h - l;
                    }
                }
                k += x; //place the bitmap on the screen
                l += y;
                drawPixel(k, l);
            }
        }
    }
#else
    drawRect(x, y, w, h);
#endif
}

void Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet){
    drawTilemap(x,y,tilemap,spritesheet,0,0,LCDWIDTH,LCDHEIGHT);
}
void Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet,uint8_t dx,uint8_t dy,uint8_t dw,uint8_t dh){
    uint8_t tilemap_width = pgm_read_byte(tilemap);
    uint8_t tilemap_height = pgm_read_byte(tilemap + 1);
    uint8_t tile_width = pgm_read_byte(tilemap + 2);
    uint8_t tile_height = pgm_read_byte(tilemap + 3);
    tilemap += 4; // now the first tiyleis at tilemap
    uint8_t ddw = dw + dx;
    uint8_t ddh = dh + dy;
    uint8_t maxDdx = (dw - x + tile_width - 1) / tile_width;
    uint8_t maxDdy = (dh - y + tile_height - 1) / tile_height;
    if(tilemap_width < maxDdx){
        maxDdx = tilemap_width;
    }
    if(tilemap_height < maxDdy){
        maxDdy = tilemap_height;
    }
    int8_t startDdx = (-x) / tile_width;
    int8_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(uint8_t ddy = startDdy;ddy < maxDdy;ddy++){
        for(uint8_t ddx = startDdx;ddx < maxDdx;ddx++){
            int8_t drawX = ddx*tile_width + x + dx;
            int8_t drawY = ddy*tile_height + y + dy;
            uint8_t tile = pgm_read_byte(tilemap + ddy*tilemap_width + ddx);
            if(drawX >= dx && drawY >= dy && drawX <= (ddw-tile_width) && drawY <= (ddh-tile_height)){
                drawBitmap(drawX,drawY,tile_width,tile_height,spritesheet[tile]);

            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
                drawBitmap(drawX,drawY,tile_width,tile_height,spritesheet[tile],dx,dy,dw,dh);
            }
        }
    }
}


.h
Code: Select all
void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap);
   void drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h , const uint8_t *bitmap);
   void drawBitmap(int8_t x, int8_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip);
   void drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh);
   boolean getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y);
   
   void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet);
   void drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet,uint8_t dx,uint8_t dy,uint8_t dw,uint8_t dh);
   


heres mine
Code: Select all
//adafruit_gfx
   void drawBitmap1(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
   void drawBitmap2(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg);
   void drawBitmap3(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
   void drawBitmap4(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg);
   void drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);

   //GAMEBUINO----SUMMONER123------for tilemap--Duhjoker
   void drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color);
   boolean getBitmapPixel(const uint8_t* bitmap, uint8_t x, uint8_t y);

   //draw from SD  mouguino updated by Duhjoker
   //Draw bitmap from SD at position x0, y0
   //void drawBitmapFromSdA(byte x, byte y, char *bitmap, uint16_t color);
   //void drawBitmapFromSdB(byte x, byte y, char *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color);
   //int drawBitmapFromSd(byte x0, byte y0, char *bitmap, uint16_t color);

   //void updateSlide();

   //GAMEBUINO----SUMMONER123
   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, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color);

[/code}

.cpp
[code]
//Adafruit GFX
// Draw a 1-bit image (bitmap) at the specified (x,y) position from the
// provided bitmap buffer (must be PROGMEM memory) using the specified
// foreground color (unset bits are transparent).
void Display::drawBitmap1(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {

   int16_t i, j, byteWidth = (w + 7) / 8;
   uint8_t byte;

   for (j = 0; j<h; j++) {
      for (i = 0; i<w; i++) {
         if (i & 7) byte <<= 1;
         else      byte = pgm_read_byte(bitmap + j * byteWidth + i / 8);
         if (byte & 0x80) drawPixel(x + i, y + j, color);

      }
   }
}

//Adafruit GFX
// Draw a 1-bit image (bitmap) at the specified (x,y) position from the
// provided bitmap buffer (must be PROGMEM memory) using the specified
// foreground (for set bits) and background (for clear bits) colors.
void Display::drawBitmap2(int16_t x, int16_t y,
   const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) {

   int16_t i, j, byteWidth = (w + 7) / 8;
   uint8_t byte;

   for (j = 0; j<h; j++) {
      for (i = 0; i<w; i++) {
         if (i & 7) byte <<= 1;
         else      byte = pgm_read_byte(bitmap + j * byteWidth + i / 8);
         if (byte & 0x80) drawPixel(x + i, y + j, color);
         else            drawPixel(x + i, y + j, bg);
      }
   }
}

//Adafruit GFX
// drawBitmap() variant for RAM-resident (not PROGMEM) bitmaps.
void Display::drawBitmap3(int16_t x, int16_t y,
   uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {

   int16_t i, j, byteWidth = (w + 7) / 8;
   uint8_t byte;

   for (j = 0; j<h; j++) {
      for (i = 0; i<w; i++) {
         if (i & 7) byte <<= 1;
         else      byte = bitmap[j * byteWidth + i / 8];
         if (byte & 0x80) drawPixel(x + i, y + j, color);
      }
   }
}

//Adafruit GFX
// drawBitmap() variant w/background for RAM-resident (not PROGMEM) bitmaps.
void Display::drawBitmap4(int16_t x, int16_t y,
   uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg) {

   int16_t i, j, byteWidth = (w + 7) / 8;
   uint8_t byte;

   for (j = 0; j<h; j++) {
      for (i = 0; i<w; i++) {
         if (i & 7) byte <<= 1;
         else      byte = bitmap[j * byteWidth + i / 8];
         if (byte & 0x80) drawPixel(x + i, y + j, color);
         else            drawPixel(x + i, y + j, bg);
      }
   }
}

void Display::drawBitmap(int8_t x, int8_t y, int8_t w, int8_t h, const uint8_t *bitmap, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color) {
   int8_t i, j, byteWidth = (w + 7) / 8;
   dw += dx;
   dh += dy;
   int8_t largest = 0;
   int8_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))) {
            int8_t drawX = x + i;
            int8_t drawY = y + j;

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

void Display::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 Display::drawTilemap(int x, int y, const uint8_t *tilemap, const uint8_t **spritesheet, uint8_t dx, uint8_t dy, uint8_t dw, uint8_t dh, uint16_t color) {
   uint8_t tilemap_width = pgm_read_byte(tilemap);
   uint8_t tilemap_height = pgm_read_byte(tilemap + 1);
   uint8_t tile_width = pgm_read_byte(tilemap + 2);
   uint8_t tile_height = pgm_read_byte(tilemap + 3);
   tilemap += 4; // now the first tiyleis at tilemap
   uint8_t ddw = dw + dx;
   uint8_t ddh = dh + dy;
   uint8_t maxDdx = (dw - x + tile_width - 1) / tile_width;
   uint8_t maxDdy = (dh - y + tile_height - 1) / tile_height;
   if (tilemap_width < maxDdx) {
      maxDdx = tilemap_width;
   }
   if (tilemap_height < maxDdy) {
      maxDdy = tilemap_height;
   }
   int8_t startDdx = (-x) / tile_width;
   int8_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 (uint8_t ddy = startDdy; ddy < maxDdy; ddy++) {
      for (uint8_t ddx = startDdx; ddx < maxDdx; ddx++) {
         int8_t drawX = ddx*tile_width + x + dx;
         int8_t drawY = ddy*tile_height + y + dy;
         uint8_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
            drawBitmap(drawX, drawY, tile_width, tile_height, spritesheet[tile], dx, dy, dw, dh, color);
         }
      }
   }
}

User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Tilemap function only shows one pixel of each bitmap

Postby Duhjoker » Tue Jan 31, 2017 8:53 am

Ok here's what's going on when I call the tilemap function. If I give the starting coordinates to 0 and 0 I get two thirds of a 6 X 6 tilemap, I also have three drawBitMap functions going in random places that I set that appear fully. If I give the tilemap start coordinates to say.....

110 and 170

The tilemap doesn't move but it appears smaller.

Code: Select all
#include <SPI.h>
#include <TFT_ILI93XX.h>

/*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
 MOSI:  11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
 MISO:  12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
 SCK:   13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
ESP8266-----------------------------------
Use:
#define __CS  16  //(D0)
#define __DC  5   //(D1)
#define __RST 4   //(D2)

 SCLK:D5
 MOSI:D7
 */
#define __CS1    10
#define __DC    9
/*
Teensy 3.x can use: 2,6,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/

const byte blank_square[] PROGMEM ={16,16,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,};

const byte red_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};

const byte green_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};

 const byte blue_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};



 const byte yellow_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};


uint8_t errorCode = 0;

TFT_ILI93XX tft = TFT_ILI93XX(__CS1, __DC);


const byte tilemap1[] PROGMEM = {6,6,
16,16,
0,1,0,0,0,1,
1,0,0,0,1,0,
0,0,0,1,0,0,
0,0,1,0,0,0,
0,1,0,0,0,1,
1,0,0,0,1,0};

const byte tilemap2[] PROGMEM = {6,6,
16,16,
1,0,1,1,1,0,
0,1,1,1,0,1,
1,1,1,0,1,1,
1,1,0,1,1,1,
1,0,1,1,1,0,
0,1,1,1,0,1};

const byte *spritesheet1[] = {blank_square,green_square};
const byte *spritesheet2[] = {blank_square,blue_square};
const byte *spritesheet3[] = {blank_square,red_square};
const byte *spritesheet4[] = {blank_square,yellow_square};


void setup() {
   Serial.begin(38400);
   long unsigned debug_start = millis();
   while (!Serial && ((millis() - debug_start) <= 5000));
   Serial.println("serial ok, testing lib...");
  tft.begin();
  tft.setFrameRate(62);
  tft.persistence = false;
  //the following it's mainly for Teensy
  //it will help you to understand if you have choosed the
  //wrong combination of pins!
  errorCode = tft.getErrorCode();
  if (errorCode != 0) {
     Serial.print("Init error! ");
     if (bitRead(errorCode, 0)) Serial.print("MOSI or SCLK pin mismach!\n");
     if (bitRead(errorCode, 1)) Serial.print("CS or DC pin mismach!\n");
  }
  else {
     Serial.println("Inited");
  }
}

void loop(void) {
//updates the gamebuino (the display, the sound, the auto backlight... everything)
  //returns true when it's time to render a new frame (20 times/second)
   if(tft.update()){

   tft.drawTilemap(32,32,tilemap1,spritesheet1, GREEN);

   tft.drawTilemap(32,32,tilemap2,spritesheet4, YELLOW);

   tft.drawBitmap1(160,110,green_square,16,16,GREEN);

   tft.drawBitmap1(175,125,blue_square,16,16,BLUE);

   tft.drawBitmap1(195,145,green_square,16,16,RED);
   }
   }



Edit:::
I tested multiple stacked bitmaps in seperate colors today. I used my Dune games paul atreades. He sure was small but it worked. Still cant figure out the tile map. I hope some one can help with that soon.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Tilemap function only shows one pixel of each bitmap

Postby Duhjoker » Fri Feb 03, 2017 8:18 am

Can pretty please get some help figuring out why I can only display partial tilemaps using the tilemap feature. Im also having a drawbitmap at int x and int_y glitch as well that might be part of the tilemap problem.

I started a sketch with my 6x6 tilemap green and yellow then added some my paul atreades bitmaps and did all the walk stuff, then changed the player_x and player_x defines at the top 160 X 110 and barely moved from the original 50 and 50.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Tilemap function only shows one pixel of each bitmap

Postby naed » Fri Feb 03, 2017 5:00 pm

The hardest part of this is that your using bespoke hardware and libraries


My guess
If the screen resolution is larger then moving it over by 50 pixels is only going to move it a small distance, because the pixels are much smaller and as far as I'm aware your library is still only using pixels to place the sprites

Don't know if I explained that so you understand but it's the best I can explain it


It's also difficult to help because any suggestions/help we give will only be able to be tested by yourself... It's pretty much a guessing game without the hardware

**edit**

IMG_2255.JPG
IMG_2255.JPG (46.6 KiB) Viewed 10759 times


If your pixel sizes are different you can see from the above pic how moving from one corner to the other would give you different sizes/distances
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: Tilemap function only shows one pixel of each bitmap

Postby Duhjoker » Sat Feb 04, 2017 9:36 am

ok well I was able to get some bitmaps to show in the tile map array the other day and still can but its only showing about a third of the tilemap. here is a pic......

Image

ok so heres what I did to get that much

Code: Select all
#include <SPI.h>
#include <TFT_ILI93XX.h>

/*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
 MOSI:  11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
 MISO:  12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
 SCK:   13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
ESP8266-----------------------------------
Use:
#define __CS  16  //(D0)
#define __DC  5   //(D1)
#define __RST 4   //(D2)

 SCLK:D5
 MOSI:D7
 */
#define __CS1    10
#define __DC    9
/*
Teensy 3.x can use: 2,6,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/

//////Paul Atreides
const byte paul_front_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x62,0x46,0x40,0x02,0x30,0x0c,0x39,0x9c,0x40,0x02,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x11,0x88,0x0e,0x70};

const byte paul_front_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x0c,0x30,0x00,0x00,0x06,0x00,0x09,0x90,0x0e,0x70,0x00,0x00};

const byte paul_front_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x08,0x10,0x10,0x08,0x20,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x20,0x2f,0xf4,0x39,0x9c,0x0d,0xb0,0x07,0xe0,0x36,0x6c,0x31,0x8c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x00,0x00,0x10,0x08,0x00,0x00,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00};

//front walk
const byte paul_front_walk_1_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x62,0x46,0x40,0x02,0x30,0x0c,0x39,0x9c,0x40,0x02,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x11,0xf8,0x0e,0x00};

const byte paul_front_walk_1_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x0c,0x30,0x00,0x00,0x06,0x00,0x09,0x90,0x0e,0x00,0x00,0x00};

const byte paul_front_walk_1_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x0b,0xd0,0x1e,0x78,0x2d,0xb4,0x1b,0xd8,0x05,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_walk_1_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x07,0xe0,0x0d,0xb0,0x0d,0xb0,0x0f,0xf0,0x06,0x60,0x33,0xcc,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_walk_1_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x00,0x00,0x10,0x08,0x00,0x00,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//front walk 2
const byte paul_front_walk_2_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x62,0x46,0x40,0x02,0x30,0x0c,0x39,0x9c,0x40,0x02,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x1f,0x88,0x00,0x70};

const byte paul_front_walk_2_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x0c,0x30,0x00,0x00,0x00,0x60,0x09,0x90,0x00,0x70,0x00,0x00};

const byte paul_front_walk_2_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x08,0x10,0x10,0x08,0x20,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_walk_2_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x07,0xe0,0x0d,0xb0,0x0d,0xb0,0x0f,0xf0,0x06,0x60,0x33,0xcc,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_walk_2_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x00,0x00,0x10,0x08,0x00,0x00,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//left
const byte paul_left_black[] PROGMEM = {16,16,
0x00,0x00,0x03,0xe0,0x04,0x10,0x08,0x08,0x10,0x04,0x10,0x04,0x14,0x04,0x10,0x08,0x10,0x10,0x08,0x60,0x07,0xe0,0x02,0x20,0x03,0x20,0x04,0xe0,0x04,0x20,0x03,0xc0};

const byte paul_left_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x03,0xc0,0x00,0x00};

const byte paul_left_brown[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x01,0xa0,0x06,0xd0,0x01,0x68,0x00,0xb0,0x00,0x58,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_left_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x0f,0x00,0x0b,0x00,0x0b,0x60,0x0f,0xe0,0x07,0x80,0x00,0x00,0x00,0xc0,0x00,0xc0,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_left_yellow[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x02,0x40,0x01,0x20,0x08,0x90,0x00,0x48,0x00,0xa0,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//rear
const byte paul_rear_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x60,0x06,0x40,0x02,0x20,0x04,0x3a,0x5c,0x49,0x92,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x11,0x88,0x0e,0x70};

const byte paul_rear_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x60,0x00,0x00,0x06,0x60,0x09,0x90,0x0e,0x70,0x00,0x00};

const byte paul_rear_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x0b,0xd0,0x1e,0x78,0x2d,0xb4,0x1b,0xd8,0x05,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x0c,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x02,0x40,0x14,0x28,0x01,0x80,0x12,0x48,0x04,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//rear walk 1
const byte paul_rear_walk_1_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x60,0x06,0x40,0x02,0x20,0x04,0x3a,0x5c,0x49,0x92,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x11,0xf8,0x0e,0x00};

const byte paul_rear_walk_1_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x60,0x00,0x00,0x06,0x60,0x09,0x90,0x0e,0x00,0x00,0x00};

const byte paul_rear_walk_1_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x0b,0xd0,0x1e,0x78,0x2d,0xb4,0x1b,0xd8,0x05,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_walk_1_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x07,0xe0,0x0d,0xb0,0x0d,0xb0,0x0f,0xf0,0x06,0x60,0x33,0xcc,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_walk_1_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x02,0x40,0x14,0x28,0x01,0x80,0x12,0x48,0x04,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//rear walk 2
const byte paul_rear_walk_2_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x60,0x06,0x40,0x02,0x20,0x04,0x3a,0x5c,0x49,0x92,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x1f,0x88,0x00,0x70};

const byte paul_rear_walk_2_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x0c,0x30,0x00,0x00,0x00,0x60,0x09,0x90,0x00,0x70,0x00,0x00};

const byte paul_rear_walk_2_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x0b,0xd0,0x1e,0x78,0x2d,0xb4,0x1b,0xd8,0x05,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_walk_2_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x0c,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_walk_2_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x02,0x40,0x14,0x28,0x01,0x80,0x12,0x48,0x04,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//right
const byte paul_right_black[] PROGMEM = {16,16,
0x00,0x00,0x07,0xc0,0x08,0x20,0x10,0x10,0x20,0x08,0x20,0x08,0x20,0x28,0x10,0x08,0x08,0x08,0x06,0x10,0x07,0xe0,0x04,0x40,0x04,0xc0,0x07,0x20,0x04,0x20,0x03,0xc0};

const byte paul_right_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0xc0,0x03,0xc0,0x00,0x00};

const byte paul_right_brown[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x05,0x80,0x0b,0x60,0x16,0x80,0x0d,0x00,0x1a,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_right_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0xf0,0x00,0xd0,0x06,0xd0,0x07,0xf0,0x01,0xe0,0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_right_yellow[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x02,0x40,0x04,0x80,0x09,0x10,0x12,0x00,0x05,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//walk left
const byte paul_walk_left_black[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x03,0x80,0x0c,0x40,0x10,0x20,0x20,0x20,0x20,0x30,0x20,0x10,0x20,0x10,0x20,0x20,0x10,0xc0,0x0f,0xc0,0x3f,0x30,0x49,0x28,0x27,0xc8,0x1c,0x30};

const byte paul_walk_left_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x10,0x18,0x30,0x00,0x00};

const byte paul_walk_left_brown[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x0a,0x80,0x01,0x40,0x0c,0x80,0x01,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_walk_left_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x12,0x00,0x16,0x00,0x1e,0xc0,0x1f,0xc0,0x0f,0x00,0x00,0x00,0x00,0xc0,0x00,0xc0,0x00,0x00,0x00,0x00};

const byte paul_walk_left_yellow[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x80,0x05,0x40,0x10,0x80,0x01,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//walk right
const byte paul_walk_right_black[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x01,0xc0,0x02,0x30,0x04,0x08,0x04,0x04,0x0c,0x04,0x08,0x04,0x08,0x04,0x04,0x04,0x03,0x08,0x03,0xf0,0x0c,0xfc,0x14,0x92,0x13,0xe4,0x0c,0x38};

const byte paul_walk_right_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x6c,0x0c,0x18,0x00,0x00};

const byte paul_walk_right_brown[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0x50,0x02,0x80,0x01,0x30,0x02,0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_walk_right_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x48,0x00,0x68,0x03,0x78,0x03,0xf8,0x00,0xf0,0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00};

const byte paul_walk_right_yellow[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x40,0x02,0xa0,0x01,0x08,0x02,0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};



const byte blank_square[] PROGMEM ={16,16,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,};

const byte red_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};

const byte green_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};

 const byte blue_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};



 const byte yellow_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};


uint8_t errorCode = 0;

TFT_ILI93XX tft = TFT_ILI93XX(__CS1, __DC);


const byte tilemap1[] PROGMEM = {22,17,
16,16,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,};

const byte tilemap2[] PROGMEM = {22,17,
16,16,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,};


const byte *spritesheet1[] = {blank_square,green_square};
const byte *spritesheet2[] = {blank_square,blue_square};
const byte *spritesheet3[] = {blank_square,red_square};
const byte *spritesheet4[] = {blank_square,yellow_square};

  int player_x = 320;
  int player_y = 240;
  int player_direction = 2;

int x=-50,y=50;

void setup() {
   Serial.begin(38400);
   long unsigned debug_start = millis();
   while (!Serial && ((millis() - debug_start) <= 5000));
   Serial.println("serial ok, testing lib...");
  tft.begin();
  tft.setTextColor(WHITE);
  tft.titleScreen(F("test"));
  tft.setFrameRate(62);
  tft.persistence = false;
  //the following it's mainly for Teensy
  //it will help you to understand if you have choosed the
  //wrong combination of pins!
  errorCode = tft.getErrorCode();
  if (errorCode != 0) {
     Serial.print("Init error! ");
     if (bitRead(errorCode, 0)) Serial.print("MOSI or SCLK pin mismach!\n");
     if (bitRead(errorCode, 1)) Serial.print("CS or DC pin mismach!\n");
  }
  else {
     Serial.println("Inited");
  }
}

void loop(void) {
//updates the gamebuino (the display, the sound, the auto backlight... everything)
  //returns true when it's time to render a new frame (20 times/second)
   if(tft.update()){
    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++;}

 
   tft.drawTilemap(0,0,tilemap1,spritesheet1,0,0,340, 220, GREEN);
   tft.drawTilemap(0,0,tilemap2,spritesheet2,0,0,340, 220, BLUE);

     if(tft.buttons.repeat(BTN_UP,1)){
 tft.drawBitmap1(player_x, player_y,paul_rear_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_rear_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_rear_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_rear_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_rear_yellow,16,16,YELLOW);
     player_direction = 1;
      player_y = player_y - 1;}
    if(player_y <= 0){
      player_y = 0;}


    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;}


        if(tft.buttons.repeat(BTN_LEFT,0)){
   tft.drawBitmap1(player_x, player_y,paul_left_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_left_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_left_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_left_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_left_yellow,16,16,YELLOW);
       player_direction = 3;
      player_x = player_x - 1;}
    if(player_x <= -2){
      player_x = -2;}
     


  if(tft.buttons.repeat(BTN_RIGHT,2)){
   tft.drawBitmap1(player_x, player_y,paul_right_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_right_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_right_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_right_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_right_yellow,16,16,YELLOW);
        player_direction = 4;
         player_x = player_x + 1;}
    if(player_x >= 77){
      player_x = 77;}

     ////////////PLAYER DIRECTION/////////////

if (player_direction == 1){
     tft.drawBitmap1(player_x, player_y,paul_rear_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_rear_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_rear_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_rear_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_rear_yellow,16,16,YELLOW);
       
  }
       
     
      else if (player_direction == 2){
      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);
      }
else if (player_direction == 3){
       tft.drawBitmap1(player_x, player_y,paul_left_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_left_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_left_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_left_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_left_yellow,16,16,YELLOW);
}
      else if (player_direction == 4){
        tft.drawBitmap1(160,110,paul_right_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_right_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_right_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_right_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_right_yellow,16,16,YELLOW);
 
}
   }
}


also player direction works and im trying to get some buttons going.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Tilemap function only shows one pixel of each bitmap

Postby Duhjoker » Tue Feb 07, 2017 3:24 am

Ok could it be that I didn't have the coordinates set to int16_t inside the function parameters and also in the cpp parameters? Also does inline void drawpixel() have to be inline? Or can I give it a regular void?
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Tilemap function only shows one pixel of each bitmap

Postby Duhjoker » Mon Feb 20, 2017 3:23 am

All right I really need someone to just look at my code and see if you can see what the problem is. im trying to use player_x and player_y before the void set up but no matter what I do I cant get the bitmap player sprite to show up any other place than pixels 32 and 32.

I also cannot get the buttons to work or if they are they aren't showing the bitmap I want it to show. AND I CANT GET THE TILEMAP TO WORK. I have the function in the library the same exact way that its included in summoners library, I just changed the int's and uint's to 16 intead of 8. Ive run into this problem with every library ive tried to update and this is where I get stuck. Im so close!!!!!!!!!!!!!!!!!!!!!!!!!

PLEASE...... you shouldn't need the hardware to just look at what ive done and give me a second or third or fourth look so ican figure this out.

here is my sketch.,.......
Code: Select all
#include <SPI.h>
#include <TFT_ILI93XX.h>

/*
Teensy3.x and Arduino's
You are using 4 wire SPI here, so:
 MOSI:  11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
 MISO:  12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
 SCK:   13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
ESP8266-----------------------------------
Use:
#define __CS  16  //(D0)
#define __DC  5   //(D1)
#define __RST 4   //(D2)

 SCLK:D5
 MOSI:D7
 */
#define __CS1    10
#define __DC    9
/*
Teensy 3.x can use: 2,6,10,15,20,21,22,23
Arduino's 8 bit: any
DUE: check arduino site
If you do not use reset, tie it to +3V3
*/

uint8_t errorCode = 0;

TFT_ILI93XX tft = TFT_ILI93XX(__CS1, __DC);

//////Paul Atreides
const byte paul_front_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x62,0x46,0x40,0x02,0x30,0x0c,0x39,0x9c,0x40,0x02,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x11,0x88,0x0e,0x70};

const byte paul_front_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x0c,0x30,0x00,0x00,0x06,0x00,0x09,0x90,0x0e,0x70,0x00,0x00};

const byte paul_front_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x08,0x10,0x10,0x08,0x20,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x20,0x2f,0xf4,0x39,0x9c,0x0d,0xb0,0x07,0xe0,0x36,0x6c,0x31,0x8c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x00,0x00,0x10,0x08,0x00,0x00,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00};

//front walk
const byte paul_front_walk_1_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x62,0x46,0x40,0x02,0x30,0x0c,0x39,0x9c,0x40,0x02,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x11,0xf8,0x0e,0x00};

const byte paul_front_walk_1_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x0c,0x30,0x00,0x00,0x06,0x00,0x09,0x90,0x0e,0x00,0x00,0x00};

const byte paul_front_walk_1_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x0b,0xd0,0x1e,0x78,0x2d,0xb4,0x1b,0xd8,0x05,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_walk_1_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x07,0xe0,0x0d,0xb0,0x0d,0xb0,0x0f,0xf0,0x06,0x60,0x33,0xcc,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_walk_1_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x00,0x00,0x10,0x08,0x00,0x00,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//front walk 2
const byte paul_front_walk_2_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x62,0x46,0x40,0x02,0x30,0x0c,0x39,0x9c,0x40,0x02,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x1f,0x88,0x00,0x70};

const byte paul_front_walk_2_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x0c,0x30,0x00,0x00,0x00,0x60,0x09,0x90,0x00,0x70,0x00,0x00};

const byte paul_front_walk_2_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x08,0x10,0x10,0x08,0x20,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_walk_2_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x07,0xe0,0x0d,0xb0,0x0d,0xb0,0x0f,0xf0,0x06,0x60,0x33,0xcc,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_front_walk_2_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x00,0x00,0x10,0x08,0x00,0x00,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//left
const byte paul_left_black[] PROGMEM = {16,16,
0x00,0x00,0x03,0xe0,0x04,0x10,0x08,0x08,0x10,0x04,0x10,0x04,0x14,0x04,0x10,0x08,0x10,0x10,0x08,0x60,0x07,0xe0,0x02,0x20,0x03,0x20,0x04,0xe0,0x04,0x20,0x03,0xc0};

const byte paul_left_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x03,0xc0,0x00,0x00};

const byte paul_left_brown[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x01,0xa0,0x06,0xd0,0x01,0x68,0x00,0xb0,0x00,0x58,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_left_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x0f,0x00,0x0b,0x00,0x0b,0x60,0x0f,0xe0,0x07,0x80,0x00,0x00,0x00,0xc0,0x00,0xc0,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_left_yellow[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x02,0x40,0x01,0x20,0x08,0x90,0x00,0x48,0x00,0xa0,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//rear
const byte paul_rear_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x60,0x06,0x40,0x02,0x20,0x04,0x3a,0x5c,0x49,0x92,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x11,0x88,0x0e,0x70};

const byte paul_rear_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x60,0x00,0x00,0x06,0x60,0x09,0x90,0x0e,0x70,0x00,0x00};

const byte paul_rear_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x0b,0xd0,0x1e,0x78,0x2d,0xb4,0x1b,0xd8,0x05,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x0c,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x02,0x40,0x14,0x28,0x01,0x80,0x12,0x48,0x04,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//rear walk 1
const byte paul_rear_walk_1_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x60,0x06,0x40,0x02,0x20,0x04,0x3a,0x5c,0x49,0x92,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x11,0xf8,0x0e,0x00};

const byte paul_rear_walk_1_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x60,0x00,0x00,0x06,0x60,0x09,0x90,0x0e,0x00,0x00,0x00};

const byte paul_rear_walk_1_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x0b,0xd0,0x1e,0x78,0x2d,0xb4,0x1b,0xd8,0x05,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_walk_1_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x07,0xe0,0x0d,0xb0,0x0d,0xb0,0x0f,0xf0,0x06,0x60,0x33,0xcc,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_walk_1_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x02,0x40,0x14,0x28,0x01,0x80,0x12,0x48,0x04,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//rear walk 2
const byte paul_rear_walk_2_black[] PROGMEM = {16,16,
0x07,0xe0,0x08,0x10,0x10,0x08,0x20,0x04,0x20,0x04,0x20,0x04,0x60,0x06,0x40,0x02,0x20,0x04,0x3a,0x5c,0x49,0x92,0x4f,0xf2,0x39,0x9c,0x16,0x68,0x1f,0x88,0x00,0x70};

const byte paul_rear_walk_2_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x00,0x00,0x0c,0x30,0x00,0x00,0x00,0x60,0x09,0x90,0x00,0x70,0x00,0x00};

const byte paul_rear_walk_2_brown[] PROGMEM = {16,16,
0x00,0x00,0x06,0x60,0x0d,0xb0,0x17,0xe8,0x1d,0xb8,0x0b,0xd0,0x1e,0x78,0x2d,0xb4,0x1b,0xd8,0x05,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_walk_2_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x0c,0x30,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_rear_walk_2_yellow[] PROGMEM = {16,16,
0x00,0x00,0x01,0x80,0x02,0x40,0x08,0x10,0x02,0x40,0x14,0x28,0x01,0x80,0x12,0x48,0x04,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//right
const byte paul_right_black[] PROGMEM = {16,16,
0x00,0x00,0x07,0xc0,0x08,0x20,0x10,0x10,0x20,0x08,0x20,0x08,0x20,0x28,0x10,0x08,0x08,0x08,0x06,0x10,0x07,0xe0,0x04,0x40,0x04,0xc0,0x07,0x20,0x04,0x20,0x03,0xc0};

const byte paul_right_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0xc0,0x03,0xc0,0x00,0x00};

const byte paul_right_brown[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x05,0x80,0x0b,0x60,0x16,0x80,0x0d,0x00,0x1a,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_right_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0xf0,0x00,0xd0,0x06,0xd0,0x07,0xf0,0x01,0xe0,0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_right_yellow[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x02,0x40,0x04,0x80,0x09,0x10,0x12,0x00,0x05,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//walk left
const byte paul_walk_left_black[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x03,0x80,0x0c,0x40,0x10,0x20,0x20,0x20,0x20,0x30,0x20,0x10,0x20,0x10,0x20,0x20,0x10,0xc0,0x0f,0xc0,0x3f,0x30,0x49,0x28,0x27,0xc8,0x1c,0x30};

const byte paul_walk_left_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x10,0x18,0x30,0x00,0x00};

const byte paul_walk_left_brown[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x0a,0x80,0x01,0x40,0x0c,0x80,0x01,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_walk_left_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x00,0x12,0x00,0x16,0x00,0x1e,0xc0,0x1f,0xc0,0x0f,0x00,0x00,0x00,0x00,0xc0,0x00,0xc0,0x00,0x00,0x00,0x00};

const byte paul_walk_left_yellow[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x80,0x05,0x40,0x10,0x80,0x01,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

//walk right
const byte paul_walk_right_black[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x01,0xc0,0x02,0x30,0x04,0x08,0x04,0x04,0x0c,0x04,0x08,0x04,0x08,0x04,0x04,0x04,0x03,0x08,0x03,0xf0,0x0c,0xfc,0x14,0x92,0x13,0xe4,0x0c,0x38};

const byte paul_walk_right_blue[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x6c,0x0c,0x18,0x00,0x00};

const byte paul_walk_right_brown[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,0x50,0x02,0x80,0x01,0x30,0x02,0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte paul_walk_right_pink[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x48,0x00,0x68,0x03,0x78,0x03,0xf8,0x00,0xf0,0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00};

const byte paul_walk_right_yellow[] PROGMEM = {16,16,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x40,0x02,0xa0,0x01,0x08,0x02,0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

const byte blank_square[] PROGMEM ={16,16,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,
 B00000000,B00000000,};

const byte red_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};

const byte green_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};

 const byte blue_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};



 const byte yellow_square[] PROGMEM ={16,16,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,
 B11111111,B11111111,};

const byte tilemap1[] PROGMEM = {22,17,
16,16,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,};

const byte tilemap2[] PROGMEM = {22,17,
16,16,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,};


const byte *spritesheet1[] = {blank_square,green_square};
const byte *spritesheet2[] = {blank_square,blue_square};
const byte *spritesheet3[] = {blank_square,red_square};
const byte *spritesheet4[] = {blank_square,yellow_square};

int  player_x = 160;
int  player_y = 110;
int   player_direction = 2;
int x=0,y=0;

void setup() {
   Serial.begin(38400);
   long unsigned debug_start = millis();
   while (!Serial && ((millis() - debug_start) <= 5000));
   Serial.println("serial ok, testing lib...");
  tft.begin();
  tft.setFrameRate(62);
  tft.persistence = false;
  //the following it's mainly for Teensy
  //it will help you to understand if you have choosed the
  //wrong combination of pins!
  errorCode = tft.getErrorCode();
  if (errorCode != 0) {
     Serial.print("Init error! ");
     if (bitRead(errorCode, 0)) Serial.print("MOSI or SCLK pin mismach!\n");
     if (bitRead(errorCode, 1)) Serial.print("CS or DC pin mismach!\n");
  }
  else {
     Serial.println("Inited");
  }
}

void loop(void) {
     if(tft.updateAll()){
    if (tft.buttons.repeat(BTN_RIGHT,2));//{x--;}
    if (tft.buttons.repeat(BTN_LEFT,0));//{x++;}
    if (tft.buttons.repeat(BTN_DOWN,3));//{y--;}
    if (tft.buttons.repeat(BTN_UP,1));//{y++;}

//     tft.drawTilemap(22,17,tilemap1,spritesheet1, GREEN);
//  tft.drawTilemap(22,17,tilemap2,spritesheet2, BLUE);

       if(tft.buttons.repeat(BTN_UP,1)){
 tft.drawBitmap1(player_x, player_y,paul_rear_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_rear_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_rear_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_rear_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_rear_yellow,16,16,YELLOW);

         player_direction = 1;
      player_y = player_y - 1;}
    if(player_y <= 0){
      player_y = 0;}
     
     
    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;}
 

     
         if(tft.buttons.repeat(BTN_LEFT,0)){
   tft.drawBitmap1(player_x, player_y,paul_left_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_left_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_left_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_left_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_left_yellow,16,16,YELLOW);

      player_direction = 3;
      player_x = player_x + 1;}
    if(player_x >= 77){
      player_x = 77;}


  if(tft.buttons.repeat(BTN_RIGHT,2)){
   tft.drawBitmap1(player_x, player_y,paul_right_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_right_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_right_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_right_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_right_yellow,16,16,YELLOW);

   player_direction = 3;
      player_x = player_x + 1;}
    if(player_x >= 77){
      player_x = 77;}

     ////////////PLAYER DIRECTION/////////////

if (player_direction == 1){
     tft.drawBitmap1(player_x, player_y,paul_rear_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_rear_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_rear_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_rear_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_rear_yellow,16,16,YELLOW);
       
  }
       
     
      else if (player_direction == 2){
      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);
      }
else if (player_direction == 3){
       tft.drawBitmap1(player_x, player_y,paul_left_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_left_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_left_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_left_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_left_yellow,16,16,YELLOW);
}
      else if (player_direction == 4){
        tft.drawBitmap1(player_x, player_y,paul_right_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_right_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_right_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_right_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_right_yellow,16,16,YELLOW);
 

 
   }
 }
}



maybe its a typo or something im missing from the sketch. idk but I need someone to be serious for a minute PLEASE


EDIT::
ok so I fixed the player_x, player_y problem and now he shows up at the coordinates entered. kind of.....I had to comment out the walk bits. I tried several ways to include them properly, I know its punctuation but I cant figure out. I tried adding more "}" and less but I cant figure out to include them right. For example......

Code: Select all
       if(tft.buttons.repeat(BTN_UP,1)){
 tft.drawBitmap1(player_x, player_y,paul_rear_black,16,16,BLACK);
    tft.drawBitmap1(player_x, player_y,paul_rear_blue,16,16,BLUE);
     tft.drawBitmap1(player_x, player_y,paul_rear_brown,16,16,BROWN);
      tft.drawBitmap1(player_x, player_y,paul_rear_pink,16,16,PINK);
       tft.drawBitmap1(player_x, player_y,paul_rear_yellow,16,16,YELLOW);

         player_direction = 1;}
//      player_y = player_y - 1;}
//    if(player_y <= 0){
//      player_y = 0;}


ok so with the comments above removed I get nothing and back to 32 and 32. but now I cant move him.

ok but I did the the button problem fixed as well. I had forgot to add the update and begin the latter being first to the begin. but wait that didn't work. I actually had to add buttons.begin and buttons.update to the sketches void setup. but now when I press a button the bitmap changes to reflect that direction.
Attachments
TFT_ILI93XX-master2.0.zip
(225.78 KiB) Downloaded 474 times
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Tilemap function only shows one pixel of each bitmap

Postby Duhjoker » Tue Apr 11, 2017 6:23 am

Ok so I'm building a library that includes ESP32 as well as every thing else. God I feel stupid but I think I might have fixed the time map function. Summoner123 original tilemap had/has an inline drawBitMap function with parameters (X,Y,W,H,bitmapname). But I remember I was having trouble with that particular bitMap function and decided to just change the order of the insides of the parameters to match an existing working function. I can't test it quite yet but I hope I fixed it. I finally found a bitMap function that matches the one used in the tilemap routine.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 11 guests

cron