首先要声明这三个东西
protected:
void onDraw(const Mat4 &transform, bool transformUpdated);
CustomCommand _customCommand;
public:
virtual void draw(Renderer *renderer, const Mat4 &transform, bool transformUpdated) override;
然后就完善它
void S2ShelterRain::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, bool transformUpdated)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(S2ShelterRain::onDraw, this, transform, transformUpdated);
renderer->addCommand(&_customCommand);
}
void S2ShelterRain::onDraw(const cocos2d::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);
//draw
CHECK_GL_ERROR_DEBUG();
auto dbRect = m_gm->getBoundingBox();
DrawPrimitives::drawRect(dbRect.origin, Vec2(dbRect.getMaxX() + 5, dbRect.getMaxY() + 5));
CHECK_GL_ERROR_DEBUG();
for(auto temp : rainList)
{
auto rect = temp->getBoundingBox();
DrawPrimitives::drawRect(rect.origin, Vec2(rect.getMaxX() + 5, rect.getMaxY() + 5));
}
}