我一直坚持使用 Haskell/Yampa (=Arrows)(使用 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)
移动器只是一个简单的积分器(加速度->速度->位置),我想在其中观察速度并将其渲染为调试输出作为(未定位的)线。
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 教程。
最佳答案
我不知道 HOOD,但 Debug.Trace 很简单:
> import Debug.Trace
> mover position0 = proc acceleration -> do
> > velocity <- integral -< acceleration
> > position <- trace ("vel:" ++ show velocity ++ "\n") $
> > > > > > > > > > > (position0 .+^) ^<< integral -< velocity
> > returnA -< position
请注意,不应将其放在定义速度的线上。
关于debugging - 在 Haskell/Yampa 和 HOOD 中调试游戏对象的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3255334/