Cocos2d-x3.2 双击事件

Cocos2d-x3.2 双击事件,第1张

概述1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 //GameScene.h   #include "cocos2d.h"   USING_NS_CC;   class  GameScene :  public  cocos2d::Layer { public :      static  cocos2d
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 //GameScene.h #include"cocos2d.h" USING_NS_CC; class GameScene: public cocos2d::Layer { : static cocos2d::Scene*createScene(); virtual bool init(); voID singleClickEvent(); doubleClickEvent(); funCallback( float dt); ontouchBegan(touch*touch,Event*unused_event); CREATE_FUNC(GameScene); private : //注意不能用auto关键字 Sizesize; Sprite*sprite; isClicked; };



? 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
//GameScene.cpp #include"GameScene.h" USING_NS_CC; cocos2d::Scene*GameScene::createScene() { auto scene=Scene::create(); //创建一个场景 layer=GameScene::create(); //创建一个图层 scene->addChild(layer); return scene; } //初始化当前的图层 GameScene::init() { if (!Layer::init()) //初始化父类 return false ; //获取屏幕大小 size=Director::getInstance()->getVisibleSize(); //autosize=Director::getInstance()->getWinSize(); //添加一个图片精灵 sprite=Sprite::create( "OnePIEce_1.png" ); sprite->setposition(Vec2(size.wIDth/2,size.height/2)); this ->addChild(sprite); isClicked= ; //创建监听事件对象 Listener=EventListenertouchOneByOne::create(); //定义监听事件的回调函数 Listener->ontouchBegan=CC_CALLBACK_2(GameScene::ontouchBegan, ); //在事件分发器中注册 _eventdispatcher->addEventListenerWithSceneGraPHPriority(Listener,monospace!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; wIDth:auto!important; Font-size:1em!important; min-height:inherit!important">); true ; @H_502_500@ } GameScene::singleClickEvent() { log ( "Singleclick" ); } GameScene::doubleClickEvent() { "Doubleclick" ); } GameScene::funCallback( dt) { (isClicked) { ; singleClickEvent(); } } GameScene::ontouchBegan(touch*touch,Event*unused_event) { (isClicked) { ; doubleClickEvent(); } else { ; //0.3秒内再次点击将再次调用ontouchBegan函数,0.3秒后再次点击将调用funCallback函数 scheduleOnce(schedule_selector(GameScene::funCallback),0.3f); } ; }
总结

以上是内存溢出为你收集整理的Cocos2d-x3.2 双击事件全部内容,希望文章能够帮你解决Cocos2d-x3.2 双击事件所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存