【问题标题】:How to add Swipe Gesture?如何添加滑动手势?
【发布时间】:2015-02-13 09:44:36
【问题描述】:
我想在 Cocos 2dx 3.2 中使用 Swipe 手势。
当然,我使用了扩展sdk。
https://github.com/spalx/cocos2d-x-extensions
但这不适用于我的情况。
我想做的事:
我在图层中使用了几个菜单项。
我想在这些项目上添加滑动功能。
所以它应该检测菜单项的点击并滑动整个图层。
但是,如果我在菜单项上滑动,则它无法检测到滑动。
我尝试了扩展。但它是一样的。
我可以实现我的想法吗?
感谢您的宝贵时间。
【问题讨论】:
标签:
ios
objective-c
cocos2d-x
cocos2d-x-3.0
【解决方案1】:
据我所知,你不能滑动菜单项,所以首先:
1. 将Menu Items改为Sprites,自行处理。
2.我的swipe实现是这样的:
onTouchBegan() {
getTouch
}
onTouchMoved() {
//swipe right
if (touch.getDelta().x > 10) {
//swiped right
}
//swipe left
if (touch.getDelta().x < 10) {
//swiped left
}
//swipe up
if (touch.getDelta().y > 10) {
//swiped up
}
//swipe down
if (touch.getDelta().y < 10) {
//swiped down
}
}