Sprite colour changes

Game Editor comments and discussion.

Sprite colour changes

Postby DrakeStoel » Wed Oct 03, 2012 6:25 pm

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.
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: Sprite colour changes

Postby skydereign » Wed Oct 03, 2012 7:39 pm

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;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Sprite colour changes

Postby DrakeStoel » Wed Oct 03, 2012 11:47 pm

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.
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: Sprite colour changes

Postby Soullem » Thu Oct 04, 2012 12:23 am

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.
Attachments
AnimTUT.zip
(56.07 KiB) Downloaded 115 times
Current Project:
The Project That needs to be Done -- Pokemon http://game-editor.com/forum/viewtopic.php?f=4&t=12591

Temporarily Abandoned:
Souls of Gustara -- Awesome upgrade blimp game 42%ish
Eggventures of Eggman -- Adventure Game 20%ish
User avatar
Soullem
 
Posts: 105
Joined: Thu Aug 02, 2012 3:12 pm
Score: 5 Give a positive score

Re: Sprite colour changes

Postby DrakeStoel » Thu Oct 04, 2012 12:36 am

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
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: Sprite colour changes

Postby Soullem » Thu Oct 04, 2012 1:05 am

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.)
Current Project:
The Project That needs to be Done -- Pokemon http://game-editor.com/forum/viewtopic.php?f=4&t=12591

Temporarily Abandoned:
Souls of Gustara -- Awesome upgrade blimp game 42%ish
Eggventures of Eggman -- Adventure Game 20%ish
User avatar
Soullem
 
Posts: 105
Joined: Thu Aug 02, 2012 3:12 pm
Score: 5 Give a positive score

Re: Sprite colour changes

Postby skydereign » Thu Oct 04, 2012 1:07 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Sprite colour changes

Postby Soullem » Thu Oct 04, 2012 1:09 am

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");
Current Project:
The Project That needs to be Done -- Pokemon http://game-editor.com/forum/viewtopic.php?f=4&t=12591

Temporarily Abandoned:
Souls of Gustara -- Awesome upgrade blimp game 42%ish
Eggventures of Eggman -- Adventure Game 20%ish
User avatar
Soullem
 
Posts: 105
Joined: Thu Aug 02, 2012 3:12 pm
Score: 5 Give a positive score

Re: Sprite colour changes

Postby DrakeStoel » Thu Oct 04, 2012 1:11 am

Alright! That works just dandy! Thanks for your help guys
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: Sprite colour changes

Postby Soullem » Thu Oct 04, 2012 1:16 am

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? ; )
Current Project:
The Project That needs to be Done -- Pokemon http://game-editor.com/forum/viewtopic.php?f=4&t=12591

Temporarily Abandoned:
Souls of Gustara -- Awesome upgrade blimp game 42%ish
Eggventures of Eggman -- Adventure Game 20%ish
User avatar
Soullem
 
Posts: 105
Joined: Thu Aug 02, 2012 3:12 pm
Score: 5 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest