Haskell SDL绑定:如何使用透明颜色复制精灵?

3

我想使用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绑定中实现相同的功能吗? …这里是精灵… 在实施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
1个回答

3

尝试使用setColorKey。您可以在此处找到更多信息。如果您正在使用PNG,则最简单的方法是使用alpha通道。


谢谢!在添加setColorKey和转换表面后,它起作用了! - martingw

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接