Solved Palette change cycle

Question that is answered or resolved.

DJGameFreakTheIguana

Active member



Didn't know the best way to word this, but I'd like to be able to have Mecha Sonic cycles through palettes like this at all times. I don't know if there's a better method for this if it's been done before, but an idea I had was to have Mecha spawn a bound entity, or panel, to keep up with him and have an idle animation that constantly commands Mecha to change palettes with loop 1.

x)
 
but an idea I had was to have Mecha spawn a bound entity, or panel, to keep up with him and have an idle animation that constantly commands Mecha to change palettes with loop 1.

That reminds me to effect entity I've coded for booster items that I released some time ago :cool:. Each booster item has FX entity which tints the item taker and also apply the boost effect. It's for limited time and at the end of boost time, the entity cancels the tint and the effect (y).
It's possible to remove the time limit and the boost effect and replace the tint with palette swap for this request.

Other option I have in mind is using ondrawscript to do this. Though, unlike using FX entity, it will require coding timer yourself for the cycle timer :sneaky:.

I'm going to try both methods :cool:
 
using ondrawscript =>
C:
     void main () {
         int delay = 5;  //Test out the value
         int currentTime = openborvariant("elapsed_time");
      
         if(currentTime % delay != 0 ) return;        
        
         void self = getlocalvar("self");
         int mapLength = getentityproperty(self,"mapcount");
         int currentMap = getentityproperty(self,"map");         
         
         int idx = currentMap == mapLength - 1 ? 0 : currentMap + 1;         
         changeentityproperty(self,"map",idx);   
}

this should meet your requirements.................
 
Last edited:
Sounds fun, and thanks in advance.

About a timer, I want the cycle to go on until I kill the spawned entity.

It was fun :LOL:. Both methods work and each has its own pros and cons :sneaky:.
Using FX entity requires extra work to apply it but it is much easier to understand and allow custom palette period setting :cool:.

For now I'll share the ondrawscript method since it's simple to share.
It works similar to one posted by Eannamagic above but with couple differences.
Palcler.c
C:
void main()
{
    int Period = 5; // 5 centiseconds period
    int Time = openborvariant("elapsed_time");
    int TPhase = Time%(2*Period);

    if(TPhase == 0){
      void self = getlocalvar("self");
      int Map = getentityproperty(self, "map");

      if(Map == 1){
        changeentityproperty(self, "map", 2);
      } else if(Map == 2){
        changeentityproperty(self, "map", 3);
      } else {
        changeentityproperty(self, "map", 1);
      }
    }
}

This script cycles used palette from 1st alternate palette, to 2nd one then 3rd one before going back to 1st one again with 5 centiseconds period.
You can modify 5 in script above to change cycle period.

To use this script, just declare this in header:
ondrawscript data/scripts/palcler.c

HTH
 
In DJ's example above, Mecha Sonic's default palette is blue while his alternate palettes are gold. I assume DJ wants Mecha Sonic to cycle his alternate palettes only.
 
Yo, I'm back to confirm the script does work, I had an extra line to add for a 4th palette but it still works. One thing though, I want the cycle to go back and fourth, go from pal4 to pal 3 instead of Pal4 to pal1, but when I try this, only 2 of the pals show up. This is what works now.
Code:
void main()
{
    int Period = 9; // 5 centiseconds period
    int Time = openborvariant("elapsed_time");
    int TPhase = Time%(2*Period);

    if(TPhase == 0){
      void self = getlocalvar("self");
      int Map = getentityproperty(self, "map");

      if(Map == 1){
        changeentityproperty(self, "map", 2);
      } else if(Map == 2){
        changeentityproperty(self, "map", 3);
      } else if(Map == 3){
        changeentityproperty(self, "map", 4);
      } else {
        changeentityproperty(self, "map", 1);
      }
    }
}

How I want it to work but doesn't.

Code:
void main()
{
    int Period = 9; // 5 centiseconds period
    int Time = openborvariant("elapsed_time");
    int TPhase = Time%(2*Period);

    if(TPhase == 0){
      void self = getlocalvar("self");
      int Map = getentityproperty(self, "map");

      if(Map == 1){
        changeentityproperty(self, "map", 2);
      } else if(Map == 2){
        changeentityproperty(self, "map", 3);
      } else if(Map == 3){
        changeentityproperty(self, "map", 4);
      } else if(Map == 4){
        changeentityproperty(self, "map", 3);
      } else if(Map == 3){
        changeentityproperty(self, "map", 2);
      } else {
        changeentityproperty(self, "map", 1);
      }
    }
}

The pals for reference.
Code:
palette       data/chars/M/PalG

alternatepal  data/chars/M/palSM0
alternatepal  data/chars/M/palSM1
alternatepal  data/chars/M/palSM2
alternatepal  data/chars/M/palSM3

In DJ's example above, Mecha Sonic's default palette is blue while his alternate palettes are gold. I assume DJ wants Mecha Sonic to cycle his alternate palettes only.
I'm actually going to have Mecha be killed first before he turns, having him summon Super Mecha via death animation, so Pal1 or palSM0 was originally going to be the first palette, but we can make it work either way.

x)
 
Ah so that's how it works :D.
I could think of hard way :unsure: to do that but I rather use simple trick for this :ninja: .
First declare the palettes like this:
Code:
alternatepal  data/chars/M/palSM0
alternatepal  data/chars/M/palSM1
alternatepal  data/chars/M/palSM2
alternatepal  data/chars/M/palSM3
alternatepal  data/chars/M/palSM2
alternatepal  data/chars/M/palSM1

then modify the script into this:
C:
void main()
{
    int Period = 9; // 9 centiseconds period
    int Time = openborvariant("elapsed_time");
    int TPhase = Time%(2*Period);

    if(TPhase == 0){
      void self = getlocalvar("self");
      int Map = getentityproperty(self, "map");

      if(Map == 1){
        changeentityproperty(self, "map", 2);
      } else if(Map == 2){
        changeentityproperty(self, "map", 3);
      } else if(Map == 3){
        changeentityproperty(self, "map", 4);
      } else if(Map == 4){
        changeentityproperty(self, "map", 5);
      } else if(Map == 5){
        changeentityproperty(self, "map", 6);
      } else {
        changeentityproperty(self, "map", 1);
      }
    }
}

The script still cycles forward as coded before but since alternate palettes are ordered like the above, it gives impression of cycling back n forth :cool:.
 
Guys, if I might offer a suggestion: Why not use tinting instead of all those maps? The script would be almost exactly the same.

DC
 
Sounds cool, but does this change the whole sprite? When Sonic and others go super saiyan, only their fur lights up.
super-sonic-sonic-the-hedgehog-33485118-572-474.gif
 
Back
Top Bottom