#include "renderer/CCRenderer.h" USING_NS_CC; class Hoge : public cocos2d::Layer { ..... public: virtual void draw(Renderer *renderer, const Mat4 &transform, bool transformUpdated) override; protected: void onDraw(const Mat4 &transform, bool transformUpdated); CustomCommand _customCommand; };
void Hoge::draw(Renderer *renderer, const Mat4 &transform, bool transformUpdated) { _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Hoge::onDraw, this, transform, transformUpdated); renderer->addCommand(&_customCommand); }
void HelloWorld::onDraw(const Mat4 &transform, bool transformUpdated) { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); //DrawPrimitives::drawLine(...); 等を使って描画 //end draw director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }