Help with 8Bit Etch-a-Sketch problem

Hi guys,

I’m writing my first game with Arduboy and it’s going to be an Etch-a-Sketch type game. I’ve reached a point where I’m not sure how I can achieve the following:

When the player reduces there brush size to 0, I want to display their cursor position with a cursor (circle outline or an X type cursor) so they can move around the screen without drawing and then increase the size to continue drawing.

I’ve managed to get this working however in my program, I never use arduboy.clear(), hence getting the effect of the drawing (constantly printing circles in the location of the users ‘cursor’ position, allowing them to draw). Therefore I want to almost ‘capture’ the screen, save it in memory, allow the player to move the cursor, and then reprint there drawing and loop this until the user decides to draw again, this means when I move the cursor, it won’t leave a trail behind it.

Unless there is another way to draw a circle or rectangle without permanently editing the pixels underneath. (like drawing a sprite over the background).

Or am I doing this completely wrong and should take a different approach?

Thanks in advanced

Jack

…this might help?

1 Like

Hey uXe,

After looking at the code I’ve realized that I need to look at it in a different way! Didn’t know about the Pixel commands!

Thank you for linking me to that project

Best regards,

Jack Daly

The easiest solution would be to create a second screen buffer,
but that would chew up a large chunk of memory.
If you avoided nesting functions too deeply and didn’t have many variables then it might work,
but that’s still a tad risky because it doesn’t leave you with much memory.

A more difficult but more efficient solution would be to have a smaller buffer, about as large as your cursor,
save the area of the screen buffer that you’re about to overwrite by drawing your cursor to that secondary buffer,
then when you move the cursor you copy the second buffer back to the main buffer,
and it will look exactly how it looked before you drew the cursor.
Again, it’s efficient but it’s quite difficult,
primarily because of the 1-bit-per-pixel format of the screen buffer.

Does that make sense at all?


(Now I think about it, you could cheat a bit to make the second approach easier by just copying several whole rows of the screen instead of an exact rectangle. Still a tad difficult, but it’s simpler.)

Hi Pharap,

The way i ended up doing it was with the GetPixel and DrawPixel commands. I was looking into the buffer methods as you stated but I don’t know enough about how that works to understand how to save the buffer and then further rewrite it (that was my original plan). I played around with it for a bit but concluded with the alternate method of using the DrawPixel command. I couldn’t figure out a way to actually save the buffer itself.

Best regards,

Jack Daly

1 Like

That’s fine too.

Using getPixel and drawPixel will also work and is simpler,
but will also be slightly less efficient.
(Presumably that means you’re copying the values to a 2D array of uint8_t or bool?)

If that’s working for you and you’re happy with it then don’t worry too much about saving the buffer.
But if you want to know more about saving and restoring fragments of the buffer then feel free to ask.

(I will however note that the buffer can be accessed either directly (as an array) with Arduboy2::sbuffer or indirectly (as a pointer) with arduboy.getBuffer(), as that information might be useful to you later on.)