OperaterLayer.h
#ifndef _OPERATE_LAYER_ #define _OPERATE_LAYER_ #include "cocos2d.h" class OperateLayer : public cocos2d::Layer { public: OperateLayer(); ~OperateLayer(); virtual bool init(); CREATE_FUNC(OperateLayer); void onTouchesBegan(const std::vector& touches, cocos2d::Event *unused_event); void onTouchesMoved(const std::vector& touches, cocos2d::Event *unused_event); void onTouchesEnded(const std::vector& touches, cocos2d::Event *unused_event); private: void showJoystick(cocos2d::Point pos); void hideJoystick(); void updateJoystick(cocos2d::Point direction, float distance); cocos2d::Sprite* m_pJoystick; cocos2d::Sprite* m_pJoystickBg; }; #endif ``` OperaterLyaer.cppvoid OperateLayer::updateJoystick(Point direction, float distance) { Point start = m_pJoystickBg->getPosition(); if (distance < 33) { m_pJoystick->setPosition(start + (direction * distance)); }else if (distance>78) { m_pJoystick->setPosition(start + (direction * 45)); }else { m_pJoystick->setPosition(start + (direction * 33)); } } void OperateLayer::onTouchesBegan(const vector& touches, Event *unused_event) { Size winSize = Director::getInstance()->getWinSize(); vector::const_iterator touchIter = touches.begin(); while(touchIter != touches.end()) { Touch *pTouch = (Touch*)(*touchIter); Point p = pTouch->getLocation(); if(p.x <= winSize.width / 2) { this->showJoystick(p); }else { } ++ touchIter; } } void OperateLayer::onTouchesMoved(const vector& touches, Event *unused_event) { Size winSize = Director::getInstance()->getWinSize(); std::vector::const_iterator touchIter = touches.begin(); Touch *pTouch = (Touch*)(*touchIter); Point start = pTouch->getStartLocation(); if(start.x > winSize.width / 2) { return; } Point dest = pTouch->getLocation(); float distance = start.getDistance(dest); Point direction = (dest-start).normalize(); //这点为什么报错啊!!!! this->updateJoystick(direction, distance); } void OperateLayer::onTouchesEnded(const vector& touches, Event *unused_event) { this->hideJoystick(); } ``` 为什么Point direction = (dest-start).normalize(); //这点为什么报错啊!!!! 1 IntelliSense: 对象包含与成员函数不兼容的类型限定符 对象类型是: const cocos2d::Vec2 c:\Users\Unity\Desktop\project\PompaDroid\Classes\OperateLayer.cpp 103 20 PompaDroid