加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Moai网格与瓷砖颜色

发布时间:2020-12-14 21:47:43 所属栏目:大数据 来源:网络整理
导读:我正在尝试使用Moai SDK为游戏创建网格.网格中的每个图块都应该能够填充颜色. 所以实际上我有两个问题: 使用Moai构建网格的最佳方法是什么? 如何用颜色单独填充每个瓷砖 谢谢 解决方法 What is the best way to build a grid using Moai Moai有一个创建网
我正在尝试使用Moai SDK为游戏创建网格.网格中的每个图块都应该能够填充颜色.

所以实际上我有两个问题:

>使用Moai构建网格的最佳方法是什么?
>如何用颜色单独填充每个瓷砖

谢谢

解决方法

What is the best way to build a grid using Moai

Moai有一个创建网格的对象:MOAIGrid.使用框架
行话,你创建一个网格,并给它一个套牌.然后你把它附在一个道具上
将道具添加到图层. (该图层还需要附加的视口
到窗口.)

How can I fill each tile individually with a color

A Moai deck是图像或图像集合.如果你想要你的
瓷砖是不同的颜色然后你会创建一个甲板上的图像
这些颜色的正方形.

此代码将在窗口中创建一个4×4网格:

-- 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)
grid:setRow(2,1)
grid:setRow(3,1)
grid:setRow(4,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)

之后,如果要更改特定单元格的颜色,请使用
setTile方法选择单元格中使用的套牌中的哪个项目.

-- Change the color of cell 1,1 to the second item in the deck
grid:setTile(1,2)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读