How to make a sprite translucent

From MiniScript Wiki
Jump to navigation Jump to search

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.


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).

for i in range(10)
	print "/\" * 33
end for
display(2).mode = displayMode.sprite
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