Hi,
I cant detect the touch on a Scaled CCSPrite.
Below is the method I am using:
THIS IS WORKING FINE WHEN NOT SCALED THE SPRITE, BUT NOT WHEN SCALE IT
void GameplayWindow::ccTouchesBegan(CCSet pTouches, CCEvent pEvent)
{
CCSetIterator it = pTouches~~>begin;
for; iTouchCount++ )
{
touch = ;
CCPoint pt = touch~~>getLocation();
CCRect recTemp= sprite->boundingBox();
if(recTemp.containsPoint(pt ))
{
//TOUCHED
}
else
{
//NOT TOUCHED
}
}
}
Please help me….
kuhar
January 15, 2014, 10:16pm
#2
What exactly does not work when scaled?
Try this snippet:
bool detectTouchOnNode ( CCNode* pNode, const CCTouch* const pTouch,
CCSize margin )
{
assert ( pNode );
assert ( pTouch );
const CCPoint touchLocation = pTouch->getLocation();
CCRect fieldRect;
fieldRect.origin = pNode->convertToWorldSpace ( CCPointZero );
fieldRect.size = gui::Positioner::getScaledSize ( pNode ); // you have to implement it
fieldRect.size.width += margin.width;
fieldRect.size.height += margin.height;
return fieldRect.containsPoint ( touchLocation );
}
Hi Jakub,
Thanks for the snippet.
How to get gui:: reference please in Cocos2d-X?
Yes, it is not working when scaled.
Thanks
kuhar
January 16, 2014, 4:53pm
#4
As I wrote: you have to implement it
float getScaledWidth ( CCNode* pNode )
{
assert ( pNode );
return pNode->getContentSize().width * pNode->getScaleX();
}
float getScaledHeight ( CCNode* pNode )
{
assert ( pNode );
return pNode->getContentSize().height * pNode->getScaleY();
}
CCSize getScaledSize ( CCNode* pNode )
{
assert ( pNode );
return CCSizeMake ( getScaledWidth ( pNode ), getScaledHeight ( pNode ) );
}
Thanks Jakub… now its working