Difference between revisions of "How to make a sprite translucent"
Jump to navigation
Jump to search
m |
|||
Line 23: | Line 23: | ||
[[File:HowToFadeSprite.png]] | [[File:HowToFadeSprite.png]] | ||
+ | |||
+ | [[Category:Mini Micro]] | ||
+ | [[Category:How To]] |
Revision as of 22:21, 7 March 2020
You can change the opacity of a sprite by using the alpha channel of the tint color. An alpha value of 255 (or FF in hex) is completely opaque; an alpha value of zero is completely transparent (invisible). Alpha values between 1 and 254 are translucent (i.e. semi-transparent). You can use the color.rgba function to construct such a color at runtime.
Note that the same technique works in a TileDisplay by using the setCellTint method.
Example
This example draws a pattern of text, just to give us a visible background, and then adds a bunch of sprites of varying translucency to display 2, above the default text layer (display 3).
clear
for i in range(10)
print "/\" * 33
end for
display(2).mode = displayMode.sprite
display(2).clear
for i in range(0, 8)
sp = new Sprite
sp.image = file.loadImage("/sys/pics/Wumpus.png")
sp.x = 50 + 800*i/8
sp.y = 500
sp.tint = color.rgba(255, 255, 255, 255*i/8)
display(2).sprites.push sp
end for