intersectRect not working with a sprite if is a child?

Hello,
I was wondering why this is not working.
I have a spriteA moving across spriteB and spirteC. spriteB is a child of a node.
And the intersection is only detected with sprite C, so it seem that intersectRect() doesn’t work with a sprite if is a child.

#include "HelloWorldScene.h"
#include "AudioEngine.h"

USING_NS_CC;


Scene* HelloWorld::createScene()
{
    auto scene = HelloWorld::create();
    return scene;
}


bool HelloWorld::init()
{
    if ( !Scene::init() )
        return false;

	Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

	spriteA = Sprite::create("spriteA.png");
	spriteA->setAnchorPoint(Vec2(0,0));				// set anchor to (0, 0) to match spriteB when making child
	addChild(spriteA);

	nodeB = Node::create();
	spriteB = Sprite::create("spriteB.png");
	spriteB->setAnchorPoint(Vec2(0, 0));			// set anchor to (0, 0) to avoid any offsets and match spriteB
	addChild(nodeB);	
	nodeB->addChild(spriteB);

	spriteC = Sprite::create("spriteC.png");
	spriteC->setAnchorPoint(Vec2(0,0));				
	addChild(spriteC);

	spriteA->setPosition(visibleSize.width/4, visibleSize.height/2);
	spriteC->setPosition(visibleSize.width/2 + 200, visibleSize.height/2);
	nodeB->setPosition(visibleSize/2);

	// Local and world pos
	CCLOG("%f x local position of spriteB", spriteA->getPosition().x);  // Result: 240
	CCLOG("%f y local position of spriteB", spriteA->getPosition().y);  // Result: 320

	CCLOG("%f x local position of spriteB", spriteB->getPosition().x);  // Result: 0
	CCLOG("%f y local position of spriteB", spriteB->getPosition().y);  // Result: 0

	auto spriteBWorldPos = spriteB->convertToWorldSpace(Vec2());
	CCLOG("%f x world position of spriteB", spriteBWorldPos.x);   // Result: 480
	CCLOG("%f y world position of spriteB", spriteBWorldPos.y);	  // Resutl: 320

	// Create move to evaluation collision
	auto moveAction = MoveTo::create(5, Vec2(800, 320 ));
	spriteA->runAction(moveAction);

	// Run the loop
	scheduleUpdate();

    return true;
}





void HelloWorld::update(float dt)
{
	if ( spriteA->getBoundingBox().intersectsRect(spriteB->getBoundingBox()) )
		CCLOG("Intersection happening with spriteB");
	else
		CCLOG("No interection with spriteB...");

	CCLOG("");

	if ( spriteA->getBoundingBox().intersectsRect(spriteC->getBoundingBox()) )
		CCLOG("Intersection happening SpriteC");
	else
		CCLOG("No interection spriteC...");

	CCLOG("------------");
	CCLOG("");
}

thanks,
R

okey, I found a solution which is creating a Rect for spriteA using the world position and then using .containPoint() for all 4 world space points of spriteB

#include "HelloWorldScene.h"
#include "AudioEngine.h"

USING_NS_CC;


Scene* HelloWorld::createScene()
{
    auto scene = HelloWorld::create();
    return scene;
}


bool HelloWorld::init()
{
    if ( !Scene::init() )
        return false;

	Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

	spriteA = Sprite::create("spriteA.png");
	spriteA->setAnchorPoint(Vec2(0,0));				// set anchor to (0, 0) to match spriteB when making child
	addChild(spriteA);

	nodeB = Node::create();
	spriteB = Sprite::create("spriteB.png");
	spriteB->setAnchorPoint(Vec2(0, 0));			// set anchor to (0, 0) to avoid any offsets and match spriteB
	addChild(nodeB);	
	nodeB->addChild(spriteB);

	spriteC = Sprite::create("spriteC.png");
	spriteC->setAnchorPoint(Vec2(0,0));				
	addChild(spriteC);

	spriteA->setPosition(visibleSize.width/4 , visibleSize.height/2);
	spriteC->setPosition(visibleSize.width/2 + 200, visibleSize.height/2);
	nodeB->setPosition(visibleSize/2);

	spriteBWorldPos = spriteB->convertToWorldSpace(Vec2());  // define after setting the position of nodeB

	// Create move to evaluation collision
	auto moveAction = MoveTo::create(5, Vec2(800, 320 ));
	spriteA->runAction(moveAction);

	// Run the loop
	scheduleUpdate();


    return true;
}



void HelloWorld::update(float dt)
{
	auto spriteAWorldPos = spriteA->convertToWorldSpace(Vec2());
	auto spriteAWorldRect = Rect(spriteAWorldPos.x, spriteAWorldPos.y, spriteA->getContentSize().width, spriteA->getContentSize().height);
	
	if (spriteAWorldRect.containsPoint(Vec2(spriteBWorldPos.x, spriteBWorldPos.y)) ||  
		spriteAWorldRect.containsPoint(Vec2(spriteBWorldPos.x + spriteB->getContentSize().width, spriteBWorldPos.y + spriteB->getContentSize().height)) ||
		spriteAWorldRect.containsPoint(Vec2(spriteBWorldPos.x + spriteB->getContentSize().width, spriteBWorldPos.y)) ||
		spriteAWorldRect.containsPoint(Vec2(spriteBWorldPos.x, spriteBWorldPos.y + spriteB->getContentSize().height)))
		CCLOG("Intersection happening with spriteB");
	else 
		CCLOG("No interection with spriteB...");


}

This work as expected, but doesn’t feel right.
According to my initial code, it looks like that intersectsRect() doesn’t work in world space. Is this correct?

thanks,
R

neeever mind. I just understood how intersectsRect works. It is in the parent space, so now I understand why spriteA and spriteB (being in another space), won’t intersect.

Cheers
R