256 Colour Tutorial Part 2(V2.62): Difference between revisions

m
no edit summary
mNo edit summary
Line 35: Line 35:
[[Image:8bittut_dizzypal.png]]
[[Image:8bittut_dizzypal.png]]


You may have noticed that, I used the "rainbow" colours in slots 240 through 253 (the first 14 slots in the last line of the above palette) to draw the "warping frame" of the background, if the colours of these slots are altered the colours of that "warping frame" will be changed accordingly (you can load the background into a graphics programme and play with the colours of these slots and see what will happen). To make an animated effect, you may try using the function '''CyclePalette()''' with ''starting slot'' 240 and ''ending slot'' 253. Here's a graphical illustration of what will happen if you do that:
You may have noticed that, I used the "rainbow" colours in slots #240 through #253 (the first 14 slots in the last line of the above palette) to draw the "warping frame" of the background, if the colours of these slots are altered the colours of that "warping frame" will be changed accordingly (you can load the background into a graphics programme and play with the colours of these slots and see what will happen). To make an animated effect, you may try using the function '''CyclePalette()''' with ''starting slot'' #240 and ''ending slot'' #253. Here's a graphical illustration of what will happen if you do that:


[[Image:8bittut_dizzypalcp.png]]
[[Image:8bittut_dizzypalcp.png]]
Line 47: Line 47:
Save the script and compile the game to test it, you'll notice that whenever you press the '''Space Bar''', the colours of the "warping frame" changes, this is due to the shift in colours in the mentioned 14 colour slots. If you keep the '''Space Bar''' pressed you'll see a smooth colour rotation animation.
Save the script and compile the game to test it, you'll notice that whenever you press the '''Space Bar''', the colours of the "warping frame" changes, this is due to the shift in colours in the mentioned 14 colour slots. If you keep the '''Space Bar''' pressed you'll see a smooth colour rotation animation.


I'm not satisfied with this yet, now I want the water at the centre to fall ''continuously'', what can we do now? Again, we can use '''CyclePalette()''', we can use this in the '''repeatedly_execute()''' or the '''repeatedly_execute _always()''' events for the continuous motion. Now, check back the background, note that the waterfall was carefully drawn using colours ''mostly'' from slot 208 through 215. I want the animation to play without ''any'' interruptions, so I add the following into the room script:
I'm not satisfied with this yet, now I want the water at the centre to fall ''continuously'', what can we do now? Again, we can use '''CyclePalette()''', we can use this in the '''repeatedly_execute()''' or the '''repeatedly_execute _always()''' events for the continuous motion. Now, check back the background, note that the waterfall was carefully drawn using colours ''mostly'' from slot #208 through #215. I want the animation to play without ''any'' interruptions, so I add the following into the room script:
   function repeatedly_execute_always() {
   function repeatedly_execute_always() {
     CyclePalette(208, 215);
     CyclePalette(208, 215);
Line 87: Line 87:
[[Image:8bittut_sprite0.png]]
[[Image:8bittut_sprite0.png]]


If you check, you'll see that the red tips of her antennae were drawn using colour slot 32. Suppose you want them to alter between black and red colours endlessly throughout the ''whole game'', what we can do is, in each game loop, if the colour of slot 32 is currently <font color='FF0000'>red</font> change it to <font color='000000'>black</font> (where (r, g, b) tuple equals (0, 0, 0) ) , ''else'' change it to <font color='FF0000'>red</font> (where (r, g, b) tuple equals (63, 0, 0) ). This logic can be visualised as follow:
If you check, you'll see that the red tips of her antennae were drawn using colour slot #32. Suppose you want them to alter between black and red colours endlessly throughout the ''whole game'', what we can do is, in each game loop, if the colour of slot #32 is currently <font color='FF0000'>red</font> change it to <font color='000000'>black</font> (where (r, g, b) tuple equals (0, 0, 0) ) , ''else'' change it to <font color='FF0000'>red</font> (where (r, g, b) tuple equals (63, 0, 0) ). This logic can be visualised as follow:


First, on top of the ''Global Script'':  
First, on top of the ''Global Script'':  
Line 104: Line 104:


Save your script and test the game, you may notice two things:
Save your script and test the game, you may notice two things:
# Though the girl's shoes were also painted in red, their colours won't flash with her antennae, since I didn't use slot 32 when painting her shoes. If you check this in the room with the [[media:8bittut_disco.pcx|"disco" background]], you'll see that the red "light" on the door lock won't flash either, because of the same reason.
# Though the girl's shoes were also painted in red, their colours won't flash with her antennae, since I didn't use slot #32 when painting her shoes. If you check this in the room with the [[media:8bittut_disco.pcx|"disco" background]], you'll see that the red "light" on the door lock won't flash either, because of the same reason.
# If you place also the alien sprite in a room, you may notice that his fingertip flashes also, this is because I also used colour slot 32 there. If you check the room with the [[media:8bittut_disco.pcx|"disco" background]], you'll find out that a pixel just about the disco ball flashes also.
# If you place also the alien sprite in a room, you may notice that his fingertip flashes also, this is because I also used colour slot #32 there. If you check the room with the [[media:8bittut_disco.pcx|"disco" background]], you'll find out that a pixel just about the disco ball flashes also.
   
   
Combining the above observations I hope you can get a hang on how to manage your palettes and images more wisely when you paint them.
Combining the above observations I hope you can get a hang on how to manage your palettes and images more wisely when you paint them.