2011-09-04 64 views
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綁定?

... here is the sprite...

這裏是實現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 

回答

3

嘗試setColorKey。你可以找到更多信息here。如果您使用PNG,最簡單的方法是使用Alpha通道。

+0

謝謝!它添加setColorKey並轉換表面後工作! – martingw