1

我目前正在为 Haskell 开发基于 tile 的 2d 引擎。所以我目前的任务是提取(=导入)图片的部分。我正在使用Graphics.Gloss.Data.Picture

bitmapSection :: Rectangle -> BitmapData -> Picture

我的问题如下:我尝试了多种不同的转换方法(请参阅下面的完整代码),但它们都没有产生我希望的结果。

基本图像为:(在此处输入图像描述尺寸为:32x32)

我得到的是:在此处输入图像描述

注意:我尝试了我能想到的所有不同的输入/转换方法,并将它们并排绘制......

现在的问题是:我做错了什么?

完整示例代码:

import Graphics.Gloss.Interface.Pure.Game
    ( white, Display(InWindow), Event, Picture(Blank), pictures, bitmap, translate)
import Graphics.Gloss.Interface.IO.Game (playIO)


import Graphics.Gloss
    ( white,
      bitmapSection,
      Display(InWindow),
      Picture(Blank),
      bitmapDataOfBMP,
      bitmapDataOfByteString,
      bitmapOfByteString,
      BitmapFormat(BitmapFormat),
      PixelFormat(PxRGBA, PxABGR),
      RowOrder(TopToBottom, BottomToTop ),
      Rectangle (Rectangle),
      BitmapData (bitmapSize), bitmapOfBMP, bitmapOfForeignPtr
      )

import qualified Data.ByteString as ByteString

main :: IO ()
main = do
    state <- read'
    playIO
        window
        background 
        fps
        state
        (\state -> return state)
        (\event state -> return state)
        (\_ state -> return state)

        where
            background = white
            window = InWindow "WindowName" (500,100) (10,10)
            fps = 60


read' :: IO Picture
read' = do
    file <- ByteString.readFile "rechteck_gruen.bmp"
    let 
        bit_map1 = bitmapDataOfByteString  32 32 (BitmapFormat BottomToTop PxRGBA) file True
        bit_map2 = bitmapDataOfByteString  32 32 (BitmapFormat TopToBottom PxRGBA) file True
        bit_map3 = bitmapDataOfByteString  32 32 (BitmapFormat BottomToTop PxABGR) file True
        bit_map4 = bitmapDataOfByteString  32 32 (BitmapFormat TopToBottom PxABGR) file True

        pic1 = bitmapOfByteString 32 32 (BitmapFormat BottomToTop PxRGBA) file True 
        pic2 = bitmapOfByteString 32 32 (BitmapFormat TopToBottom PxRGBA) file True
        pic3 = bitmapOfByteString 32 32 (BitmapFormat BottomToTop PxABGR) file True
        pic4 = bitmapOfByteString 32 32 (BitmapFormat TopToBottom PxABGR) file True

        {--
        Important: bitmapSection with size 32x32 is only for testing purpose... 
        therefore picFromSection should be equal to picFromByteString ? 
        --}
        picFromSection = map (\bitMap -> bitmapSection (Rectangle (0,0) (32,32)) bitMap) 
            [bit_map1, bit_map2, bit_map3, bit_map4]

        picFromByteString = [pic1, pic2, pic3, pic4]

        picFromBitMap = map (\bitMap -> bitmap bitMap) 
            [bit_map1, bit_map2, bit_map3, bit_map4]

        scene = picFromSection ++ picFromByteString ++ picFromBitMap

        performTranslate _ [] = []
        performTranslate n (x:xs) = translate (n*40-230) 0 x  : performTranslate (n+1)  xs

   
    
    return $ pictures $ performTranslate 0 scene
4

0 回答 0