好吧,这里借出原文的名字,正好看到了,先po出原文地址:http://bbs.9ria.com/thread-157487-1-1.html
这里具体的原理利用了点16进制运算的原理,具体的请参看原文,这里先放出效果图
这里直接给出简单demo的实现:
local layer = display.newColorLayer(cc.c4b(255, 123, 33, 127))
layer:addTo(self)
local w, h = 64, 64
local rows, cols = 10, 14
local x, y = 0, 0
self.childs = {}
for i = 1, rows do
self.childs* = {}
local sprite
for j = 1, cols do
sprite = display.newSprite("tileds/0.png")
sprite:align(display.LEFT_BOTTOM, x, y)
sprite:scale(w / sprite:getContentSize().width, h / sprite:getContentSize().height)
sprite:addTo(layer)
x = x + w
self.childs* = {sprite = sprite, leftTop = 0, leftBottom = 0, rightTop = 0, rightBottom = 0}
end
x = 0
y = y + h
end
layer:addNodeEventListener(cc.NODE_TOUCH_EVENT, function(event)
local row = math.floor(event.y / h) + 1
local col = math.floor(event.x / w) + 1
if row > #self.childs or col > #self.childs then
return
end
local child = self.childs
if child.leftTop ~= 4 then
child.leftTop = child.leftTop + 4
end
if col + 1 <= #self.childs then
child = self.childs
if child.rightTop ~= 8 then
child.rightTop = child.rightTop + 8
end
end
if row >= 2 then
child = self.childs
if child.leftBottom ~= 1 then
child.leftBottom = child.leftBottom + 1
end
end
if row >= 2 and (col + 1 <= #self.childs) then
child = self.childs
if child.rightBottom ~= 2 then
child.rightBottom = child.rightBottom + 2
end
end
for i = 1,rows do
for j = 1,cols do
local c = self.childs*
local num = c.leftBottom + c.leftTop + c.rightBottom + c.rightTop
if num ~= 0 then
if num > 15 then
num = 15
end
c.sprite:setTexture("tileds/" .. num .. ".png")
end
end
end
end)
```
具体的,就是每次点击以后,点击中的方块,会改变自身,自身右边,和自身下边,还有自身右下的四个方块,这里主要图还有点特殊处理
用来制作地图和迷雾效果还是挺棒的
顺便求教下,这两天玩瘟疫公司,很想做里面的世界地图点击,由于都是不规则区域,查看了下apk,没加密的有两张svg的矢量图,不过cocos不支持
这里目前想到的一个实现是:用两张图,底图是地图,上面盖一张alpha为0的掩码,然后给每个国家设置不同的颜色,点击的时候,获取点击点的颜色值,
然后根据一张对应表,判断点中的是那个国家,看了zrong的文章,好像那个效率比较低的获取像素点颜色的方法已经没了,用的quick 3.3final
大家还有什么别的好方法吗?
不要那种每个国家造一张png图,叠上去的,3Q
***




