当前位置:网站首页>Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
2022-07-05 04:56:00 【Meteor spot】
Register touch events :
function RankCenterPanel:registerTouchListener()
local listener = cc.EventListenerTouchOneByOne:create()
listener:setSwallowTouches(true)
listener:registerScriptHandler(function(touch, event)
return self:onTouchBegan(touch, event)
end, cc.Handler.EVENT_TOUCH_BEGAN)
listener:registerScriptHandler(function(touch, event)
self:onTouchEnded(touch, event)
end, cc.Handler.EVENT_TOUCH_ENDED)
ls.Director:getEventDispatcher():addEventListenerWithFixedPriority(listener, -1)
self._touchListener = listener
end
Initialize call :self:registerTouchListener()
Cancel the touch event :
function RankCenterPanel:unregisterTouchListener()
ls.removeEventListener(self._touchListener)
self._touchListener = nil
end
local function onTouchBegan(touch, event)
local touchPos = self:convertTouchToNodeSpace(touch)
return cc.rectContainsPoint(cc.rect(0,0,100,100), touchPos)
end
local function onTouchEnded(touch, event)
local touchPos = self:convertTouchToNodeSpace(touch)
if (cc.rectContainsPoint(cc.rect(cc.rect(0,0,100,100), touchPos)) then
print(" In this area ");
end
end
边栏推荐
- Minor spanning tree
- Function overloading
- Flutter 小技巧之 ListView 和 PageView 的各种花式嵌套
- UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
- #775 Div.1 C. Tyler and Strings 组合数学
- Manually implement heap sorting -838 Heap sort
- AutoCAD - command repetition, undo and redo
- AutoCAD - Zoom previous
- [Business Research Report] Research Report on male consumption trends in other economic times -- with download link
- 2022/7/2做题总结
猜你喜欢
AutoCAD - scaling
Minor spanning tree
stm32Cubemx(8):RTC和RTC唤醒中断
【acwing】837. Number of connected block points
Panel panel of UI
Autocad-- dynamic zoom
AutoCAD - isometric annotation
2022 thinking of mathematical modeling D problem of American college students / analysis of 2022 American competition D problem
Leetcode word search (backtracking method)
An article takes you to thoroughly understand descriptors
随机推荐
【acwing】528. cheese
3dsmax2018 common operations and some shortcut keys of editable polygons
2022 thinking of mathematical modeling D problem of American college students / analysis of 2022 American competition D problem
Sixth note
質量體系建設之路的分分合合
[groovy] closure (closure call | closure default parameter it | code example)
Forecast report on research and investment prospects of Chinese wormwood industry (2022 Edition)
Function template
Download the details and sequence of the original data access from the ENA database in EBI
2021 huashubei mathematical modeling idea + reference + paper
669. 修剪二叉搜索树 ●●
[groovy] closure (Introduction to closure class closure | this, owner, delegate member assignment and source code analysis)
用 Jmeter 工具做个小型压力测试
669. Prune binary search tree ●●
Unity intelligent NPC production -- pre judgment walking (method 1)
[groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
2020-10-27
Group counting notes (1) - check code, original complement multiplication and division calculation, floating point calculation
Panel panel of UI
Unity writes timetables (without UI)