【问题标题】:how to display an image with the grid.lua lib如何使用 grid.lua 库显示图像
【发布时间】:2014-09-12 00:59:28
【问题描述】:

我找到了这个库,可以轻松地在 lua 中创建一个网格,但我不能在每个单元格上分配一个图像。 https://github.com/CoderDojoSV/corona-game-template/blob/master/docs/grid.md

我已经联系了 grid.lua 的作者,但没有任何答复。 你有真正的语法吗?感谢您的帮助。

local grid = require("grid")

myGrid = grid.newGrid(5, 5, 500) 
myGrid:eachSquare(function(doeach)

【问题讨论】:

    标签: arrays image lua grid


    【解决方案1】:

    从我在文档中看到的网格是基于矩形对象的,因此您将无法直接将图像分配给网格。 但是您可以将图像放在每个正方形坐标中

    基于文档:

    local myGrid = grid.newGrid(8, 8, 700)
    myGrid:eachSquare(function(gridSquare)
         local image = display.newImage(pathToYourImage)
         image.x, image.y = gridSquare.displayObject.x, gridSquare.displayObject.y
    end)
    

    如果您需要在网格方块中引用图像,您可以将其分配给 gridSquare

    gridSquare.myImage = image
    

    这样,在以后的 eachSquare 迭代中,您将可以访问图像参考。

    【讨论】:

    • 嗨,感谢您的回复。但返回是:尝试调用方法 'eachSquare' (零值) local grid = require("grid") grid.newGrid(8, 8, 720) grid:eachSquare(function(gridSquare) local image = display.newImage (my2.png) image.x, image.y = gridSquare.displayObject.x, gridSquare.displayObject.y end)
    【解决方案2】:

    我找到了解决办法

    grille:eachSquare(function(gridSquare)
    gridSquare.displayObject:setFillColor(0, 0, 0, 255)
    gridSquare.displayObject.xScale=.1
    gridSquare.displayObject.yScale=1
    gridSquare.myImage = display.newImage("my2.png") 
    gridSquare.myImage.x = gridSquare.displayObject.x+35
    gridSquare.myImage.y = gridSquare.displayObject.y
    gridSquare.myImage.yScale=0.5
    gridSquare.myImage.xScale=0.5
    end)
    

    【讨论】:

    • 基本上和我的方案一样。
    猜你喜欢
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    相关资源
    最近更新 更多