我的cocos2d-x版本号为3.3
开发环境为VS2013
为什么没有调用draw方法???
Rect.h文件的内容为:
#include
#include “cocos2d.h”
USING_NS_CC;
using namespace std;
namespace testDraw{
class Rect :public Node{
public:
virtual bool init();
virtual void draw();
CREATE_FUNC(Rect);
};
}
Rect.cpp文件的内容为:
#include “Rect.h”
namespace testDraw{
bool Rect::init(){
return true;
}
//没有调用这个函数,这是为什么呀
void Rect::draw(){
CCLOG(“test draw function”);//这是进行测试,判断是否调用了draw()函数
//设置画笔的颜色
DrawPrimitives::setDrawColor4B(255,0,0,255);
//绘制具体的图形
DrawPrimitives::drawRect(Vec2(0,0),Vec2(100,100));
}
}
HelloWorld.cpp文件init()函数里面的内容
HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
//如何使用绘图API
auto rect = testDraw::Rect::create();
rect->setPosition(Vec2(100,100));
this->addChild(rect);
return true;
}