drawBitmap offscreen? [Learning about Integers]

Hi, I’ve been playing with the idea of a platform game on Arduboy, but when I try to draw my sprite transitioning onto the screen, it just refuses to draw. Unless the top left pixel is on screen I get nothing. I can’t quite figure out how the drawBitmap function works, but surely this is a bug? It draw fine when exiting the screen on the bottom or right.

Any clues?

That’s by default in the arduboy lib. Out of performance reasons it won’t draw anything off screen.
You can change the implementation with bigger bounds or write your own draw method.

I figured it wouldn’t draw any pixels off screen, but those pixels that are on screen should be draw surely? If a sprite can be drawn half off the right of the screen, why not half off the left?

So the issue is drawing things with locations of negative numbers?

@MLXXXp and @crait what is your suggestion for this?

That’d be it, should have thought of that first! Fixed, no issue at all, silly me :slight_smile:

I’m under the impression that as long as some portion of an object is on the screen then it should draw that portion to the screen buffer. This should apply to all objects, including bitmaps and sprites. If not, I’d consider it a bug, or at least a design oversight.

There’s “catch all” code at the beginning of drawBitmap() to do nothing if the bitmap is entirely off screen, but unless it’s not working properly it shouldn’t prevent partially on screen bitmaps from drawing.

  // no need to draw at all if we're offscreen
  if (x+w < 0 || x > WIDTH-1 || y+h < 0 || y > HEIGHT-1)
    return;

I’ll look into it if I get some time but I can’t say when that will be. If someone else wants to investigate and finds the problem, I’ll make changes to the Arduboy2 library.

yeah, I was using byte for my x,y variables, rather than signed char. So negative number was really a much larger positive.

Using negative x or y coordinates should be fine as long as the object falls within the boundaries of a signed 16 bit integer. The library should treat the screen’s top left corner (coordinate 0, 0) as being at the centre of that larger grid.

OK, now I understand. Glad you found the problem and it’s not in the library! :smile:

I’ve been in this boat so many times before it went from being funny, to not funny, back to being funny again.

1 Like