Changeset 20174

Show
Ignore:
Timestamp:
09/29/08 00:06:16 (5 years ago)
Author:
mokehehe
Message:

画像のカラーキー設定
終了時に読み込んだ画像の解放

Location:
lang/haskell/nario
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/nario/Main.hs

    r20156 r20174  
    1212import Field 
    1313import Util 
     14import Const 
    1415 
    1516wndTitle = "delayed-stream test" 
     
    8889process :: [[SDLKey]] -> IO [Scr] 
    8990process kss = do 
    90         imgres <- loadImageResource 
     91        imgres <- loadImageResource images 
    9192        st <- initialState 
    92         return $ map (\scr -> scr imgres) $ loop [] st kss 
     93        let scrs = map (\scr -> scr imgres) $ loop [] st kss 
     94        return $ scrs ++ [(\sur -> do {releaseImageResource imgres})] 
    9395        where 
    9496                loop :: [SDLKey] -> GameState -> [[SDLKey]] -> [(ImageResource -> Scr)] 
  • lang/haskell/nario/Util.hs

    r20156 r20174  
    7373 
    7474-- 画像リソース読み込み 
    75 loadImageResource :: IO ImageResource 
    76 loadImageResource = mapM load images 
     75loadImageResource :: [ImageType] -> IO ImageResource 
     76loadImageResource = mapM load 
    7777        where 
    7878                load imgtype = do 
    7979                        sur <- loadBMP $ ("data/img/" ++) $ imageFn imgtype 
    80 --                      colorKey <- mapRGB (surfacePixelFormat sur) $ Color r g b a 
    81                         let colorKey = 0xff00ff 
    82                         setColorKey sur [SRCCOLORKEY] colorKey 
    83                         return (imgtype, sur) 
    84                 r = 255 
    85                 g = 0 
    86                 b = 255 
    87                 a = 255 
     80                        setNuki sur 
     81                        converted <- displayFormat sur 
     82                        freeSurface sur 
     83                        return (imgtype, converted) 
    8884 
     85                setNuki sur = do 
     86                        let fmt = surfacePixelFormat sur 
     87                        if not $ null $ pfPalette fmt 
     88                                then setColorKey sur [SRCCOLORKEY] 0 >> return ()       -- パレット0番目をぬき色に 
     89                                else return () 
     90 
     91releaseImageResource :: ImageResource -> IO () 
     92releaseImageResource = mapM_ (\(t, sur) -> freeSurface sur) 
    8993 
    9094getImageSurface :: ImageResource -> ImageType -> Surface