_customCommand.func = CC_CALLBACK_0(TowerPos::onDraw,this, transform, transforUpdated);
CC_CALLBACK_123我都试过了也报错这是为什么 我用的 3.7.1
我看的是木头的书















坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
坐等
#ifndef _TowerPos_H_
#define _TowerPos_H_
#define RADUIUS 32
#include "PosBase.h"
#include"cocos2d.h"
USING_NS_CC;
class TowerPos :public PosBase{
public:
TowerPos();
~TowerPos();
static TowerPos* create(Point pos);
static TowerPos* create(Point pos, bool isDebug);
bool init(Point pos);
bool init(Point pos, bool isDebug);
/*判断坐标是否进入范围*/
virtual bool isClickMe(Point pos) override;
void draw(Renderer* renderer, const kmMat4 &transfrom, bool transforUpdated);
private:
void onDraw(const kmMat4 &transfrom, bool transforUpdated);
CustomCommand _customCommand;
};
#endif // !_TowerPos_H_
```
#include"TowerPos.h"
TowerPos::TowerPos() {
m_pos = Point(0, 0);
m_isDebug = false;
}
TowerPos::~TowerPos() {
}
TowerPos* TowerPos::create(Point pos) {
TowerPos* tPos = new TowerPos();
if (tPos && tPos->init(pos)) {
tPos->autorelease();
}
else {
CC_SAFE_DELETE(tPos);
}
return tPos;
}
TowerPos* TowerPos::create(Point pos, bool isDebug) {
TowerPos* tPos = new TowerPos();
if (tPos && tPos->init(pos, isDebug)) {
tPos->autorelease();
}
else {
CC_SAFE_DELETE(tPos);
}
return tPos;
}
bool TowerPos::init(Point pos) {
bool bRet = false;
do {
CC_BREAK_IF(!PosBase::init(pos));
bRet = true;
} while (0);
return bRet;
}
bool TowerPos::init(Point pos, bool isDebug) {
bool bRet = false;
do {
CC_BREAK_IF(!PosBase::init(pos, isDebug));
bRet = true;
} while (0);
return bRet;
}
void TowerPos::draw(Renderer* renderer, const kmMat4 &transfrom, bool transforUpdated){
if(m_isDebug){
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(TowerPos::onDraw, this, transform, transforUpdated);
renderer->addCommand(&_customCommand);
}
}
void TowerPos::onDraw(const kmMat4 &transform, bool transformUpdate){
kmGLPushMatrix();
kmGLLoadMatrix(&transform);
glLineWidth(5.0f);
/*绘制矩形*/
Point srcPos = Point(m_pos.x - RADUIUS, m_pos.y - RADUIUS);
Point destPos = Point(m_pos.x + RADUIUS, m_pos.y + RADUIUS);
DrawPrimitives::drawRect(srcPos, destPos);
glLineWidth(1);
kmGLPopMatrix();
}
bool TowerPos::isClickMe(Point pos){
Point srcPos = Point(m_pos.x - RADUIUS, m_pos.y - RADUIUS);
Point destPos = Point(m_pos.x + RADUIUS, m_pos.y + RADUIUS);
if (pos.x >= srcPos.x&&pos.x <= destPos.x&&pos.y >= srcPos.y&&pos.y <= destPos.y){
return true;
}
return false;
}
```