【问题标题】:Is there a way to have the origin be in the top left corner when using Gloss使用 Gloss 时有没有办法让原点位于左上角
【发布时间】:2021-03-23 04:43:08
【问题描述】:

我正在使用 Gloss 在 Haskell 中制作 Asteroids 克隆。

如果飞船在屏幕右侧熄灭,我希望飞船从左侧返回。 原点(0, 0) 位于屏幕中间这一事实使这变得不必要地棘手。

有没有办法将原点移到左上(或下)?

我的Main 模块(我正在与Gloss 交互的地方)如下所示:

module Main where

import           Graphics.Gloss    (Display (InWindow), black, play)

-- my own imported code
import           Assets            (loadAssets)
import           GameState         (defaultHeight, defaultWidth, initGameState)
import           HandleInput       (handleInput)
import           ProgressGameState (progressGameState)
import           Render            (render)

windowDisplay :: Display
windowDisplay = InWindow "Window" (defaultWidth, defaultHeight) (10, 10)

main :: IO ()
main = do
  assets <- loadAssets
  play
    windowDisplay
    black
    60
    initGameState
    (render assets)
    handleInput
    progressGameState

【问题讨论】:

    标签: haskell gloss


    【解决方案1】:

    我认为没有一种简单的方法可以移动原点。但是无论你的格式之间的转换是一个简单的翻译。您可以使用函数(甚至是smart constructor)在两者之间进行计算。

    例如,如果 (0,0) 位于尺寸为 (x,y) 的图片的中心,但您希望它位于左上角,您只需从所有图片中减去 (x/2,y/2)你的观点让数学再次正确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-19
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      • 2017-07-06
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多