【发布时间】:2012-03-22 13:19:08
【问题描述】:
我目前正在使用 cocos2d 为 iphone 创建一个点击应用程序。然而,在我当前的实现中,碰撞检测条件只有在我点击左上角而不是精灵中的任何地方时才成立。如果我将锚点位置设置为 0,这会使事情变得更好,但这会导致我的旋转精灵功能中断。
这是我的代码,有人能发现这里有什么问题吗? 在我的初始化代码中
if( (self=[super init]))
{
cocosGuy = [TouchableSprites spriteWithFile: @"Icon.png"];
//[cocosGuy setAnchorPoint:CGPointMake(0, 0)];
cocosGuy.position = ccp( 200, 300 );
//[cocosGuy setPosition: ccp(100,100)];
[self addChild:cocosGuy];
self.isTouchEnabled = YES;
}
在 touchBegan 中,我确定图像是否被触摸
CGPoint pt = [touch locationInView:[touch view]];
CGPoint ptConv = [[CCDirector sharedDirector] convertToGL:pt];
CGSize size = [cocosGuy contentSize];
CGPoint point = [cocosGuy position];
CGRect rect = CGRectMake(point.x, point.y, size.width, size.height);
if (CGRectContainsPoint(rect, ptConv))
{
retValue = YES;
}
任何帮助将不胜感激
【问题讨论】:
标签: iphone objective-c cocos2d-iphone collision-detection sprite