6 years ago
Hi,
Beginner question: I've made a small function that slides in an image from the top of the screen. When I call it, I want to send the bitmap name as a parameter, but it doesn't work and displays nothing. I suspect it's because the string in the parameter is in the wrong format so it gets ignored in the function, but cannot find a way to get it to work. Can anyone see what's wrong?
function:
void slideIn(char myimg[]) { gb.display.drawBitmap(0,y,myimg); if (i <21) { i = ++i; y = y + (easing[i]); } }
and then I call it this way:
slideIn("img1");
NEW 6 years ago
Hi,
drawBitmap needs a pointer to the bitmap array - not the name of that array (after compilation the name isnt there anymore) see https://gamebuino.com/academy/reference/graphics-drawbitmap for usage (works basically with legacy gamebuino too - except the meta stuff like yellow color ;))
NEW 6 years ago
Thanks for your answer. Concretely how do I send a pointer to the bitmap array to the function, not just the name of the array? I can't see anything different from what I'm doing on the reference page.
NEW 6 years ago
Try this:
void slideIn(uint8_t* myimg) { gb.display.drawBitmap(0,y,myimg); if (i <21) { i = ++i; y = y + (easing[i]); } }
and then
slideIn(img1);
The difference here is, that you don't pass a string "img1" to the function, but the pointer to the actual buffer itself. A string of a name of a variable is something totally different than a variable
NEW 6 years ago
Thanks! I got it now. It works with the uint8_t* data type and it also works with byte, which I was using initially:
void slideIn(byte myimg[]) { gb.display.drawBitmap(0,y,myimg); if (i <21) { i = ++i; y = y + (easing[i]); } }
and then:
slideIn(img1);