3
我想使用Haskell的SDL綁定將精靈粘貼到曲面上,但我不知道如何在精靈曲面中定義透明顏色。這是迄今爲止代碼: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圖書館,我可以像設置球的屬性:
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
謝謝!它添加setColorKey並轉換表面後工作! – martingw