Here I am, the tree with that can be found here: https://github.com/Sorunome/Gamebuino/tree/tilemapper
It allows for things like this:
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
// define some sprites
const byte sprite0[] PROGMEM = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
const byte sprite1[] PROGMEM = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
// define the spritesheet
const byte *spritesheet[] = {sprite0,sprite1};
// define the tilemap
const byte tilemap[] PROGMEM = {12,12,
8,8,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,1,0,1,0,
};
void setup() {
// put your setup code here, to run once:
gb.begin();
gb.titleScreen(F("test"));
gb.display.clear();
gb.display.drawTilemap(-3,-1,tilemap,spritesheet,4,4,76,30); // draw the tilemap
gb.display.drawRect(2,2,80,34);
gb.display.update();
}
void loop() {
// put your main code here, to run repeatedly:
}
Now, as you can see gb.display.drawTilemap(); is the new function.
the last four parameters are optional, here is how stuff is working:
gb.display.drawTilemap(x,y,tilemap,spritesheet[,drawX,drawY,drawWidth,drawHeight]);
so, tilemap and spritesheet should be pretty straight forward, x and y are for offsets, so that if y is -5 for example the whole tilemap is displayed five pixels up, that is so that you could easily make it so that a character walks around and the tilemap moves.
Now, what are those mysterious last four parameters? If defined the tilmap will ONLY be rendered in that area! Be sure to note that x/y is actually relative to drawX/drawY.
That means that something like gb.display.drawTilemap(x,y,tilemap,spritesheet,0,0,LCDWIDTH,LCDHEIGHT-8); for example would always leave the lower 8 pixels of the screen free, so you could, for example, draw some stats there!
I hope you enjoy!
Oh, also, any-sized tiles are allowed, in the tilemap definition the first two numbers are width/height of the tilemap, the second two width/height of the tiles! The tiles themselves don't have any width/height stored to save space.
EDIT: Also rodot, as my browser is acting up right now i can't create a pull request :/