在
void onTouchesBegan(const std::vector<Touch*>& touches, Event * unused_event)
{
_info->setString(String::createWithFormat("%d", touches.size())->getCString());
}
发现size始终是1,在touchesmove里则正常,是我用法有误导致的还是本来就这样??
我是在手机上测试的
补充下,我是在手机上测试的,其他人有碰到过吗
看了下代码,好像began,end里永远只有一个touch
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesBegin(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) {
intptr_t idlong = id;
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &idlong, &x, &y);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesEnd(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) {
intptr_t idlong = id;
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &idlong, &x, &y);
}
吐槽下,论坛真是一潭死水啊
无论单点还是多点触摸,touch的began都只有一个,单点是传一个点,多点是传一个数组。
move,当然不一样了,是会实时监听的。
你仔细理解一下。
虽然传的是一个数组,但是在TouchesJni.cpp中,handleTouchesBegin(1, &idlong, &x, &y);个数始终是1,所以began里的数组大小始终是1,对吗
void GLView::handleTouchesBegin(int num, intptr_t ids], float xs], float ys])
{
intptr_t id = 0;
float x = 0.0f;
float y = 0.0f;
int unusedIndex = 0;
EventTouch touchEvent;
for (int i = 0; i < num; ++i)
{
id = ids*;
x = xs*;
y = ys*;
auto iter = g_touchIdReorderMap.find(id);
// it is a new touch
if (iter == g_touchIdReorderMap.end())
{
unusedIndex = getUnUsedIndex();
// The touches is more than MAX_TOUCHES ?
if (unusedIndex == -1) {
CCLOG("The touches is more than MAX_TOUCHES, unusedIndex = %d", unusedIndex);
continue;
}
Touch* touch = g_touches = new (std::nothrow) Touch();
touch->setTouchInfo(unusedIndex, (x - _viewPortRect.origin.x) / _scaleX,
(y - _viewPortRect.origin.y) / _scaleY);
CCLOGINFO("x = %f y = %f", touch->getLocationInView().x, touch->getLocationInView().y);
g_touchIdReorderMap.insert(std::make_pair(id, unusedIndex));
touchEvent._touches.push_back(touch);
}
}
if (touchEvent._touches.size() == 0)
{
CCLOG("touchesBegan: size = 0");
return;
}
touchEvent._eventCode = EventTouch::EventCode::BEGAN;
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->dispatchEvent(&touchEvent);
}***