我正在学习corona -这是下面的代码,当两个对象重叠时,它变成了一个对象(一起移动),我不知道发生了什么……
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
local physics = require( "physics" )
physics.start()
local crate1 = display.newImage( "crate.png", display.contentCenterX, 100 )
crate1.name = "crate1"
local crate2 = display.newImage( "crate.png", display.contentCenterX + 100, 100 )
crate2.name = "crate2"
crate1:scale(0.2, 0.2)
crate2:scale(0.2, 0.2)
local bodyTouched = function(event)
if(crate1.name == event.target.name and event.phase == "moved")
then
print("Moved " , event.target.name )
crate1.x = event.x
crate1.y = event.y
elseif (crate2.name == event.target.name and event.phase == "moved")
then
print( "Moved ", event.target.name )
crate2.x = event.x
crate2.y = event.y
end
end
physics.addBody( crate1, "static")
physics.addBody( crate2, "static")
crate1:addEventListener( "touch", bodyTouched )
crate2:addEventListener( "touch", bodyTouched )发布于 2016-06-25 17:13:26
请参阅Corona文档。https://docs.coronalabs.com/daily/guide/events/detectEvents/index.html#TOC
部分:了解命中事件
通常,您应该阅读有关您使用的任何内容的文档。您的触摸事件将通过与事件坐标相交的所有显示对象传播。该事件将在其途中触发所有已注册的事件侦听器。
为了避免多个侦听器触发您的事件侦听器,bodyTouch必须返回true,这将告诉Corona您处理了事件,不应该再调用侦听器。
https://stackoverflow.com/questions/38027573
复制相似问题