#ifndef __CC_TOUCH_H__
#define __CC_TOUCH_H__

#include "base/CCRef.h"
#include "math/CCGeometry.h"

NS_CC_BEGIN



/** @class Touch
 * @brief Encapsulates the Touch information,such as touch point,id and so on,and provides the methods that commonly used.
 */
class CC_DLL Touch : public Ref
{
public:
    /** 
     * dispatch mode,how the touches are dispathced.
     * @js NA
     */
    enum class dispatchMode
    {
        ALL_AT_ONCE,/** All at once. */
        ONE_BY_ONE,/** One by one. */
    };

    // 构造函数.cocos2dx源码中 void GLView::handletouchesBegin(int num,intptr_t ids[],float xs[],float ys[])调用过。
    Touch() 
    : _id(0),_startPointCaptured(false)
    {
    
    }
    
    /** Set the touch infomation. It always used to monitor touch event.
     *
     * @param id A given id
     * @param x A given x coordinate.
     * @param y A given y coordinate.
     */
    void setTouchInfo(int id,float x,float y)
    {
        _id = id;
        _prevPoint = _point;
        _point.x   = x;
        _point.y   = y;
        
        if (!_startPointCaptured)   // 首次设置touchInfo,startPoint、prevPoint 与 point相等。
        {
            _startPoint = _point;
            _startPointCaptured = true;
            _prevPoint = _point;
        }
    }
    
    // in openGL coordinates.  (开始坐标,前一个坐标,当前坐标)
    Vec2 getStartLocation() const;
    Vec2 getPrevIoUsLocation() const;
    Vec2 getLocation() const;


    // in screen coordinates.  (开始坐标,前一个坐标,当前坐标)
    Vec2 getStartLocationInView() const;
    Vec2 getPrevIoUsLocationInView() const;
    Vec2 getLocationInView() const;
    
    
    
    // 当前坐标和前一个坐标之间的差值。
    Vec2 getDelta() const;
    
    
    /** Get touch id.
     * @js getId
     * @lua getId
     *
     * @return The id of touch.
     */
    int getID() const
    {
        return _id;
    }

private:
    int _id;                    // id
    bool _startPointCaptured;   // 是否捕获过开始点
    Vec2 _startPoint;           // 开始点
    Vec2 _point;                // 当前点
    Vec2 _prevPoint;            // 上一次点坐标
};



NS_CC_END

#endif
#include "base/CCTouch.h"
#include "base/CCDirector.h"

NS_CC_BEGIN

// returns the current touch location in screen coordinates
Vec2 Touch::getLocationInView() const 
{ 
    return _point; 
}

// returns the prevIoUs touch location in screen coordinates
Vec2 Touch::getPrevIoUsLocationInView() const 
{ 
    return _prevPoint; 
}

// returns the start touch location in screen coordinates
Vec2 Touch::getStartLocationInView() const 
{ 
    return _startPoint; 
}

// returns the current touch location in OpenGL coordinates
Vec2 Touch::getLocation() const
{ 
    return Director::getInstance()->convertToGL(_point); 
}

// returns the prevIoUs touch location in OpenGL coordinates
Vec2 Touch::getPrevIoUsLocation() const
{ 
    return Director::getInstance()->convertToGL(_prevPoint);  
}

// returns the start touch location in OpenGL coordinates
Vec2 Touch::getStartLocation() const
{ 
    return Director::getInstance()->convertToGL(_startPoint);  
}

// returns the delta position between the current location and the prevIoUs location in OpenGL coordinates
Vec2 Touch::getDelta() const
{     
    return getLocation() - getPrevIoUsLocation();
}

NS_CC_END

Touch类相对比较简单。

待解决问题:

1.Touch对象在CCGLview的创建,以及整个流程。

2.Director::getInstance()->convertToGL(_point); 坐标转换问题。

#ifndef __CCEVENT_H__
#define __CCEVENT_H__

#include "base/CCRef.h"
#include "platform/CCPlatformMacros.h"


NS_CC_BEGIN

class Node;


// 所有事件的基类
class CC_DLL Event : public Ref
{
public:
    // 内部枚举类Type(使用方法,Event::Type::TOUCH)
    enum class Type
    {
        TOUCH,KEYBOARD,acceleration,MOUSE,FOCUS,GAME_CONTROLLER,CUSTOM
    };
    
public:
    Event(Type type);
    virtual ~Event();

    // 类型
	inline Type getType() const { return _type; };
    
    // 停止传播事件
    inline void stopPropagation() { _isstopped = true; };
    
    // 事件是否停止
    inline bool isstopped() const { return _isstopped; };
    
    // 与node关联的事件才有用,fixedPriority 返回0.(It onlys be available when the event listener is associated with node. It returns 0 when the listener is associated with fixed priority.)
    inline Node* getCurrentTarget() { return _currentTarget; };
    
protected:
    inline void setCurrentTarget(Node* target) { _currentTarget = target; };
    

	Type _type;             // 描述当前对象的事件类型。
    bool _isstopped;        // 描述当前事件是否已经停止。
    Node* _currentTarget;   // 是侦听事件的Node类型的对象。
    
    friend class Eventdispatcher;
};

NS_CC_END

#endif

#include "base/CCEvent.h"

NS_CC_BEGIN

Event::Event(Type type)
: _type(type),_isstopped(false),_currentTarget(nullptr)
{
}

Event::~Event()
{
}


NS_CC_END
Event类是事件类的基类,有3个重要属性:

1.target

2.type

3.isstopped

#ifndef __cocos2d_libs__TouchEvent__
#define __cocos2d_libs__TouchEvent__

#include "base/CCEvent.h"
#include <vector>


NS_CC_BEGIN

class Touch;

#define TOUCH_PERF_DEBUG 1

class CC_DLL EventTouch : public Event
{
public:
    static const int MAX_touches = 15;  // 事件的最大Touch个数。
    
    // 内部枚举类EventCode。在dispatcher event时会用到。
    enum class EventCode
    {
        BEGAN,MOVED,ENDED,CANCELLED
    };

    EventTouch();

    inline EventCode getEventCode() const { return _eventCode; };
    
    // 当前触摸屏幕所有点的列表
    inline const std::vector<Touch*>& gettouches() const { return _touches; };

    // 测试相关方法
#if TOUCH_PERF_DEBUG
    void setEventCode(EventCode eventCode) { _eventCode = eventCode; };
    void settouches(const std::vector<Touch*>& touches) { _touches = touches; };
#endif
    
private:
    EventCode _eventCode;           // 事件code(began,moved,ended,cancelled)
    std::vector<Touch*> _touches;   // touch数组 获取当前触摸屏幕所有点的列表

    friend class GLView;
};


NS_CC_END


#endif
#include "base/CCEventTouch.h"
#include "base/CCTouch.h"

NS_CC_BEGIN

EventTouch::EventTouch()
: Event(Type::TOUCH)
{
    _touches.reserve(MAX_touches);
}

NS_CC_END
EventTouch类继承自Event,加上Event的3个属性,EventTouch共有5个属性:

1.target

2.type

3.isstopped

4.touches:当前触摸屏幕所有点的列表

5.eventCode:该属性在dispatcher中会用到,后面分析。


#ifndef __cocos2d_libs__CCCustomEvent__
#define __cocos2d_libs__CCCustomEvent__

#include <string>
#include "base/CCEvent.h"


NS_CC_BEGIN

class CC_DLL EventCustom : public Event
{
public:
    EventCustom(const std::string& eventName);
    
    inline void setUserData(void* data) { _userData = data; };
    inline void* getUserData() const { return _userData; };
    
    inline const std::string& getEventName() const { return _eventName; };
protected:
    void* _userData;        // User data
    std::string _eventName;
};

NS_CC_END

#endif

#include "base/CCEventCustom.h"
#include "base/CCEvent.h"

NS_CC_BEGIN

EventCustom::EventCustom(const std::string& eventName)
: Event(Type::CUSTOM),_userData(nullptr),_eventName(eventName)
{
}

NS_CC_END

EventCustom类继承自Event,加上Event的3个属性,EventCustom共有5个属性:

1.target

2.type

3.isstopped

4.eventName

5.userData

使用EventCustom的地方还是很多的,这里只粗略介绍下。

#ifndef __CCEVENTLISTENER_H__
#define __CCEVENTLISTENER_H__

#include <functional>
#include <string>
#include <memory>

#include "platform/CCPlatformMacros.h"
#include "base/CCRef.h"


NS_CC_BEGIN

class Event;
class Node;

/** @class EventListener
 *  @brief The base class of event listener.
 *  If you need custom listener which with different callback,you need to inherit this class.
 *  For instance,you Could refer to EventListeneracceleration,EventListenerKeyboard,EventListenerTouchOneByOne,EventListenerCustom.
 */
class CC_DLL EventListener : public Ref
{
public:
    /** Type Event type.*/  // 这个类型与Event的类型有一小点不同,就是将触摸事件类型分成了 One by One (一个接一个) 与  All At Once (同时一起)两种。
    enum class Type
    {
        UNKNowN,TOUCH_ONE_BY_ONE,TOUCH_ALL_AT_ONCE,CUSTOM
    };

    typedef std::string ListenerID;

 
public:
    EventListener();
    bool init(Type t,const ListenerID& listenerID,const std::function<void(Event*)>& callback);
    virtual ~EventListener();

    
    // 纯虚函数监测监听器是否可用
    virtual bool checkAvailable() = 0;
    
    // 纯虚函数,因为clone的方式不同,又需要这个功能接口,所以在设置为纯虚函数,使子类必需实现。
    virtual EventListener* clone() = 0;

    // 当EventListener enabled并且not paused时,EventListener才能接受事件。
    inline void setEnabled(bool enabled) { _isEnabled = enabled; };
    inline bool isEnabled() const { return _isEnabled; };

protected:
    /** Gets the type of this listener
     *  @note It's different from `EventType`,e.g. TouchEvent has two kinds of event listeners - EventListenerOneByOne,EventListenerAllAtOnce
     */
    inline Type getType() const { return _type; };
  
    // eventType && listenerID ===> listeners.  EventListenerTouchOneByOne::LISTENER_ID = "__cc_touch_one_by_one"; EventListenerTouchAllAtOnce::LISTENER_ID = "__cc_touch_all_at_once"; (When event is being dispatched,listener ID is used as key for searching listeners according to event type.)
    inline const ListenerID& getListenerID() const { return _listenerID; };
    
    // 注册
    inline void setRegistered(bool registered) { _isRegistered = registered; };
    inline bool isRegistered() const { return _isRegistered; };
    
    /************************************************
     Sets paused state for the listener
     The paused state is only used for scene graph priority listeners.
     `Eventdispatcher::resumeAllEventListenersForTarget(node)` will set the paused state to `false`,while `Eventdispatcher::pauseAllEventListenersForTarget(node)` will set it to `true`.
     @note 
            1) Fixed priority listeners will never get paused. If a fixed priority doesn't want to receive events,call `setEnabled(false)` instead.
            2) In `Node`'s onEnter and onExit,the `paused state` of the listeners which associated with that node will be automatically updated.
     
     sceneGraPHPriorityListener:
     fixedPriorityListener:不使用_paused属性。
     
     paused状态在node 的“onEnter”和“onExit”中改变
     ************************************************/
    inline void setPaused(bool paused) { _paused = paused; };
    inline bool isPaused() const { return _paused; };
    
    // 获取与listener相关联的node。fixed priority listeners为nullptr。
    inline Node* getAssociatednode() const { return _node; };
    inline void setAssociatednode(Node* node) { _node = node; };
   

    // 用于fixed priority listeners,可以设为不为0的值。
    inline void setFixedPriority(int fixedPriority) { _fixedPriority = fixedPriority; };
    inline int getFixedPriority() const { return _fixedPriority; };

    
protected:
    Type _type;                             // Event listener type
    ListenerID _listenerID;                 // Event listener ID
    std::function<void(Event*)> _onEvent;   // Event callback function
    
    bool _isRegistered;                     // Whether the listener has been added to dispatcher.
    bool _isEnabled;                        // Whether the listener is enabled
    bool _paused;                           // Whether the listener is paused
    
    Node* _node;                            // scene graph based priority
    
    int  _fixedPriority;                    // The higher the number,the higher the priority,0 is for scene graph base priority.
    
    friend class Eventdispatcher;
};

NS_CC_END

#endif

#include "base/CCEventListener.h"

NS_CC_BEGIN

EventListener::EventListener()
{}
    
EventListener::~EventListener() 
{
	cclOGINFO("In the destructor of EventListener. %p",this);
}

bool EventListener::init(Type t,const std::function<void(Event*)>& callback)
{
    _onEvent = callback;
    _type = t;
    _listenerID = listenerID;
    _isRegistered = false;
    _paused = true;
    _isEnabled = true;
    
    return true;
}

bool EventListener::checkAvailable()
{ 
	return (_onEvent != nullptr);
}

NS_CC_END
EventListener是事件监听器的基类,有8个属性:

1.type

2.listenerID

3.onEvent

4.register

5.paused

6.enabled

7.node

8.fixedPriority

#ifndef __cocos2d_libs__CCTouchEventListener__
#define __cocos2d_libs__CCTouchEventListener__

#include "base/CCEventListener.h"
#include <vector>



NS_CC_BEGIN

class Touch;

// 单点触摸监听器
class CC_DLL EventListenerTouchOneByOne : public EventListener
{
public:
    static const std::string LISTENER_ID;
    
    // 创建单点触摸事件监听器
    static EventListenerTouchOneByOne* create();
    EventListenerTouchOneByOne();
    bool init();
    virtual ~EventListenerTouchOneByOne();
    
    // 是否吞噬掉触摸点,如果true,触摸将不会向下层传播。
    bool isSwallowtouches();
    void setSwallowtouches(bool needSwallow);
    
    /// Overrides 重写夫类的纯虚函数。
    virtual EventListenerTouchOneByOne* clone() override;
    virtual bool checkAvailable() override;
    
public:

//    typedef std::function<bool(Touch*,Event*)> ccTouchBeganCallback;
//    typedef std::function<void(Touch*,Event*)> ccTouchCallback;

    // public方法:创建监听器时,需手动设置 onTouch方法(onTouchBegan,onTouchMoved,onTouchEnded,onTouchCancelled)。
    std::function<bool(Touch*,Event*)> onTouchBegan;
    std::function<void(Touch*,Event*)> onTouchMoved;
    std::function<void(Touch*,Event*)> onTouchEnded;
    std::function<void(Touch*,Event*)> onTouchCancelled;
    
private:
    std::vector<Touch*> _claimedtouches;    // 触摸点列表。(onTouchBegan 返回true)&&(listener已经注册)过的Touch对象才会被添加。
    bool _needSwallow;                      // 是否需要吞噬触摸点
    
    friend class Eventdispatcher;
};

// 多点触摸监听器
class CC_DLL EventListenerTouchAllAtOnce : public EventListener
{
public:
    static const std::string LISTENER_ID;
    
    static EventListenerTouchAllAtOnce* create();
    EventListenerTouchAllAtOnce();
    bool init();
    virtual ~EventListenerTouchAllAtOnce();
    
    /// Overrides
    virtual EventListenerTouchAllAtOnce* clone() override;
    virtual bool checkAvailable() override;
public:

    typedef std::function<void(const std::vector<Touch*>&,Event*)> cctouchesCallback;

    cctouchesCallback ontouchesBegan;
    cctouchesCallback ontouchesMoved;
    cctouchesCallback ontouchesEnded;
    cctouchesCallback ontouchesCancelled;
    
    
private:
    
    friend class Eventdispatcher;
};

NS_CC_END

#endif

#include "base/CCEventListenerTouch.h"
#include "base/CCEventdispatcher.h"
#include "base/CCEventTouch.h"
#include "base/CCTouch.h"

#include <algorithm>

NS_CC_BEGIN

const std::string EventListenerTouchOneByOne::LISTENER_ID = "__cc_touch_one_by_one";

EventListenerTouchOneByOne* EventListenerTouchOneByOne::create()
{
    auto ret = new (std::nothrow) EventListenerTouchOneByOne();
    if (ret && ret->init())
    {
        ret->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(ret);
    }
    return ret;
}

EventListenerTouchOneByOne::EventListenerTouchOneByOne()
: onTouchBegan(nullptr),onTouchMoved(nullptr),onTouchEnded(nullptr),onTouchCancelled(nullptr),_needSwallow(false)
{
}

bool EventListenerTouchOneByOne::init()
{
    if (EventListener::init(Type::TOUCH_ONE_BY_ONE,LISTENER_ID,nullptr))
    {
        return true;
    }
    
    return false;
}

EventListenerTouchOneByOne::~EventListenerTouchOneByOne()
{
    cclOGINFO("In the destructor of EventListenerTouchOneByOne,%p",this);
}


void EventListenerTouchOneByOne::setSwallowtouches(bool needSwallow)
{
    _needSwallow = needSwallow;
}

bool EventListenerTouchOneByOne::isSwallowtouches()
{
    return _needSwallow;
}

bool EventListenerTouchOneByOne::checkAvailable()
{
    // Eventdispatcher will use the return value of 'onTouchBegan' to determine whether to pass following 'move','end'
    // message to 'EventListenerTouchOneByOne' or not. So 'onTouchBegan' needs to be set.
    // onTouchBegin 必须需要。
    if (onTouchBegan == nullptr)
    {
        CCASSERT(false,"Invalid EventListenerTouchOneByOne!");
        return false;
    }
    
    return true;
}

EventListenerTouchOneByOne* EventListenerTouchOneByOne::clone()
{
    auto ret = new (std::nothrow) EventListenerTouchOneByOne();
    if (ret && ret->init())
    {
        ret->autorelease();
        
        ret->onTouchBegan = onTouchBegan;
        ret->onTouchMoved = onTouchMoved;
        ret->onTouchEnded = onTouchEnded;
        ret->onTouchCancelled = onTouchCancelled;
        
        ret->_claimedtouches = _claimedtouches;
        ret->_needSwallow = _needSwallow;
    }
    else
    {
        CC_SAFE_DELETE(ret);
    }
    return ret;
}

/////////

const std::string EventListenerTouchAllAtOnce::LISTENER_ID = "__cc_touch_all_at_once";

EventListenerTouchAllAtOnce::EventListenerTouchAllAtOnce()
: ontouchesBegan(nullptr),ontouchesMoved(nullptr),ontouchesEnded(nullptr),ontouchesCancelled(nullptr)
{
}

EventListenerTouchAllAtOnce::~EventListenerTouchAllAtOnce()
{
    cclOGINFO("In the destructor of EventListenerTouchAllAtOnce,this);
}

bool EventListenerTouchAllAtOnce::init()
{
    if (EventListener::init(Type::TOUCH_ALL_AT_ONCE,nullptr))
    {
        return true;
    }
    
    return false;
}

EventListenerTouchAllAtOnce* EventListenerTouchAllAtOnce::create()
{
    auto ret = new (std::nothrow) EventListenerTouchAllAtOnce();
    if (ret && ret->init())
    {
        ret->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(ret);
    }
    return ret;
}

bool EventListenerTouchAllAtOnce::checkAvailable()
{
    // ontouchesBegin、ontouchesMoved、ontouchesEnded、ontouchesCancelled 只需要任意一个不为空就行了
    if (ontouchesBegan == nullptr && ontouchesMoved == nullptr&& ontouchesEnded == nullptr && ontouchesCancelled == nullptr)
    {
        CCASSERT(false,"Invalid EventListenerTouchAllAtOnce!");
        return false;
    }
    
    return true;
}

EventListenerTouchAllAtOnce* EventListenerTouchAllAtOnce::clone()
{
    auto ret = new (std::nothrow) EventListenerTouchAllAtOnce();
    if (ret && ret->init())
    {
        ret->autorelease();
        
        ret->ontouchesBegan = ontouchesBegan;
        ret->ontouchesMoved = ontouchesMoved;
        ret->ontouchesEnded = ontouchesEnded;
        ret->ontouchesCancelled = ontouchesCancelled;
    }
    else
    {
        CC_SAFE_DELETE(ret);
    }
    return ret;
}

NS_CC_END
EventListenerTouch是EventListener的子类,具有EventListener的所有属性,加上自身4个属性,共14个属性:

1.onTouchBegan

2.onTouchMove

3.onTouchEnded

4.onTouchCanceled

5.claimedtouches

6.needSwallow

7.type

8.listenerID

9.onEvent

10.paused

11.enabled

12.registered

13.node

14.fixedPriority


#ifndef __cocos2d_libs__CCCustomEventListener__
#define __cocos2d_libs__CCCustomEventListener__

#include "base/CCEventListener.h"

NS_CC_BEGIN

class EventCustom;


/****************************************************************************
 用法:
    // 1.dispatcher
    auto dispatcher = Director::getInstance()->getEventdispatcher();
 
    // 2.addListener
    auto listener = EventListenerCustom::create("your_event_type",[](EventCustom* event){ do_some_thing(); });
    dispatcher->addEventListenerWithSceneGraPHPriority(listener,one_node);
 
    // 3.dispatcherEvent,触发事件。
    EventCustom event("your_event_type");
    dispatcher->dispatchEvent(&event);
 
 ****************************************************************************/
// EventCustom
class CC_DLL EventListenerCustom : public EventListener
{
public:
    // 当特定的事件被分发,对应callback将会被调用
    static EventListenerCustom* create(const std::string& eventName,const std::function<void(EventCustom*)>& callback);
    EventListenerCustom();
    bool init(const ListenerID& listenerId,const std::function<void(EventCustom*)>& callback);
    
    
    /// Overrides
    virtual bool checkAvailable() override;
    virtual EventListenerCustom* clone() override;
protected:
    std::function<void(EventCustom*)> _onCustomEvent;
    
    friend class LuaEventListenerCustom;
};

NS_CC_END

#endif

#include "base/CCEventListenerCustom.h"
#include "base/CCEventCustom.h"

NS_CC_BEGIN

EventListenerCustom::EventListenerCustom()
: _onCustomEvent(nullptr)
{
}

EventListenerCustom* EventListenerCustom::create(const std::string& eventName,const std::function<void(EventCustom*)>& callback)
{
    EventListenerCustom* ret = new (std::nothrow) EventListenerCustom();
    if (ret && ret->init(eventName,callback))
    {
        ret->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(ret);
    }
    return ret;
}

bool EventListenerCustom::init(const ListenerID& listenerId,const std::function<void(EventCustom*)>& callback)
{
    bool ret = false;
    
    // callback ==> listener.
    // EventListenerCustom的onCustomEvent 与 EventListener的onEvent相关联。
    _onCustomEvent = callback;
    auto listener = [this](Event* event){
        if (_onCustomEvent != nullptr)
        {
            _onCustomEvent(static_cast<EventCustom*>(event));
        }
    };
    
    // event参数的传入
    // EventListener::init(Type t,ListenerID listenerID,std::function<void(Event*)>& callback)
    if (EventListener::init(EventListener::Type::CUSTOM,listenerId,listener))
    {
        ret = true;
    }
    return ret;
}

EventListenerCustom* EventListenerCustom::clone()
{
    EventListenerCustom* ret = new (std::nothrow) EventListenerCustom();
    if (ret && ret->init(_listenerID,_onCustomEvent))
    {
        ret->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(ret);
    }
    return ret;
}

bool EventListenerCustom::checkAvailable()
{
    bool ret = false;
    if (EventListener::checkAvailable() && _onCustomEvent != nullptr)
    {
        ret = true;
    }
    return ret;
}

NS_CC_END
EventListenerCustom是EventListener的子类,共有9个属性:

1.onCustomEvent

2.onEvent

3.type

4.listenerID

5.registered

6.paused

7.enabled

8.node

9.fixedPriority

cocos2d-x 3.7 源码分析 EventDispatcher的更多相关文章

  1. HTML实现代码雨源码及效果示例

    这篇文章主要介绍了HTML实现代码雨源码及效果示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  2. Html5 Canvas实现图片标记、缩放、移动和保存历史状态功能 (附转换公式)

    这篇文章主要介绍了Html5 Canvas实现图片标记、缩放、移动和保存历史状态功能 (附转换公式),本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  3. ios8 – iOS 8上的ptrace

    我试图在ptrace上调用一个像thisptrace一样的函数;但是当我尝试使用#include导入它时,Xcode会给我一个错误’sys/ptrace.h’文件找不到.我错过了什么,我是否需要导入一个库,或者这在iOS上根本不可用?

  4. 在编译时编译Xcode中的C类错误:stl vector

    我有一个C类,用gcc和可视化工作室中的寡妇在linux上编译.boid.h:并在boid.cpp中:但是,当我在Xcode中编译此代码时,我收到以下错误:有任何想法吗?我以为你可以使用C/C++代码并在Xcode中编译没有问题?.m文件被视为具有Objective-C扩展名的.c文件..mm文件被视为具有Objective-C扩展名的.cpp文件,那么它被称为Objective-C只需将.m文件重命名为.mm,右键单击或按住Ctrl键并在Xcode中的文件中选择重命名.

  5. 如何从Haxe创建iOS-和OSX-库并在本机应用程序中使用它?

    我有一个在Haxe上编写自己的协议,数据结构和逻辑的跨平台实现.如何在iOS和OSX的企业应用程序中构建和使用它?

  6. ios – 类中的extern NSString * const.

    嗨,我有这个头文件:执行:当我在.pch文件中导入头文件时,我可以在任何地方访问常量.但我试着了解发生了什么.我从不为此对象分配init,因此它们不能是实例常量.所以常量必须是“类对象常量对吗?但我认为类对象不能包含数据.谁能解释一下?解决方法那些外部变量是app级全局变量.它们没有作用于类,它们不限于类的实例.Objective-C不支持实例或类级别全局变量.如果需要类级别常量,则需要定义类方法

  7. 源码推荐:简化Swift编写的iOS动画,iOS Material Design库

    本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请发送邮件至dio@foxmail.com举报,一经查实,本站将立刻删除。

  8. swift皮筋弹动发射飞机ios源码

    这是一个款采用swift实现的皮筋弹动发射飞机游戏源码,游戏源码比较详细,大家可以研究学习一下吧。

  9. swift 写的app 源码,保存一下下

    http://www.topthink.com/topic/3345.htmlhttp://www.csdn.net/article/2015-01-09/2823502-swift-open-source-libs

  10. swift 源码网站 code4app

    http://code4app.com/ios/HTHorizontalSelectionList/54cb2c94933bf0883a8b4583http://123.th7.cn/code/DMPagerViewController_2522.html

随机推荐

  1. 【cocos2d-x 3.x 学习笔记】对象内存管理

    Cocos2d-x的内存管理cocos2d-x中使用的是上面的引用计数来管理内存,但是又增加了一些自己的特色。cocos2d-x中通过Ref类来实现引用计数,所有需要实现内存自动回收的类都应该继承自Ref类。下面是Ref类的定义:在cocos2d-x中创建对象通常有两种方式:这两中方式的差异可以参见我另一篇博文“对象创建方式讨论”。在cocos2d-x中提倡使用第二种方式,为了避免误用第一种方式,一般将构造函数设为protected或private。参考资料:[1]cocos2d-x高级开发教程2.3节[

  2. 利用cocos2dx 3.2开发消灭星星六如何在cocos2dx中显示中文

    由于编码的不同,在cocos2dx中的Label控件中如果放入中文字,往往会出现乱码。为了方便使用,我把这个从文档中获取中文字的方法放在一个头文件里面Chinese.h这里的tex_vec是cocos2dx提供的一个保存文档内容的一个容器。这里给出ChineseWords,xml的格式再看看ChineseWord的实现Chinese.cpp就这样,以后在需要用到中文字的地方,就先include这个头文件然后调用ChineseWord函数,获取一串中文字符串。

  3. 利用cocos2dx 3.2开发消灭星星七关于星星的算法

    在前面,我们已经在GameLayer中利用随机数初始化了一个StarMatrix,如果还不知道怎么创建星星矩阵请回去看看而且我们也讲了整个游戏的触摸事件的派发了。

  4. cocos2dx3.x 新手打包APK注意事项!

    这个在编译的时候就可以发现了比较好弄这只是我遇到的,其他的以后遇到再补充吧。。。以前被这两个问题坑了好久

  5. 利用cocos2dx 3.2开发消灭星星八游戏的结束判断与数据控制

    如果你看完之前的,那么你基本已经拥有一个消灭星星游戏的雏形。开始把剩下的两两互不相连的星星消去。那么如何判断是GameOver还是进入下一关呢。。其实游戏数据贯穿整个游戏,包括星星消除的时候要加到获得分数上,消去剩下两两不相连的星星的时候的加分政策等,因此如果前面没有做这一块的,最好回去搞一搞。

  6. 利用cocos2dx 3.2开发消灭星星九为游戏添加一些特效

    needClear是一个flag,当游戏判断不能再继续后,这个flag变为true,开始消除剩下的星星clearSumTime是一个累加器ONE_CLEAR_TIME就是每颗星星消除的时间2.连击加分信息一般消除一次星星都会有连击信息和加多少分的信息。其实这些combo标签就是一张图片,也是通过控制其属性或者runAction来实现。源码ComboEffect.hComboEffect.cpp4.消除星星粒子效果消除星星时,为了实现星星爆裂散落的效果,使用了cocos2d提供的粒子特效引擎对于粒子特效不了

  7. 02 Cocos2D-x引擎win7环境搭建及创建项目

    官网有搭建的文章,直接转载记录。环境搭建:本文介绍如何搭建Cocos2d-x3.2版本的开发环境。项目创建:一、通过命令创建项目前面搭建好环境后,怎样创建自己的Cocos2d-x项目呢?先来看看Cocos2d-x3.2的目录吧这就是Cocos2d-x3.2的目录。输入cocosnew项目名–p包名–lcpp–d路径回车就创建成功了例如:成功后,找到这个项目打开proj.win32目录下的Hello.slnF5成功了。

  8. 利用cocos2dx 3.2开发消灭星星十为游戏添加音效项目源码分享

    一个游戏,声音也是非常的重要,其实cocos2dx里面的简单音效引擎的使用是非常简单的。我这里只不过是用一个类对所有的音效进行管理罢了。Audio.hAudio.cpp好了,本系列教程到此结束,第一次写教程如有不对请见谅或指教,谢谢大家。最后附上整个项目的源代码点击打开链接

  9. 03 Helloworld

    程序都有一个入口点,在C++就是main函数了,打开main.cpp,代码如下:123456789101112131415161718#include"main.h"#include"AppDelegate.h"#include"cocos2d.h"USING_NS_CC;intAPIENTRY_tWinMain{UNREFERENCED_ParaMETER;UNREFERENCED_ParaMETER;//createtheapplicationinstanceAppDelegateapp;return

  10. MenuItemImage*图标菜单创建注意事项

    学习cocos2dx,看的是cocos2d-x3.x手游开发实例详解,这本书错误一大把,本着探索求知勇于发现错误改正错误的精神,我跟着书上的例子一起调试,当学习到场景切换这个小节的时候,出了个错误,卡了我好几个小时。

返回
顶部