当前位置:网站首页>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
边栏推荐
- Unity and database
- [LeetCode] 整数反转【7】
- Recherche de mots pour leetcode (solution rétrospective)
- Understand encodefloatrgba and decodefloatrgba
- 質量體系建設之路的分分合合
- Judge the position of the monster in the role under unity3d
- Thinking of 2022 American College Students' mathematical modeling competition
- MD5 bypass
- China needle coke industry development research and investment value report (2022 Edition)
- [groovy] closure (closure parameter list rule | default parameter list | do not receive parameters | receive custom parameters)
猜你喜欢
Introduce Hamming distance and calculation examples
Chinese notes of unit particle system particle effect
AutoCAD - workspace settings
Solution of circular dependency
Autocad-- Real Time zoom
UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
JVM 原理和流程简介
2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling
The 22nd Spring Festival Gala, an immersive stage for the yuan universe to shine into reality
Is $20billion a little less? Cisco is interested in Splunk?
随机推荐
【acwing】837. Number of connected block points
Rip notes [rip message security authentication, increase of rip interface measurement]
Common database statements in unity
Sixth note
669. 修剪二叉搜索树 ●●
XSS injection
Establish cloth effect in 10 seconds
Unity synergy
Download the details and sequence of the original data access from the ENA database in EBI
Fluent objects and lists
Common technologies of unity
Manually implement heap sorting -838 Heap sort
Variable category (automatic, static, register, external)
Dotween usage records ----- appendinterval, appendcallback
Function template
China polyurethane rigid foam Market Research and investment forecast report (2022 Edition)
中国溶聚丁苯橡胶(SSBR)行业研究与预测报告(2022版)
mysql審計日志歸檔
【acwing】240. food chain
C4D simple cloth (version above R21)