1

私は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'

最新バージョンをインストールしているのに、Glosslibにいくつかの機能が欠けているようです。たとえば、gloss-examplesパッケージのこのコード「GameEvent」は、完全に(とても美しい)コンパイルおよび実行されます。

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)
4

1 に答える 1

7

参照しているデータコンストラクターがRectangleWireスコープ内にないため、コードのコンパイルに失敗しています。エラーはこれを示しています:

main.hs:3:43: Not in scope: data constructor `RectangleWire'

Glossのドキュメントをスキャンすると、探しているように見えます

rectangleWire :: Float -> Float -> PictureSource

指定された幅と高さで、原点を中心とするワイヤーフレームの長方形。からエクスポートされましたGraphics.Gloss.Data.Picture

于 2012-06-07T15:33:16.107 に答える