How can I get sprite shape (PhysicsShapePolygon)

I am trying to get sprite shape like this:

auto sprite = getChildByName("mysprite");
auto shape = sprite->getPhysicsBody()->getShape(1);
PhysicsShapePolygon* shapepoly  = dynamic_cast<PhysicsShapePolygon*>(shape);

but throws error, cannot dynamic_cast PhysicsShape to PhysicsShapePolygon, but I saw same PhysicsShape to PhysicsShapePolygon dynamic_cast in cpp-test example as function parameter.

In short I am trying to get sprite shape to get polygon point ; this is only possible by casting PhysicsShapePolygon from sprite->getPhysicsBody()->getShape(1); method. Maybe I mixed too much can anyone help?

I need to use these methods;

Pshapepoly->getPointsCount()
Pshapepoly->getPoints()

I solved like this

auto sprite = getChildByTag(21);

auto shape = sprite->getPhysicsBody()->getFirstShape() ;

PhysicsShapePolygon*  shapepoly  = dynamic_cast< PhysicsShapePolygon* >(shape);

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.