Some handheld gaming hardware that's compatible with MakeCode Arcade includes one or more NeoPixel RGB LEDs. The PyGamer and PyBadge each have a strip of five NeoPixels located just below the display screen, while the PyBadge LC has a single NeoPixel.
Or, get really fancy and plug in external NeoPixels to the PyGamer or PyBadge/PyBadge LC JST connector port!
You can use these to great effect in your games! Flash lights when you blow up an enemy, show the player sprite's life/hearts meter, or display rainbow effects when a player sets a new high score!
Here's what you need to know to use the NeoPixels in your MCA games.
Add Extension
First, open the Advanced category section and click on the Extensions item.
Next, click on the light extension, which adds the blocks we need.
Click the Light category to see the available blocks.
In order to simply light up the five NeoPixels on, say, the PyGamer, here's one arrangement that'll do that.
- set pixels length to 5 pixels
- set brightness to 10
- set all pixels to magenta
By setting the proper pixel length of the strip we can then use the graphing, animation, and other blocks accurately.
Here's a very simple way to light up specific NeoPixels when you press the left button or A button.
Life Meter
In order to tie the NeoPixel bar to the health status in a typical MCA game, I lit the first three NeoPixels to red, and then added these blocks to the loop that's run when the player loses a life (in this case from overlapping an un-needed component).
First, set the brightness high, then set the NeoPixel to black at the same index as the current life number, and finally return the brightness to a moderate level. It's pretty simple!
You can add all kinds of other effects using the NeoPixel animation block and run them when different events occur in the game.
Page last edited March 08, 2024
Text editor powered by tinymce.