【发布时间】:2010-05-22 04:17:05
【问题描述】:
我知道我可能已经发布了三个与此相关的问题然后删除了它们,但这只是因为我在得到答案之前解决了它们。但是,这个我无法解决,我不相信与其他人相比它很难。所以,事不宜迟,这是我的问题:
所以我使用的是 Cocos2d,主要问题之一是它们没有按钮。为了弥补按钮的缺失,我试图检测触摸结束时是否与正方形(按钮)发生碰撞。这是我的代码:
- (void)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:touch.view];
NSLog(@"%f", 240-location.y);
if (isReady == YES)
{
if (((240-location.y) <= (240-StartButton.position.x - 100) || -(240-location.y) >= (240-StartButton.position.x) + 100) && ((160-location.x) <= (160-StartButton.position.y) - 25 || (160-location.x) >= (160-StartButton.position.y) + 25))
{
NSLog(@"Coll:%f", 240-StartButton.position.x);
CCScene *scene = [PlayScene node];
[[CCDirector sharedDirector] replaceScene:[CCZoomFlipAngularTransition transitionWithDuration:2.0f scene:scene orientation:kOrientationRightOver]];
}
}
}
你知道我做错了什么吗?
【问题讨论】:
-
不确定它是否是故意的,但看起来你的一些变量在接近尾声时被切换了。您正在将 x 与 y 进行比较。
-
@Ed Marty:是的,这是故意的……
-
你还没有解释出了什么问题。不匹配吗?不应该匹配的时候匹配吗?您根本没有参加活动吗?另外,您是否设置了断点并单步执行,以查看变量取什么值?
-
好的,问题是当 BOOL isReady == YES 时,只要我在 iPhone 模拟器中放开鼠标,程序就会自动停止并转到 PlayScene 场景。如您所见,我正在使用 NSLog 进行调试。
标签: iphone button cocos2d-iphone collision-detection