Tinting sprite

SGDK only sub forum

Moderator: Stef

Post Reply
vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Tinting sprite

Post by vnsbr » Thu Dec 28, 2017 3:20 pm

is there a way to tint a sprite or at least to make it flash white (blink) when hurt?

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Tinting sprite

Post by Sik » Thu Dec 28, 2017 9:30 pm

Two options:

1) If you can reserve dedicated colors for the sprite, you can change those colors from the palette.
2) If you can afford wasting palettes (there are only 4!), you can switch to a different palette.

In both cases you need to be careful regarding color management (specifically which colors are reserved for the job, and whether they can be reused elsewhere or not).

In Sonic games they do this by altering the black color when you hit a boss, but this causes everything black to flash. And some games may just switch to any other palette even if colors would be garbage if it's just for a "got hurt" flash effect. So how much of a trade-off you can afford is up to you.


EDIT: and if it's just for something getting hurt, you can also just flash it transparent (literally don't draw the sprite when transparent) instead of resorting to tinting.
Sik is pronounced as "seek", not as "sick".

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: Tinting sprite

Post by Miquel » Thu Dec 28, 2017 10:22 pm

Just expanding what Sik said:

First option is to change palette colors, is only doable if those colors are dedicated to a lonely character/object/layer. Changing palette is usually not an option since there are so few.

Then if isn't possible to play with the colors, two other options remain:
- Blinking
- Flickering

For blinking all you have to do is alternate displaying the character or not, a simple binary AND with the frame counter will do. Best result at 60hz is to change every two frames.

Code: Select all

if( frameCounter & 2)
{
      DrawActor();
}
Flickering is changing the palette every frame, doesn't matter witch colors actually are in the palette since the switching will be so fast that the eyes will not catch it. Again the simplest way is to use the frame counter to select which palette to use, something like:

Code: Select all

palette = frameCounter&3;
I recommend to incorporate these features to the drawing function so any actor can use them.

ALSO there are more experimental options, like:
- Masquerade part of the character using the sprite limit or a mask sprite
- Using shadow/highlight sprite to mask part of the character or substitute the entire character.
- Using shadow/highlight tiles to make a surrounding effect.
HELP. Spanish TVs are brain washing people to be hostile to me.

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: Tinting sprite

Post by Miquel » Thu Dec 28, 2017 10:44 pm

Furthermore:
Using more sprites and switching them on/off every frame. For example a hit/flash red sprite cam symbolize a blood spill while tinting the character red.

The key here is to go at 60/50hz so it seems transparent. Although in windowed emulators with a variable frame rate imposed by the OS doesn't feel as good as the real deal.
HELP. Spanish TVs are brain washing people to be hostile to me.

Post Reply