Page 1 of 1
Sprite colour changes
Posted:
Wed Oct 03, 2012 6:25 pm
by DrakeStoel
I'm making a game with magic spells, and one of them is similar to the Shield spell in Zelda II: Adventure of Link. When you use the spell, it changes the colour of the actor clothes. I've got all the sprites made out, but I'm wondering if there's a way to change to the different set of sprites without having to make a new actor.
Re: Sprite colour changes
Posted:
Wed Oct 03, 2012 7:39 pm
by skydereign
Actors have r, g, b actor variables (0-255). They aren't additive, so if you want to be able to get all the colors, the base animation needs to be white, but from there you just change the values to whatever you want.
actor -> Create Actor -> Script Editor
- Code: Select all
// this sets the color to red
r=255;
g=0;
b=0;
Re: Sprite colour changes
Posted:
Wed Oct 03, 2012 11:47 pm
by DrakeStoel
Yes, that works good and all, but that's not quite what I'm looking for. I need just certain colours of the sprites to change, mainly his clothing, and his skin colour stays the same.
Re: Sprite colour changes
Posted:
Thu Oct 04, 2012 12:23 am
by Soullem
If you are willing to make a new set of sprites for every action then I have made a system of animation that is perfect for you with just a little tweeking (see global code.
Hopefully you will get it, but if not I will be happy to explain further...
The system works because of three variables, Stance,Direction, and SwordShield(For you this could be COLOR)...
Stance changes when you stand, run, jump, fall, or crouch. When right or left key are pressed stance is set to 1, up key it is set to 2, falling sets it to 3 and crouching is four.
The stance variable sets a string array to the appropiate string
Direction is the simplest, it changes to 1 and -1 based on the last key you've pressed. 1 for right and -1 for left
The direction variable sets DirString to Left or Right.
SwordShield (COLOR) changes when you press the blue button with your mouse. when the value is 0 you have no sword, and when it is 1 you have a sword.
SwordShield sets a string variable to sword or nosword. Or for you Green and Red.
Then my functions take these variables to make a new super variable called Animation. All you have to do is name your animations apropiately.(see download for details)
its a bit complicated at first, but its very simple and logical.
Re: Sprite colour changes
Posted:
Thu Oct 04, 2012 12:36 am
by DrakeStoel
Ok, I think I get what's going on there. Now, my game isn't a side scroller like that, it's a top down view, like the original Legend of Zelda. Also, my actor would have a third colour for when night falls
Re: Sprite colour changes
Posted:
Thu Oct 04, 2012 1:05 am
by Soullem
You can change it around a little... I dont have sprites for it but ill explain how you can make it work...
First replace the players draw actor with the movement code with this
- Code: Select all
char*key=GetKeyState();
MovementRL=key[KEY_RIGHT]-key[KEY_LEFT];
switch (MovementRL)
{
case 1:
x+=4;
Direction=1;
if (Jumping==0)
{Stance=1;}
break;
case -1:
x-=4;
Direction=3;
if (Jumping==0)
{Stance=1;}
break;
case 0:
if (Stance==1)
{Stance=0;}
break;
}
MovementUD=key[KEY_UP]-key[KEY_DOWN];
switch (MovementUD)
{
case 1:
y-=4;
Direction=4;
Stance=1
break;
case -1:
y+=4;
Direction=2;
Stance=1
break;
case 0:
if (Stance==1)
{Stance=0;}
break;
}
Then in the global code add into the function in place of direction...
- Code: Select all
switch (Direction)
{
case (1)
strcpy(DirString, "Right");
break:
case (2)
strcpy(DirString, "Down");
break:
case (3)
strcpy(DirString, "Left");
break:
case (4)
strcpy(DirString, "Up");
break:
}
This will allow you to change this into a 4 directional work... (I believe, I have not tried this out yet.)
Re: Sprite colour changes
Posted:
Thu Oct 04, 2012 1:07 am
by skydereign
You could also have the animations have the same names, and create separate actors (with the save events using inheritance). That way you don't have to do string operations when changing animations (not very efficient).
But in terms of coloring, the only type of coloring built into gE is by setting rgb. So, if you want to be able to change only his tunic, you'll have to have the tunic be a separate actor. It is possible to link your actors together, but it does take a bit of work. The only other option is to use different animations for each color, similarly to what Soullem posted. But if you are using many different colors, you should invest the time to setup the multiple white actors instead.
Re: Sprite colour changes
Posted:
Thu Oct 04, 2012 1:09 am
by Soullem
Well... For when night falls you can add an if which changes SwordShield 's value to 2, and add a strcpy (String copy) to the first part of the function...
For yours it would be
- Code: Select all
strcpy(SSString[0], "Green");
strcpy(SSString[1], "Red");
strcpy(SSString[2], "Night");
Re: Sprite colour changes
Posted:
Thu Oct 04, 2012 1:11 am
by DrakeStoel
Alright! That works just dandy! Thanks for your help guys
Re: Sprite colour changes
Posted:
Thu Oct 04, 2012 1:16 am
by Soullem
No problem... Hope your game works out well...
And thanks for the advice Sky I just find it easier to keep actor numbers down, and this handles everything visual including the movement attire, and weapon. This allows me to easilly see the matchups through numbers... Just how my mind works.. your method will work great after 3 or 4 colors (when the animation number gets to high)... Like in the Eggventures of Eggdude.
Also not bad for my first function? ; )