In the last post we covered basic drawing on the Gameboy Advance screen using Sniff. That works fine, but at some point you'll probably want to make some "real" artwork, as a bitmap, and draw it on the screen. You might also want to add sound. Both of these are pretty easy if you're familiar with Sniff on a PC, as there are GBA equivalents of the Sound and Bitmap devices.
We've covered these previously, but they're pretty easy to use. To draw a bitmap on the screen:
make display gbaScreen device 4
make displayX number
make displayY number
make img bitmap device
make fileData string
when start
.tell display to "clear"
.
.set fileData to "Castle.bmp"
.tell img to "load"
.set displayX to 100
.set displayY to 80
.tell img to "draw"
First we need too set up the graphics screen, so that we have somewhere to draw. Then create a bitmap device. Set the image name, and tell the bitmap to load it, and then we can draw it at specific coordinates on the screen.
There are a couple of differences between the Bitmap device on a computer and on the gameboy, but these probably shouldn't affect your games. Firstly the bitmap is "read only". For example in SniffPaint we actually create the contents of a bitmap device inside the program before saving it out. On GBA that's not possible due to the way data is stored. The other thing you can't do is rotate bitmaps. On a PC you can tell the bitmap to rotate, and draw it at a jaunty angle... On the GBA this was just too slow, and it was slowing down all of the drawing code, so we removed it. However in the next post we'll talk about sprites, which can do this super quick and easily!
Sounds work just the same way:
make player sound device
make fileData string
when start
.set fileData to "WinSound.raw"
.tell player to "load sound"
.forever
..tell player to "play"
..wait 10 secs
They play 8 bit signed raw audio data at 16KHz Mono, but otherwise they behave just like on other platforms.
However there's one thing we've glossed over (and the reason I'm writing about both of these together)... On a PC the bitmap and the audio data get loaded from files, but the GBA is a games console - it doesn't have files, so where does the data come from?
It needs to be made into an "asset bundle" which gets added to your program. Fortunately we've got a bunch of scripts which make it really easy. In the folder your working in, create a folder called "Images" and put bmp files in there. Similarly create a "Sounds" folder and add ".raw" files containing the audio. Then in the main folder type "gbaBundleAssets". If all goes well this will create a file called "ASSETSBUNDLE", which will automatically be included in your game.
If you get an error about commands not being found then go to the folder examples/GBA/tools and run installIDE to compile and install the bitmap conversion tools, which are written in Sniff. These pre-process the images into the format needed for inclusion.
And that's all there is to drawing bitmaps and playing sounds on a Gameboy Advance.
No comments:
Post a Comment