ccTouchesBegan not giving correct touch coordinates?


#1

I am wondering why if i touch outside the bounding box it still activates. I have my CCSprite scaled but i have enabled the ccsprite debug outline and i can clearly see the bounding box. I have also tried not scaling it and its the same issue.

void HelloWorld::ccTouchesBegan(CCSet* pTouches, CCEvent* event) {
CCSetIterator i;
CCPoint tap;
CCTouch *touch = (CCTouch *)pTouches~~>anyObject;
if{
tap = touch~~>getLocation();
CCRect box = ball->boundingBox();
if(ball->boundingBox().containsPoint(tap) ){
}
}

Does anybody know what i am doing wrong? or have any suggestions on how i can improve it? I am extremely confused as to why it accepts touch’s outside the bounding box


#2

Does your sprite is in another sprite as a child? If yes, you should do sth like that:

if(ball->boundingBox().containsPoint(ball->parent().convertToNodeSpace(tap)))

#3

I used to have the similar problem when I set wrong screen size. The app works fine on win 32, but failed on my handset.

@ view~~>setFrameSize;
view~~>setDesignResolutionSize(960,640,kResolutionNoBorder);@

actually my handset screen size is 1280x768. after modify my code to

@ view~~>setFrameSize;
view~~>setDesignResolutionSize(1280,768,kResolutionNoBorder);@

the problem solves.


#4

Tobias S wrote:

Does your sprite is in another sprite as a child? If yes, you should do sth like that:
[…]

No i have not made sprites the children of other sprites. But i did try your suggestion and XCode is giving me a “no member named ‘parent’ in ‘cocos2d::CCSprite’” error.

pearce wang wrote:
>I used to have the similar problem when I set wrong screen size. The app works fine on win 32, but failed on my handset.
>
>view~~>setFrameSize;
>view~~>setDesignResolutionSize(960,640,kResolutionNoBorder);
>
>actually my handset screen size is 1280x768. after modify my code to
>
>view~~>setFrameSize;
>view~~>setDesignResolutionSize(1280,768,kResolutionNoBorder);
>
>the problem solves.

I do not believe i have the same issue. I am testing my app in the XCode simulator. I tried changing the design resolution to standard iPad and it didn’t do anything