Ios Can';在cocos2d-xv3上无法进行多点触摸操作

Ios Can';在cocos2d-xv3上无法进行多点触摸操作,ios,cocos2d-x,multi-touch,Ios,Cocos2d X,Multi Touch,我正在使用cocos2d-xv3.3rc0 我正在尝试处理多点触控,但我只收到一次触控。 它的行为类似于单触,而不是多触。当我触摸超过一根手指时,Ontouchsbegan只打了一次电话 希望有人能帮我解决这个问题 这是我启用多点触摸的代码 ControlLayer.h #include "cocos2d.h" class ControlLayer : public cocos2d::Layer{ public: static ControlLayer* create();

我正在使用cocos2d-xv3.3rc0
我正在尝试处理多点触控,但我只收到一次触控。
它的行为类似于单触,而不是多触。当我触摸超过一根手指时,Ontouchsbegan只打了一次电话

希望有人能帮我解决这个问题

这是我启用多点触摸的代码

ControlLayer.h

#include "cocos2d.h"

class ControlLayer : public cocos2d::Layer{


public:

    static ControlLayer* create();
    virtual bool init();

    void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *unused_event);
    void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *unused_event);
    void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event *unused_event);

};
#包括“cocos2d.h”
类ControlLayer:public cocos2d::Layer{
公众:
静态ControlLayer*创建();
虚拟bool init();
void onTouchesBegan(const std::vector&touch,cocos2d::Event*未使用的事件);
void onTouchesMoved(const std::vector&touchs,cocos2d::Event*未使用的事件);
void ontouchesend(const std::vector&touch,cocos2d::Event*未使用的事件);
};
ControlLayer.cpp

bool ControlLayer::init(){

    if (!Layer::init()){
        return false;
    }

    auto touchListener = EventListenerTouchAllAtOnce::create();
    touchListener->onTouchesBegan = CC_CALLBACK_2(ControlLayer::onTouchesBegan, this);
    touchListener->onTouchesMoved = CC_CALLBACK_2(ControlLayer::onTouchesMoved, this);
    touchListener->onTouchesEnded = CC_CALLBACK_2(ControlLayer::onTouchesEnded, this);

    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, this);

    return true;
}

void ControlLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event){
    CCLOG("onTouchesBegan[%lu]", touches.size());
}
void ControlLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *unused_event){
    CCLOG("onTouchesMoved[%lu]", touches.size());
}
void ControlLayer::onTouchesEnded(const std::vector<Touch*>& touches, Event *unused_event){

}
boolcontrollayer::init(){
如果(!Layer::init()){
返回false;
}
auto-touchListener=EventListenerTouchAllAtOnce::create();
touchListener->onTouchesBegan=CC_CALLBACK_2(ControlLayer::onTouchesBegan,this);
touchListener->OntouchsMoved=CC_CALLBACK_2(ControlLayer::OntouchsMoved,this);
touchListener->onTouchesEnded=CC_CALLBACK_2(ControlLayer::onTouchesEnded,this);
Director::getInstance()->getEventDispatcher()->AddEventListenerWithCeneGraphPriority(touchListener,this);
返回true;
}
void ControlLayer::onTouchesBegan(const std::vector&touch,事件*未使用的事件){
CCLOG(“onTouchesBegan[%lu]”,touch.size();
}
void ControlLayer::ontouchsmoved(const std::vector&touch,事件*未使用的事件){
CCLOG(“ontouchsmoved[%lu]”,touch.size());
}
void ControlLayer::ontouchesend(const std::vector&touch,事件*未使用的事件){
}

您必须在每个平台上启用多点触控以支持本机操作

以下是一个示例(iOS):

-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项{
//应用程序启动后自定义的覆盖点。
//将视图控制器的视图添加到窗口并显示。
窗口=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]边界]];
//初始化视图
CCEAGLView*eaglView=[CCEAGLView视图带边框:[窗口边界]
像素格式:kEAGLColorFormatRGBA8
深度格式:GL_DEPTH24_模具8_OES
巴弗:没有
共享组:无
多重取样:否
样本数:0];

[AgLVIEW StPixEndoTouCuffel:Yes;//您必须在项目的IOS部分启用多点触摸,即使项目的其余部分是用C++编写的。模板项目也有行<代码> [AgLVIEW StSuffEndoTouCuff:No.];准备好将“否”更改为“是”。

对于iOS,您需要启用它。从Cocos2d-x 3.16开始,修改由
COCOCOS new
命令行工具生成的
RootViewController.mm
的单行,以启用多点触控

--- a/proj.ios_mac/ios/RootViewController.mm
+++ b/proj.ios_mac/ios/RootViewController.mm
@@ -52,7 +52,7 @@
                                      numberOfSamples: 0 ];

     // Enable or disable multiple touches
-    [eaglView setMultipleTouchEnabled:NO];
+    [eaglView setMultipleTouchEnabled:YES];

什么是CCLOG(“onTouchesBegan[%lu]”,touch.size());在onTouchesBegan中打印?日志是“onTouchesBegan[1]”问题是,对于C++的COCOS2D-X,你的答案是用COCOS2D的Objto-C。@ Wistelkar,我的答案是COCOS2D X。每个本地AppDeaveTeo都会委托每个UIApple委托调用到共享(C++)。代理。因此,启用多点触控的原则是有效的。我给出的示例是iOS实现。我不可能把每个实现都放在答案中。我明白了。我以为你的“示例”就是“答案”。如果这只是一个例子,我想删除我的否决票。但是,它说我不能删除我的否决票,除非你的帖子被编辑。你能编辑你的帖子,这样我就可以删除我的否决票吗?
--- a/proj.ios_mac/ios/RootViewController.mm
+++ b/proj.ios_mac/ios/RootViewController.mm
@@ -52,7 +52,7 @@
                                      numberOfSamples: 0 ];

     // Enable or disable multiple touches
-    [eaglView setMultipleTouchEnabled:NO];
+    [eaglView setMultipleTouchEnabled:YES];