android - Corona SDK - 如何实现对象取消触摸
<p><p>我正在使用 Corona SDK 开发游戏,我有很多球要在游戏中显示。我已经为所有球对象实现了 <code>TouchListener</code> <a href="/image/wzcVo.png" rel="noreferrer noopener nofollow"><img src="/image/wzcVo.png" alt="enter image description here"/></a> .</p>
<p>代码在这里</p>
<pre><code>local function ballTouchEvent(e)
local touchedBall = e.target
local phase = e.phase
if phase == "began" then
log("Touch began Phase")
elseif phase == "moved" then
log("Moved Phase")
elseif phase == "ended" or phase == "cancelled" then
log("Ended Phase")
end
return true
end
ball:addEventListener("touch",ballTouchEvent)
</code></pre>
<p>当用户触摸任何显示的球并将他的触摸移动到白色背景(没有球的地方)时,我想实现一些功能。谁能指导我如何实现这一点?提前致谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在所有球后面实现一个 React 并为该 react 实现点击监听器。这样当用户离开空白区域时,将调用 react 监听器的结束阶段,您可以将您的实现放在那里您想做的事情。</p>
<pre><code>function scene:create( event )
sceneGroup = self.view
local rect = display.newRect(centerX, centerY, constants.screenWidth, constants.screenHeight)
-- rect:setFillColor( 0.0 )
rect.name = "background"
rect:addEventListener("touch",backTouchEvent)
sceneGroup:insert( rect )
end
</code></pre></p>
<p style="font-size: 20px;">关于android - Corona SDK - 如何实现对象取消触摸,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35314807/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35314807/
</a>
</p>
页:
[1]