Search code examples
androidcgrectcocos2d-android

How to get CGRect of a wheel in spriteMoveFinished method in Cocos2d-android?


I am developing a game using Cocos2d, the problem i am facing is while getting CGRect of the wheel which i have placed at anchor points(0.5,0.5) and position at win-size width/2-height/2.I am detecting touch on wheel and i am facing problem in that using CGRect.intersects(CGRect a,CGRect b).

I am trying this to get wheel CGRect positions

CGRect wheelrect=CGRect.make(wheel.getPosition().x-(wheel.getContentSize().width), 
                                     wheel.getPosition().y-(wheel.getContentSize().height), 
                                     wheel.getContentSize().getWidth(), 
                                     wheel.getContentSize().getHeight());

I am getting CGRect of left half of the wheel, But i need to detect the touch on whole wheel.

I am using Intersect method of CGRect to follow the intersect points.

Need some help.Thanks in advance. This is how it is happening


Solution

  • is there a boundingBox method or property? If so you could use that.

    Anyway your issue is that you subtract contentSize from position, but you need to multiply contentSize with anchorPoint (ie half the contentSize) before subtracting it.