I am wondering if it’s possible to connect Box2D object with cocos2d::sprite, i’ve created tilemap Box2d and i would like to add player and move it.
I have sth like this but i doesnt work correctly my PNG stay in one possition and Box2d object is moving :(( i would like to steer by the Sprite.
// Create object by layer
TMXObjectGroup *objects = _tileMap->getObjectGroup(“player”);
auto playerShowUpPoint = objects->getObject(“spawn”);
{
int x = playerShowUpPoint[“x”].asInt();
int y = playerShowUpPoint[“y”].asInt();
// Create sprite and add it to the layer
auto hero = Sprite::create("hero.png");
hero->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
addChild(hero);
b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set(100 / PTM_RATIO, 300 / PTM_RATIO);
ballBodyDef.userData = hero;
b2Body *body = world->CreateBody(&ballBodyDef);
b2CircleShape circle;
circle.m_radius = 26.0 / PTM_RATIO;
b2FixtureDef ballShapeDef;
ballShapeDef.shape = &circle;
ballShapeDef.density = 1.0f;
ballShapeDef.friction = 0.2f;
ballShapeDef.restitution = 0.8f;
body->CreateFixture(&ballShapeDef);
THANKS SO MUCH!!!