09-04-2018, 02:39 AM
Hi guys,
I think about two ways to handle this -and probably a combination of both-:
1. Different palettes
Clone the palette of the object to have a "highlighted" version, and lighten it with TLN_AddPaletteColor() . Alternatively you can craft a different palette in a graphic editor and load it with TLN_LoadPalette(). When you want to lighten the selected object, use TLN_SetSpritePalette() to pass the lighted palette, and call it again with the original palette when to restore it. Remeber to get a reference to the original palette with TLN_GetSpritePalette().
Assuming you are modifying sprite 0:
2. Custom blending
As pointed out by RexyDallas, you can create a custom blend function. Proper documentation is lacking. The idea is that you create a transfer function between the intensities of color components of the image you want to draw and the image below it, and return a new intensity. For example to multiply the intensity of the source image by 2 and then add to the destination, you would do something like this:
I haven't compiled this, there may be some typos but you get the idea
I think about two ways to handle this -and probably a combination of both-:
1. Different palettes
Clone the palette of the object to have a "highlighted" version, and lighten it with TLN_AddPaletteColor() . Alternatively you can craft a different palette in a graphic editor and load it with TLN_LoadPalette(). When you want to lighten the selected object, use TLN_SetSpritePalette() to pass the lighted palette, and call it again with the original palette when to restore it. Remeber to get a reference to the original palette with TLN_GetSpritePalette().
Assuming you are modifying sprite 0:
Code:
/* grab the original palette */
TLN_Palette original_palette = TLN_GetSpritePalette(0);
/* clone and add 50% white to thel new palette */
TLN_Palette selected_palette = TLN_ClonePalette(original_palette);
TLN_AddPaletteColor(selected_palette, 128,128,128, 0,255);
/* set "highlighted" palette */
TLN_SetSpritePalette(0, selected_palette);
/* restore original palette */
TLN_SetSpritePalette(0, original_palette);
2. Custom blending
As pointed out by RexyDallas, you can create a custom blend function. Proper documentation is lacking. The idea is that you create a transfer function between the intensities of color components of the image you want to draw and the image below it, and return a new intensity. For example to multiply the intensity of the source image by 2 and then add to the destination, you would do something like this:
Code:
/* your blend function: source*2 + deination, clamped to 0-255 */
uint8_t my_blend_function(uint8_t src, uint8_t dst)
{
int blend = src*2 + dst;
if (blend <= 255)
return (uint8_t)blend;
else
return 255;
}
/* set custom blending: */
TLN_SetCustomBlendFunction(my_blend_function);
TLN_SetSpriteBlendMode(0, BLEND_CUSTOM, 0);
I haven't compiled this, there may be some typos but you get the idea