Cast your mind back to the opening title of Sonic the Hedgehog. As the game loaded, the title screen went from an entirely black screen to our spiky blue friend and his impressive logo. This is a technique which can be performed fairly simply and using the knowledge that we have previously learned regarding the VDU.
Note: We are going to be using the Same moon.bmp resource as the the previous lesson – so you can utilise the same resource file
The idea behind this code is to place one background image on the screen as we did in the previous lesson. In order for the Fade in to Work correctly, I need to initialise a few things first.
I create a vector palette_complete with 64 positions, it is in this vector that I will save the colour value of the palettes of the images. I will collect these later.
Before loading the images, with VDP_setPaletteColors and the SGDK constant palette_black, we set each and every one of the palette colours to black. When we load the image, all the values of the palette are black. On screen we simply see a black image – even though the images and tiles are already loaded into memory.
Next we collect the palettes of the image and keep a copy of their values in the vector palette_complete using memcopy. The two palettes (black and full colour) are stored in the palette_complete array at indexes 0 and 16.
The values of the two palettes are now stored in the Vector – not in the VDP
To perform the Fade In, I use VDP_fadeIn() and the SGDK will modify the palettes so that they end up having the same value as the values stored in the complete_palette.
The Handle Input Function
I have also declared and included a function which will detect key presses on the Megadrive’s joypad. This is to help to begin to get an understanding of how we detect any input from the controller so that we can begin to animate and move images in later lessons.
So here we read the input of the controller by JOY_readJoypad(JOY_1). This grabs the input from the controller plugged into port 1 of the Megadrive. We use simple IF statements to check what is being pressed (if anything) each frame and output the corresponding directional or button pressed as text.
If nothing is pressed we clear what text was already on the screen.
If everything has gone to plan you should observe the following on your Megadrive / Emulator.