大佬教程收集整理的这篇文章主要介绍了cocos2dx-触摸、传感器、物理按键及绘图(四),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这些都是添加在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);
//添加加速度传感器 //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);
//物理按键监听 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-触摸、传感器、物理按键及绘图(四)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。