Difference between revisions of "How to make a sprite translucent"
Jump to navigation
Jump to search
(Created page with "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 comp...") |
|||
Line 19: | Line 19: | ||
display(2).sprites.push sp | display(2).sprites.push sp | ||
end for</ms> | end for</ms> | ||
+ | |||
+ | [[File:HowToFadeSprite.png]] |
Revision as of 22:20, 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.
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