我一直使用Haskell/Yampa(= Arrows)(與HOOD)爲我的遊戲對象生成調試輸出。在Haskell/Yampa和HOOD中調試遊戲對象的輸出
我的引擎基本上運行一個產生輸出狀態(線,圓)的遊戲對象列表,然後渲染。
data Output = Circle Position2 Double | Line Vector2
output :: [Output] -> IO()
output oos = mapM render oos
render :: Output -> IO()
render (Circle p r) = drawCircle p r
render (Line vec) = drawLine (Point2 0 0) vec
的選手對象只是移動到右側,被表示爲(定位)的圓。
playerObject :: SF() Output -- SF is an Arrow run by time
p <- mover (Point2 0 0) -< (Vector2 10 0)
returnA -< (Circle p 2.0)
動機只是一個簡單的積分器(加速 - >網速度>位置)其中,I想觀察速度並使其作爲調試輸出作爲(unpositioned)線。
mover :: Position2 -> SF Vector2 Position2
mover position0 = proc acceleration -> do
velocity <- integral -< acceleration -- !! I want to observe velocity
position <- (position0 .+^) ^<< integral -< velocity
returnA -< position
如何爲我的遊戲對象函數的內部值創建附加圖形調試輸出?實際上應該發生的是在輸出中,首先渲染實際對象(圓形),但也渲染額外的調試輸出(作爲行的移動向量)。大概我可以通過HOOD來實現這個目標,但是我仍然不太熟悉Haskell,也不知道如何爲我的案例採用HOOD教程。
這不會給圖形輸出,不過,在控制檯上只是文本,並且一般有點有限。有時候'unsafePerformPrintfDebugging'就是你真正需要的,但我認爲這裏的提問者不止於此。 – 2010-07-15 13:50:38