我从C ++切换到Haskell并使用Gloss来制作游戏。 我在main.hs中写了这个有效的代码:
import Graphics.Gloss.Interface.Pure.Game
events (EventKey (Char 'a') Down _ _) _ = RectangleWire 10 10
events _ x = x
main = play (InWindow "GameEvent" (700, 100) (10, 10))
white
100
(Circle 10.0)
id
events
(\_ world -> world)
然后命令ghc main.hs
回答:
[1 of 1] Compiling Main ( main.hs, main.o )
main.hs:3:43: Not in scope: data constructor `RectangleWire'
即使我安装了最新版本,我的Gloss lib也似乎缺少某些功能。例如,这个代码,来自gloss-examples包的“Game Event”,编译和运行完美(非常漂亮):
import Graphics.Gloss
-- | Display the last event received as text.
main
= play (InWindow "GameEvent" (700, 100) (10, 10))
white
100
""
(\str -> Translate (-340) 0 $ Scale 0.1 0.1 $ Text str)
(\event _ -> show event)
(\_ world -> world)
答案 0 :(得分:7)
您的代码无法编译,因为您引用的数据构造函数RectangleWire
不在范围内。错误表明:
main.hs:3:43: Not in scope: data constructor `RectangleWire'
扫描documentation for Gloss,看起来你正在寻找
rectangleWire :: Float -> Float -> PictureSource
以原点为中心的线框矩形,具有给定的宽度和高度。从Graphics.Gloss.Data.Picture
。