• cocos2d 单点触控


    //
    //  Single.hpp
    //  dev
    //
    //  Created by sun on 15/12/20.
    //
    //
    
    #ifndef Single_hpp
    #define Single_hpp
    
    #include <stdio.h>
    #include "cocos2d.h"
    #include "HelloWorldScene.h"
    USING_NS_CC;
    class Single : public CCLayer
    {
    public:
        virtual bool init();
        static CCScene* scene();
        CREATE_FUNC(Single);
        
        //touch
    private:
        void registerWithTouchDispatcher(void);
        bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
        void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
        void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
        void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);
    };
    
    #endif /* Single_hpp */
    
    
    //
    //  Single.cpp
    //  dev
    //
    //  Created by sun on 15/12/20.
    //
    //
    
    #include "Single.hpp"
    
    CCScene* Single::scene()
    {
        CCScene *scene = CCScene::create();
        Single  *layer = Single::create();
        scene->addChild(layer);
        return scene;
    }
    
    bool Single::init()
    {
        if ( !CCLayer::init() )
        {
            return false;
        }
        
        this->setTouchEnabled(true);
        
        return true;
    }
    
    void Single::registerWithTouchDispatcher()
    {
        CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
    }
    
    
    bool Single::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
    {
        CCPoint touchpoint = pTouch->getLocation();		 //获取触摸坐标
        CCLOG("touch began, touchpoint is %f %f", touchpoint.x,touchpoint.y);
        
        CCScene* helloscene=HelloWorld::scene();
        CCDirector::sharedDirector()->replaceScene(helloscene);
        
        
        return true;      //true表示继续响应CCTouchMove,CCTouchEnd,CCTouchCancalled,false表示不响应。
    }
    
    
    void Single::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
    {
        CCPoint touchpoint = pTouch->getLocation();		 //获取触摸坐标
        CCLOG("touch moved, touchpoint is %f %f", touchpoint.x,touchpoint.y);
    }
    
    
    void Single::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
    {
        CCPoint touchpoint = pTouch->getLocation(); //获取触摸坐标
        CCLOG("touch ended, touchpoint is %f %f", touchpoint.x,touchpoint.y);
    }
    
    
    void Single::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent)
    {
        CCPoint touchpoint = pTouch->getLocation();		 //获取触摸坐标
        CCLOG("touch cancelled, touchpoint is %f %f", touchpoint.x,touchpoint.y);
    }
    
    
    
    
  • 相关阅读:
    理解 Java Thread ContextClassLoader(线程上下文类加载器)
    StringUtils工具类常用方法汇总2(截取、去除空白、包含、查询索引)
    StringUtils工具类常用方法汇总1(判空、转换、移除、替换、反转)
    数组去重(2)
    数组去重(1)
    查找数组中的最大值(最小值)及相对应的下标
    javascript 隐式转换 == 之 [ ]==![ ] 结果为true,而{ }==!{ } 结果为false
    圣杯布局(2)>>>>>
    圣杯布局(1)>>>>>
    二分查找里的upper bound与lower bound的实现与分析
  • 原文地址:https://www.cnblogs.com/yufenghou/p/5068035.html
Copyright © 2020-2023  润新知