我想使用Haskell的SDL绑定将一个sprite blit到一个surface上,但是我不知道如何定义sprite surface中的透明颜色。以下是目前的代码:
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绑定中实现相同的功能吗?
![…这里是精灵…](https://istack.dev59.com/ZjXdw.webp)
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