Position after adding physicsbody

auto moveto = MoveTo::create(1, Vec2(player->getPositionX(),y->getPositionY()));
bullet= Sprite::create("bullet= .png");
bullet->setScale(1.3);
bullet->setPosition(Vec2(enemy->getPositionX(), (enemy->getPositionY()));
bulletbody = PhysicsBody::createBox(Size(bullet->getContentSize().width, bullet->getContentSize().height));
bulletbody->setDynamic(false);
bulletbody->setGravityEnable(false);
bulletbody->setCollisionBitmask(909);
bulletbody->setContactTestBitmask(true);
bullet->setPhysicsBody(bulletbody);
danbody->setPositionOffset(Vec2(sp->getPositionX(), sp->getPositionY()));
layer->addChild(bullet, 20);
bullet->runAction(moveto);

I create a bullet at the enemy position, the enemy is a sprite.
If I don’t add physicsbody to the bullet then the position when it is created is correct but when I add physicsbody to it, it is created at the left corner of the screen (0,0); Can someone explain help me

what do you use API call to accomplish?

1 Like

thank you :smiley::smiley::smiley::smiley::smiley:

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