256 Colour Tutorial Part 2(V2.62): Difference between revisions
256 Colour Tutorial Part 2(V2.62) (view source)
Revision as of 07:03, 7 December 2005
, 7 December 2005no edit summary
m (Added TOC) |
No edit summary |
||
Line 1: | Line 1: | ||
'''Palette effects using pre-defined functions''' | '''Palette effects using pre-defined functions''' | ||
(by [[user:Gilbert|Gilbert Cheung]]) | (by [[user:Gilbert|Gilbert Cheung]]) | ||
==Palette related functions== | ==Palette related functions== | ||
In [[256 Colour Tutorial Part 3|Part 1]] we had learnt about how to create and import 256 colour images for use with AGS games, let's move on to some applications. | In [[256 Colour Tutorial Part 3|Part 1]] we had learnt about how to create and import 256 colour images for use with AGS games, let's move on to some applications. | ||
Line 68: | Line 67: | ||
==Changing an individual colour== | ==Changing an individual colour== | ||
''( | Sometimes you may want to change the colour of a particular slot for some reasons, in such case you may check out the function '''SetPalRGB()''', again, let me just copy something from the AGS manual to bloat this space a bit: | ||
'''SetPalRGB (int slot, int red, int green, int blue)''' | |||
Changes the RGB components of one of the palette slots. The palette | |||
is initially set up in the Palette Editor, but you can override it | |||
during the game using this function for special effects. The RED, | |||
GREEN and BLUE parameters each range from 0 to 63 (as used in the | |||
Palette Editor). | |||
If SLOT is a background slot, then this function's effect will last | |||
until the player changes screen, when the palette is changed to the | |||
new room's palette. If SLOT is not a background slot, the effect of | |||
this function is permanent. | |||
'''NOTE:''' This function will allow you to change the colours which | |||
are "locked" in the Room Editor. However, you should not normally do | |||
this as it can cause strange colours in the game. | |||
Well, I won't bother explaining the above word by word, basically what this function does, is to change the colour of a slot directly, ''all'' pixels on screen which use this slot will be changed to the new colour immediately. | |||
Let's illustrate this with an example, remember the [[media:8bittut_ss1.pcx|sprites]] we used in the part 1? Conside the girl sprite: | |||
[[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 slot 32 is <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'': | |||
int antennaecol=1; //variable to keep track of the colour change | |||
Then add the follow to the ''Global script'': | |||
function repeatedly_execute_always() { | |||
if (antennaecol==0) { | |||
antennaecol=1; | |||
SetPalRGB (32, 63, 0, 0); //(63, 0, 0) is red | |||
} else { | |||
antennaecol=0; | |||
SetPalRGB (32, 0, 0, 0); //(0, 0, 0) is black | |||
} | |||
} | |||
Save your script and test the game, you may notice two things: | |||
# Though the girl's shoes were also painted in red, but their colours won't flash with her antennaem, since I didn't use slot 32 in 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. | |||
Combining the above observations I hope you can get a hang on how to manage your palette and images more wisely when you paint them. | |||
Now, let's do some more interesting effect, suppose we don't want the girl's antennae tips to flash quickly, but want the colour to fade in and out gradually, what can we do? Well we may make the following modifications to the above codes: | |||
int antennaecol='''63, antennaefade=-1'''; | |||
Also: | |||
function repeatedly_execute_always() { | |||
'''antennaecol+=antennaefade;''' | |||
'''if (antennaecol==0) antennaefade=1; //Fade in''' | |||
'''else if (antennaecol==63) antennaefade=-1; //Fade out''' | |||
'''SetPalRGB (32, antennaecol, 0, 0); //Just alter the intensity of the R-channel''' | |||
} | |||
Again, save your script and test the game, got it already? | |||
Above are just some small examples on how to modify individual palette slots using '''SetPalRGB()''', you may experience yourself, like change other slots, change some of the slots into other crazy colours, etc., you may even think of some colour animation, with colour changes decided by some mathematical formulae, everything is left to your imaginations. But bear in mind that whenever you use '''SetPalRGB()''', the r-, g-, b- channel values ''must'' be within the allowed range of 0 through 63. | |||
==Conclusion== | |||
This part of the tutorial is quite short compared to the others, but I think the effects are interesting enough for you to try. You may ask, "HEY! What about the '''UpdatePalette()''' function?" Well, I won't cover the usage of '''UpdatePalette()''' in detail here, as it's not yet useful in this stage. In the next and last part of the tutorial, however, this function plays a ''very'' important role, when you want more low-level control of the palette, so I'll end this part here.Again I'll give you another present: | |||
[[media:8bittut_paltut2.zip|Download this file]] | |||
Which is merely just the above materials put together into an AGS "game". To test it just unzip it into an empty folder and load up '''ac2game.dta''' via the AGS editor and ''save'' a game. ('''room1.crm''' is the "dizzy" room, where you can click to transport you to '''room2.crm''', which is the "disco" room, you can click on the door(way) to toggle between opening and closing of the door, you'll notice also the door lock light will change colour according to the status of the door, you can read the room script for more info on how to do this. If you're having enough "fun" just press '''ctrl-Q''' to quit.) | |||
Coming next - [[256 Colour Tutorial Part 3|Part 3: Full control of palette effects]] | Coming next - [[256 Colour Tutorial Part 3|Part 3: Full control of palette effects]] |