我想使用Haskell的SDL绑定将精灵blit到表面,但我不知道如何在精灵的表面中定义透明颜色。这是迄今为止的代码:
module Main where
import Graphics.UI.SDL as SDL
import Graphics.UI.SDL.Image as SDLi
main = do
SDL.init [SDL.InitVideo]
screen <- SDL.setVideoMode 500 500 32 []
SDL.fillRect screen Nothing (SDL.Pixel 0x00FFFFFF)
ball <- SDLi.load "30ball.png"
SDL.blitSurface ball Nothing screen Nothing
SDL.flip screen
delay 2000
SDL.quit
在Sdldotnet-Library中,我可以使用以下内容设置 ball 的属性:
ball.Transparent<-true
ball.TransparentColor<-Color.FromArgb (0, 255, 0)
知道如何在Haskell的SDL绑定中实现相同的目标吗?
这是执行Banthar建议后的工作版本:
module Main where
import Graphics.UI.SDL as SDL
import Graphics.UI.SDL.Image as SDLi
main = do
SDL.init [SDL.InitVideo]
screen <- SDL.setVideoMode 500 500 32 []
SDL.fillRect screen Nothing (SDL.Pixel 0x00FFFFFF)
ball <- SDLi.load "30ball.bmp"
b2 <- convertSurface ball (surfaceGetPixelFormat screen) []
t <- mapRGB (surfaceGetPixelFormat b2) 0 255 0
setColorKey b2 [SrcColorKey, RLEAccel] t
SDL.blitSurface b2 Nothing screen Nothing
SDL.flip screen
delay 2000
SDL.quit