Im trying to add a fade in out transition but i only want it on a single sprite compared to the whole screen, is there any way or extension to do this?
probably not in the way you imagine… most of the time fading in and out is accomplished by changing the color palette. makecode only supports 16 colors at a time so there is no way to change the color palette for just one sprite. also, i’m imagining you want this sprite to fade into the background rather than to a solid color which makes things even more tricky…
that being said, i can think of two ways to do this
Option A: interpolate colors without changing the palette
this option is similar to what the shader extension does. basically, you will accomplish the fade by mapping each pixel in a sprites image to one that is closer to whatever pixel is underneath the sprite and repeat until all the pixels in the sprite are the same as the background.
let’s look at a concrete example! say i had a sprite that was a single cyan pixel:
this sprite happens to be over a background pixel that has the color dark purple:
if i were to fade this pixel from cyan to dark purple, i would do it in two steps like so:
first i move the pixel to a color that is in between cyan and dark purple (blue), and then i move it to dark purple.
easy enough! the tricky part is that for each color, you need to determine which color is the next step in the fading chain. i think the easiest way to do this would be to create some sort of lookup table. for example, you could create a 16x16 where each column and row represent one color in the palette and then fill each pixel in the image with the next pixel that would result from trying to fade one color to the other
…which would be tedious, but you’d only have to do it once!
Option B: use a reduced color palette
this option requires you to have a game with fewer than 16 colors. in fact, i think the maximum number of colors you could have would be 3. that being said, it would allow you to have nice smooth fades.
the idea here would be that when you want to start a fade effect, you would map each color in the sprite to a different color in the palette based on it’s start color and end color. Then you would use the color fading extension to do a fade from a palette that maps all those colors to the start colors to another palette that maps them all to the end colors.
the benefit of this approach is it’s super easy to code. in fact, if i wasn’t busy at the moment i’d write you an example (i’ll try to post one later). the downside is that, of course, you can only have three colors in your palette