void BaseTower::attack(float delta)
{
auto startPos = getPosition();
// auto targetPos = currTarget->getPosition();
auto targetPos = Vec2(100.0f, 100.0f); // for testing
auto bullet = cocos2d::DrawNode::create();
bullet->drawDot(startPos, 3.0f, Color4F::BLACK);
getParent()->addChild(bullet); // add as chid to scene object
auto shootAct = MoveTo::create(0.5f, targetPos);
bullet->runAction(Sequence::create(shootAct, RemoveSelf::create(true), nullptr));
}
BaseTower is a subclass of Sprite and its object is a child of a Scene object. The problem is shootAct moves bullet to 100,100 relatively to the BaseTower object origin not to the Scene object origin. So why shootAct acts like that?
It seems bullet is child of Tower and Tower is child of scene.
you need to convert the position, i don’t clearly remember the exact code, will check it later.
try convertToNodeSpace or convertToWorldSpace.