我正在尝试使用Moai SDK为游戏创建网格.网格中的每个图块都应该能够填充颜色.
所以实际上我有两个问题:
谢谢
使用Moai构建网格的最佳方法是什么?
Moai有一个创建网格的对象:MOAIGrid.使用框架的术语,您创建一个网格并给它一个套牌.然后将它附加到道具并将道具添加到图层.(该图层还需要一个附加到窗口的视口.)
如何用颜色单独填充每个瓷砖
甲摩埃甲板是图像的图像或集合.如果您希望您的瓷砖颜色不同,那么您将创建一个带有这些颜色的正方形图像的卡座.
此代码将在窗口中创建一个4x4网格:
-- Open the window and create a viewport
MOAISim.openWindow("Example", 512, 512)
viewport = MOAIViewport.new()
viewport:setSize(512, 512)
viewport:setScale(512, 512)
-- Create a layer
layer = MOAILayer2D.new()
layer:setViewport(viewport)
MOAISim.pushRenderPass(layer)
-- Create a 4x4 grid of 64x64px squares
grid = MOAIGrid.new()
grid:initGrid(4, 4, 64)
grid:setRow(1, 1, 1, 1, 1)
grid:setRow(2, 1, 1, 1, 1)
grid:setRow(3, 1, 1, 1, 1)
grid:setRow(4, 1, 1, 1, 1)
-- Load the image file
deck = MOAITileDeck2D.new()
deck:setTexture("squares.png")
deck:setSize(2, 2)
-- Make a prop with that grid and image set
prop = MOAIProp2D.new()
prop:setDeck(deck)
prop:setGrid(grid)
prop:setLoc(-256, -256)
-- Add it to the layer so it will be rendered
layer:insertProp(prop)
Run Code Online (Sandbox Code Playgroud)
之后,如果要更改特定单元格的颜色,请使用该
setTile
方法选择单元格中使用的套牌中的哪个项目.
-- Change the color of cell 1,1 to the second item in the deck
grid:setTile(1, 1, 2)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2311 次 |
最近记录: |