Haskell光泽度加载.bmp

时间:2016-12-30 04:45:52

标签: haskell gloss

-- | Main function
main :: IO ()
main = do 
          wall <- loadBMP "wall.bmp" -- loads wall image
          play initialState drawState reactEvent reactTime


-- | Function that creates the game
play :: State -> (State -> Picture) -> (Event -> State -> State) -> (Float -> State -> State) -> IO ()
play initialState drawState reactEvent reactTime = play
            (InWindow "Game" (900, 900) (0, 0))      -- Window ize
            (greyN 0.5)                              -- background coloer
            1                                        -- refresh rate
            initialState                             -- initial state
            drawState                                -- draws game state
            reactEvent                               -- teacts to evente
            reactTime                                -- reacts to time

-- | One game represenction
type State = (Map,Picture)

-- | Initial game state
initialState :: State
initialState = ((map 13 0),wall)

功能地图创建我的地图。 我的游戏已经运行良好,但我需要用一些BMP图像替换我使用的表示(来自光泽的圆圈),但是当我尝试加载这个墙时,我甚至无法加载它会出现错误我在这里分享的最后一行: 不在范围内&#39;墙&#39;

有人能看出为什么会这样吗?

1 个答案:

答案 0 :(得分:2)

定义main时,您在此处创建的变量无法在main的定义之外访问。 initialState超出了main的定义。

您需要将wall传递到initialState,方法是更改​​maininitialState,如下所示:

main :: IO ()
main = do 
          wall <- loadBMP "wall.bmp" -- loads wall image
          play (initialState wall) drawState reactEvent reactTime

initialState :: Picture -> State
initialState wall = ((map 13 0),wall)