Learning to FX with bouncing balls

This thread will be for beginners who want to learn by example, modifying others code to learn how the library works so far.

For this example I’ll be using the bouncing balls demo from @Mr.Blinky posted here:

The goals for this thread will be:

  1. Understand the file structure and tools, how to load an FX game onto the Dev Kit
  2. Basic understanding of the library functions within the sketch
  3. How to modify and create new assets within the external memory bin file (how to change and add sprites)

Specifically I’d like to change all the bouncing balls to be different pokemon or otherwise sprites that all have at least 3 maybe 4 frames of animation.


This is a great idea for those who have become lost in the other conversations (me!).


And me!​​​​

1 Like

I’ve been involved in some of the other conversations and I’m still somewhat lost. :P

Going to get a walkthrough live from @mr.blinky in chat on twitch tomorrow at 2pm pacific time.

If there is a better time that works for you and you really want to attend please post it up.

The video will be archived if you cannot.

The stream was great here is a link to the full video:

I will be editing it soon to clip out some stuff like when I go to the bathroom. Here is everything that we accomplished in the video with some notes:

  1. Install Arduino
  2. Install Python
  3. Download Game
  4. Install Arduboy2 Library
  5. Run Flash Cart Test
  6. Get pyhton utilities from github
    install into working directory
    make sure python is set in path
    Path = %CD%Python;%CD%Python\Scripts;%PATH%
  7. Install pyserial
    python -m pip install pyserial
  8. Test if pyserial works
    python eeprom-backup.py
  9. Upload video
    python flashcart-writer.py -d .\flashcart\test-sketch\thedoor-frames.bin
  10. Upload ball data
    use memory location 0xE948
    python flashcart-writer.py 59720 .\flashcart\test-sketch\drawballs-test\drawballs-test.bin
  11. Edit sketch for new location
    #define PROGRAM_DATA_PAGE 0xE948
  12. Flash ball test sketch
1 Like

You can change python flashcart-writer.py 59720 .\flashcart\test-sketch\drawballs-test\drawballs-test.bin to python flashcart-writer.py 0xE948 .\flashcart\test-sketch\drawballs-test\drawballs-test.bin now if you want.

@Mr.Blinky has added numeric base detection to flashcart-writer.py.

(Also I believe he’s solved the problem that was causing the balls to not render properly.)

Anyone seeing RX/TX blinking? I have that on my one where the bouncing balls is still working, but I haven’t uploaded the data with the new tool so I suppose it’s possible it’s still partially corrupted?

Some notes:
(Windows guide)
1: Download and install Arduino
2: Download Python 2.7.xx and install (check add to windows path option during install)

10: use flashcart-writer.py -d .\flashcart\test-sketch\drawballs-test\drawballs-test.bin

11: not needed

There was a bug in the flashcart-writer.py script that required using a different address to store the datafile. This has been fixed now.

The LED blinks because nextFrameDEV() is used. Whenever a frame is delayed the LED is turned on. The blinking is caused by your PC interrupting Arduboy by ‘pinging’ it over USB. When you disconnect USB the blinking stops.

You can change arduboy.nextFrameDEV() into arduboy.nextFrame() to stop the LED from blinking when connected to USB.

Oh nextFrameDEV has a serial console output if it misses a frame?

No it just turns the LED on

Not totally sure the best place to put it, but I did some experiments and perceptable slowdown seems to appear between 80 and 90 sprites being drawn on the screen at the same time.

Even with 128 sprites I think it was still getting 30fps.

Yep 55 balls was the threshold to stay at 60fps in all situations with the moving background. by adding a few more balls you don’t have a complete frame skip just a small frame delay. Slow down becomes noticable when you add a lot more balls.

if the balls where full square sprites they could be drawn as normal bitmap/tiles without a mask and you could have even more.( a tile/bitmap can be any pixel size not just a multiple of 8)

Oh by the way it seems like your flash utilities work just fine without the Arduino drivers installed. Which is super duper good news :slight_smile:

Was working on multiple sprites for the balls and discovered a bug in the code, here is the asset I created.


The problem is every other (after 1) sprite has the wrong start offset by 8 pixels too many from the top. So
i=0 no problem
i=1 no problem
i=2 problem
i=3 no problem
i =4 problem…

It’s a bug in cart.cpp line 447:

uint24_t offset = (uint24_t)(frame * (height+7) / 8 + skiptop) * width + skipleft;

should be:

uint24_t offset = (uint24_t)(frame * ((height+7) / 8) + skiptop) * width + skipleft;
There were brackets missing around (height+7) / 8

For what it’s worth, this is why I put brackets around every sub expression.
I don’t even have to think about the order of operations because I make it explicit every time.
Ever since I started doing that I’ve never had an order-of-operations related bug.
(As far as I can remember.)

1 Like

Wicked! We learned in the stream that making sprite sheets works but a little advancements in the tool will make using it a walk in the park. Right now its kind of a headache with a lot of manual calculating and setting of memory offsets and orders.

Nice, I tested it! It works great! This is so exciting!