跟进这个问题,Storyboard with Ceramic Tile Engine 和 Collision Detection 仍然是个谜。这是代码:
-- hide status bar
display.setStatusBar(display.HiddenStatusBar)
local storyboard = require("storyboard")
--Set up the physics world
local physics = require("physics")
physics.start()
physics.setGravity(0, 0)
physics.setDrawMode('hybrid')
local scene = storyboard.newScene()
local widget = require("widget")
-- Add Hero to Physics
local hero = display.newImage("images/man.png")
hero.x = 40
hero.y = 80
local heroCollisionFilter = { categoryBits = 4, maskBits = 2 }
local heroBody = { filter=heroCollisionFilter, isSensor=true }
physics.addBody(hero, "dynamic", heroBody)
function scene:createScene( event )
local group = self.view
local ceramic = require("Ceramic")
ceramic.showPrints = false
local map = ceramic.buildMap("maps/map.lua")
-- collisionLayer = map.layer['Collision']
-- collisionLayer.ccName = "map"
-- physics.addBody(collisionLayer, "static", { friction=0.5, bounce=0.3 } )
map.y = 0
map.setCameraDamping(10)
map.layer['World']:insert(hero)
end
function onGlobalCollision(event)
if(event.phase == "began") then
print( "Global report: " .. event.object1.ccName .. " & " .. event.object2.ccName .. " collision began" )
elseif(event.phase == "ended") then
print( "Global report: " .. event.object1.ccName .. " & " .. event.object2.ccName .. " collision ended" )
end
print( "**** " .. event.element1 .. " -- " .. event.element2 )
end
Runtime:addEventListener("collision", onGlobalCollision)
scene:addEventListener( "createScene", scene )
return scene
截图如下:
但是,冲突永远不会触发,因为print
消息根本不会出现在终端中。
我在用着:
- 电晕SDK
- 瓷砖引擎
- 电晕模块:故事板,物理
如何启用碰撞检测?参数是否正确?
编辑 2013/10/27
平铺地图设置如下:
在 Mac OS X 中运行时,不会发生碰撞(只有混合层会改变颜色)。
在 Windows 7 中运行时,代码在此行崩溃:
ceramic.buildMap("maps/map.lua")
有错误:
尝试在 Ceramic.lua 中调用全局“reversePolygon”(一个 nil 值):617
在我注释掉以下几行之后,错误就消失了:
collisionLayer = map.layer['Collision']
collisionLayer.ccName = "map"
physics.addBody(collisionLayer, "static", { friction=0.5, bounce=0.3 } )
但不会调用碰撞函数。