Cocos2d-x_单点触摸

Cocos2d-x_单点触摸,第1张

概述//// HelloWorldScene.h//#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocos-ext.h"#include "TestLayer.h"USING_NS_CC;USING_NS_CC_EXT;class Hello
//// HelloWorldScene.h//#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocos-ext.h"#include "TestLayer.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d::cclayer{public:    virtual bool init();    static cocos2d::CCScene* scene();    CREATE_FUNC(HelloWorld);    // cclayer已经实现CCtouchDelegate协议,所以cclayer的子类不用再次调用此接口    // 重写“单点”触摸回调函数    virtual bool cctouchBegan(CCtouch *ptouch,CCEvent *pEvent);    virtual voID cctouchmoved(CCtouch *ptouch,CCEvent *pEvent);    virtual voID cctouchended(CCtouch *ptouch,CCEvent *pEvent);    virtual voID cctouchCancelled(CCtouch *ptouch,CCEvent *pEvent);        // 重写生命周期函数    virtual voID onEnter();    virtual voID onExit();    };#endif

//// HelloWorldScene.cpp//#include "HelloWorldScene.h"USING_NS_CC;CCScene* HelloWorld::scene(){    CCScene *scene = CCScene::create();    HelloWorld *layer = HelloWorld::create();    scene->addChild(layer);        return scene;}bool HelloWorld::init(){    if ( !cclayer::init() )    {        return false;    }        CCSize winSize = CCDirector::sharedDirector()->getWinSize();        return true;}voID HelloWorld::onEnter(){    cclayer::onEnter();    CCDirector::sharedDirector()->gettouchdispatcher()->addTargetedDelegate(this,false);  // 增加“单点”触摸代理        /*     使用导演获得触摸事件调度者,给它添加一个代理,代理为this     */}voID HelloWorld::onExit(){    cclayer::onExit();    CCDirector::sharedDirector()->gettouchdispatcher()->removeDelegate(this);        /*     使用导演获得触摸事件调度者,把当前的代理this删除掉     */}bool HelloWorld::cctouchBegan(cocos2d::CCtouch *ptouch,cocos2d::CCEvent *pEvent){    cclOG("HelloWorld::cctouchBegan");    return true;}voID HelloWorld::cctouchmoved(cocos2d::CCtouch *ptouch,cocos2d::CCEvent *pEvent){    cclOG("HelloWorld::cctouchmoved");}voID HelloWorld::cctouchended(cocos2d::CCtouch *ptouch,cocos2d::CCEvent *pEvent){    cclOG("HelloWorld::cctouchended");}voID HelloWorld::cctouchCancelled(cocos2d::CCtouch *ptouch,cocos2d::CCEvent *pEvent){    cclOG("HelloWorld::cctouchCancelled");}
总结

以上是内存溢出为你收集整理的Cocos2d-x_单点触摸全部内容,希望文章能够帮你解决Cocos2d-x_单点触摸所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存