塔防游戏子弹的伤害如何根据父节点实现

最近利用下班时间自学cocos2dx,发现一个很好的教程,贼来了。但是在碰撞检测实现伤害时使用了简单的减一处理。
请问如果我想在这段代码根据父节点的塔的攻击力属性来决定伤害,该如何实现?
–1 子弹添加部分代码
auto bulletVector = Sprite::createWithSpriteFrameName(“arrowBullet.png”);
instance->bulletVector.pushBack(bulletVector );//bulletVector 为Vector<Sprite*>
//子弹的父节点为对应的塔,塔含有伤害的属性。
–2碰撞检测部分
auto bullet = bulletVector.at(i);
bullet->getBoundingBox();
auto bulletRect = Rect(bullet->getPositionX() + bullet->getParent()->getPositionX() - bullet->getContentSize().width / 2,
bullet->getPositionY() + bullet->getParent()->getPositionY() - bullet->getContentSize().height / 2,
bullet->getContentSize().width,
bullet->getContentSize().height);

    for (int j = 0; j < enemyVector.size(); j++)
    {
        auto enemy = enemyVector.at(j);
        auto enemyRect = enemy->getBoundingBox();

        if (bulletRect.intersectsRect(enemyRect))
        {
            auto currHp = enemy->getCurrHp();
                            
            currHp--;
            enemy->setCurrHp(currHp);

        }
          }

不胜感激

子弹创建的时候,传一个塔的引用进去

就是说需要把子弹也建成一个类 里面增加一个Tower类的指针变量吗? 有没有可能通过 getParent() 来实现呢?

能保证子弹一定是tower的子节点的话可以通过getParent()获取

教程里子弹是addChild 到塔上的,
->getParent(), 就能获取到炮塔了

继续讨论那个教程,
LZ 你编译过原程序跑了吗?
—当点击非空地(比如道路,比如树木)时候,是不是也报错中断程序?

是啊 会出现中断错误

gatparent怎么把获得的Node转为Tower类?

gatparent怎么把获得的Node转为Tower类? 我这点不清楚。

强制类型转换下(Tower*)getParent(),更保险点的就用 Tower* parent = dynamic_cast<<Tower*>>(getParent()), 后边一种方法如果parent不是tower将返回null, 前一种方式不检查就强制转换