简体   繁体   中英

How to detect the collision of three sprite in cocos2d-x 2.2?

I am new to cocos2d-x and I am implementing my own flappy bird.

Now I am working with the collision detection and I am stuck.

I added the down_pipe sprite and the up_pipe sprite to a parent sprite pipes, and I move the parent shift from right to left.

But when I check the collision by

if (bird->boundingBox().intersectsRect(pipes->boundingBox()))

It doesn't work.

And I try this way:

if (bird->boundingBox().intersectsRect(pipes->getChildByTag(DOWN_PIPE)->boundingBox()) || bird->boundingBox().intersectsRect(pipes->getChildByTag(UP_PIPE)->boundingBox()))

It still doesn't work.

How can I solve the problem? Any advice?

You try this,

        CCRect target = CCRectMake(pipes->getPosition().x - (pipes->getContentSize().width/2),pipes->getPosition().y - (pipes->getContentSize().height/2),pipes->getContentSize().width,pipes->getContentSize().height);

if (bird->boundingBox().intersectsRect(target))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM