cocos2dx-触摸、传感器、物理按键及绘图(四)

cocos2dx-触摸、传感器、物理按键及绘图(四),第1张

概述这些都是添加在init()方法中 1.单点触摸事件监听 2.多点触摸 //多点触摸 auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan=[](std::vector<Touch*> ts,Event *e){ log("ontouchbegin");

这些都是添加在init()方法中


1.单点触摸事件监听


2.多点触摸

    //多点触摸    auto Listener = EventListenertouchAllAtOnce::create();    Listener->ontouchesBegan=[](std::vector<touch*> ts,Event *e){        log("ontouchbegin");    };    //移动    Listener->ontouchesMoved=[](std::vector<touch*> ts,Event *e){        log("touches moved and counts is %ld",ts.size());    };        //this表示这个层    Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(Listener,this);


3.加速传感器
//添加加速度传感器    //1.打开传感器    Device::setAccelerometerEnabled(true);    //2.监听传感器    Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(EventListeneracceleration::create([](acceleration *a,Event *e){        log("x:%g,y:%g,z:%g",a->x,a->y,a->z);            }),this);

4.物理按键
   //物理按键监听    auto Listener = EventListenerKeyboard::create();    Listener->onkeyreleased=[](EventKeyboard::KeyCode code,Event*e){        log("key code :%d",code);        switch (code) {            case EventKeyboard::KeyCode::KEY_BACKSPACE:                Director::getInstance()->end();                break;            case EventKeyboard::KeyCode::KEY_MENU:                log("this is menu");            default:                break;        }    };    Director::getInstance()->getEventdispatcher()->addEventListenerWithSceneGraPHPriority(Listener,this);

5.绘图

    auto r = cocos2d::DrawNode::create();    addChild(r);//    r->drawDot(Vec2(100,100),10,cocos2d::color4F::GREEN);    r->drawRect(Point(20,10),Point(100,color4F::RED);    r->drawSolIDRect(Point(120,120),Point(500,500),color4F::BLUE);
总结

以上是内存溢出为你收集整理的cocos2dx-触摸、传感器、物理按键及绘图(四)全部内容,希望文章能够帮你解决cocos2dx-触摸、传感器、物理按键及绘图(四)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1036192.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存