• cocos2d 多点触控


    #ifndef __HELLOWORLD_SCENE_H__
    #define __HELLOWORLD_SCENE_H__
    
    #include "cocos2d.h"
    
    USING_NS_CC;
    class HelloWorld : public cocos2d::CCLayer
    {
    public:
        virtual bool init();
        static cocos2d::CCScene* scene();
        void menuCloseCallback(CCObject* pSender);
        CREATE_FUNC(HelloWorld);
    //touch
    private:
        virtual void registerWithTouchDispatcher(void);
        virtual void ccTouchesBegan(CCSet * set,CCEvent * e);
        virtual void ccTouchesMoved(CCSet * set,CCEvent * e);
        virtual void ccTouchesEnded(CCSet * set,CCEvent * e);
        
        //写上生命周期函数
        virtual void onEnter();
        virtual void onExit();
    };
    
    #endif // __HELLOWORLD_SCENE_H__
    
    
    #include "HelloWorldScene.h"
    
    CCScene* HelloWorld::scene()
    {
        CCScene *scene = CCScene::create();
        HelloWorld *layer = HelloWorld::create();
        scene->addChild(layer);
        return scene;
    }
    
    bool HelloWorld::init()
    {
        if ( !CCLayer::init() )
        {
            return false;
        }
        
        this->setTouchEnabled(true);
        
        return true;
    }
    
    void HelloWorld::registerWithTouchDispatcher(void){
        //注册监听
        CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this,0);
    }
    
    void HelloWorld::ccTouchesBegan(CCSet * set,CCEvent * e)
    {
        CCLOG("hello begin");
    }
    
    
    void HelloWorld::ccTouchesMoved(CCSet * set,CCEvent * e)
    {
        CCLOG("hello moved");
    }
    
    
    void HelloWorld::ccTouchesEnded(CCSet * set,CCEvent * e)
    {
    
        CCLOG("hello ended");
    }
    
    
    void HelloWorld::onEnter()
    {
        CCLayer::onEnter();
    }
    
    void HelloWorld::onExit()
    {
        CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
        CCLayer::onExit();
    }
    
    
    
    
  • 相关阅读:
    Idea中创建maven项目
    安装axios
    配置路由
    安装Mock.js
    安装SCSS
    Incorrect username or password ( access token )
    Navicat使用笔记06Navicat Premium 12的安装、激活
    dump.rdb file All In One
    如何把闲置的 Mac mini 搭建成一个局域网中的 Web 服务器 All In One
    VSCode walkthroughs All In One
  • 原文地址:https://www.cnblogs.com/yufenghou/p/5068039.html
Copyright © 2020-2023  润新知