Hi guys,
I need your help. I’m migrating my little game from version 3.0-RC to 3.6 and DrawPrimitives::draw* methods are deprecated.
I’m having problem to migrate this code, it renders a healthbar that follows the player.
Point localPos = this->getPosition();//CCNode::convertToNodeSpace(this->getPosition());
//draw health bar
DrawPrimitives::drawSolidRect(Point(localPos.x+HEALTH_BAR_ORIGIN,localPos.y+30),
Point(localPos.x+HEALTH_BAR_ORIGIN+HEALTH_BAR_WIDTH, localPos.y+28),
Color4F(1.0, 0, 0, 1.0));
DrawPrimitives::drawSolidRect(Point(localPos.x+HEALTH_BAR_ORIGIN,localPos.y+30),
Point(localPos.x+HEALTH_BAR_ORIGIN + (float)(m_health * HEALTH_BAR_WIDTH)/MAX_HEALTH,localPos.y+28),
Color4F(0, 1.0, 0, 1.0));
It works great but I want to change it as DrawPrimitives is deprecated. I tried this:
Vec2 localPos = this->getPosition();//CCNode::convertToNodeSpace(this->getPosition());
//draw health bar
auto draw = DrawNode::create();
addChild(draw, 2);
draw->clear();
draw->drawSolidRect(Vec2(localPos.x+HEALTH_BAR_ORIGIN,localPos.y+30),
Vec2(localPos.x+HEALTH_BAR_ORIGIN+HEALTH_BAR_WIDTH, localPos.y+28),
Color4F(1.0, 0, 0, 1.0));
draw->drawSolidRect(Vec2(localPos.x+HEALTH_BAR_ORIGIN,localPos.y+30),
Vec2(localPos.x+HEALTH_BAR_ORIGIN + (float)(m_health * HEALTH_BAR_WIDTH)/MAX_HEALTH,localPos.y+28),
Color4F(0, 1.0, 0, 1.0));
And the code above doesn’t work in the way I expected. It draw the bar but far away from the player and goes weird when the player moves, etc. it just doesn’t work.
So, how can I migrate my old code?
Thanks for any help!