Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TLN_SetSpriteBlendMode to highlight items
#1
Hello everybody,

I used TLN_SetSpriteBlendMode(id,BLEND_ADD,1); and TLN_SetSpriteBlendMode(id,BLEND_NONE,1); to highlight and de-highlight inventory items in my game when player hovers the mouse over them.

BLEND_ADD looks good but the effect is too subtle, I would like to use a BLEND_ADD but with more strength.

Any tips on this? Or maybe a parameter that lets you set the strength (but I think this is the third deprecated parameter).

Best regards.
Reply
#2
You can always use BLEND_CUSTOM to define your own blend function. The documentation on TLN_SetCustomBlendFunction() seems to have the information you'd need to do this.
Reply
#3
Thank you very much. There is any example of calling this function?

The function-parameter and "components" intensity look strange, it would be useful to start from a given example.
Reply
#4
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:
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
Reply
#5
Thank you very much for your answers, time and code. I will try that.
Reply
#6
I'd say the palette swapping method was the traditional approach.

In my game I just released, Jump-n-Bump, each menu option is a sprite with 2 frames of animation - very ham-fisted, but it was made in Godot and it doesn't have palette swapping.  When I make my next game in Tilengine, I'll be using palette swapping for a lot of things!
Reply
#7
It worked like a charm.

Congratulations for your game Domarius!
Reply
#8
Haha what a cute guts-fest your jump-n-bump game Domarius Biggrin Biggrin  I don't know the original game, but congratulations for your funny remake
Reply
#9
Thanks guys Smile I have to say, I'm really missing the palette swapping, I'm making an update to the game, and just manually created 8 colour variations of 3 new animals, each - something that could have been done with palette swapping. So yeah, will be looking into getting Tilengine compiling for Mac next... since the Mac version of my Jump n Bump game was the 2nd most downloaded after Windows... with Linux third...
Reply
#10
Yeah Domarius throw away that Godot thing and "jump" to tilengine Smile just kidding, kudos to the people behind Godot. But it's not designed with retro graphics in mind.

Talking about Mac, let me know when you attempt to build it. I don't have a Mac, I build for it with a modified version of VMWare and a pirated copy of OSX 10.11 "El Capitan". But it works. And Tilengine is also more downloaded in OSX than in linux (but the undisputed king is Windows 64-bit)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)