Problem in collision with line

Hi,

I’m using cocos2dx 3.3 ver. working on android project.

I draw a line like this -

rectNode = DrawNode::create();
Vec2 rectangle[2];

rectangle[0] = Vec2(0, -50);
rectangle[1] = Vec2(0, 50);

Color4F white(1, 1, 1, 1);
rectNode->drawLine(rectangle[0],rectangle[1],white);

rectNode->setPosition(Vec2(650,200));

this->addChild(rectNode,5);

And code for detecting collision with this line is as follows-

if(rectNode->getBoundingBox().intersectsRect(SpritePlayer->getBoundingBox()))
{
lable->setString(“Collide”);
}else
lable->setString(“No Collide”);

The above code shows collision only from middle point of the line.

Not from complete line.

Why ?

please tell me how can I detect collision of player with any part of line ?

How about trying some simple debugging to see if you can figure out what’s happening?

e…g. add a line
auto BB = rectNode.getBoundingBox();
auto SBB = SpritePlayer->getBoundingBox();
CCLOG(“Rect BB = (%f,%f,%f,%f)”, BB.origin.x, BB.origin.y, BB…size.x, BB.size.y);
CCLOG(“Sprite BB = (%f, %f, %f, %f)”, SBB.origin.x SBB.origin.y, SBB.size.x, SBB.size.y);

Now you can see the values of the two bounding boxes and perhaps work out why they aren’t intersecting.