我是Objective C中的编程新手,甚至是编程类的。 我正在制作一个简单的乒乓球游戏,当我试图为计算机播放器制作AI时,程序总是“关闭”,显示线程1中的SIGABRT错误。
我已经在这里提出了这个问题,但没有得到答案,只是被要求提供更多代码。
这个错误实际上是从编辑代码中突然出现的,突然它出现了,甚至在删除了自上次成功构建以来编写的代码后,它仍然显示错误。即使我开始我知道有效的备份。
所以这里是我的所有代码。
PongViewController.m - 我在错误出现之前编辑的代码
#import "pongViewController.h"
#define kGameStateRunning 1
#define kGameStatePaused 2
#define kMicSpeedX 3
#define kMicSpeedY 4
#define ObtiznostPocitace 15
@implementation pongViewController
@synthesize mic,plosina_a,plosina_b,hrac_score,pocitac_score,gameState,micVelocity,TapToBegin;
- (void)viewDidLoad {
[super viewDidLoad];
self.gameState = kGameStatePaused;
micVelocity = CGPointMake(kMicSpeedX, kMicSpeedY);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if(gameState == kGameStatePaused) {
TapToBegin.hidden = YES;
gameState = kGameStateRunning;
} else if (gameState == kGameStateRunning) {
[self touchesMoved:touches withEvent:event];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
CGPoint xLocation = CGPointMake(location.x,plosina_a.center.y);
plosina_a.center = xLocation;
}
- (void) gameLoop {
if(gameState == kGameStateRunning) {
mic.center = CGPointMake(mic.center.x + micVelocity.x, mic.center.y + micVelocity.y);
if(mic.center.x > self.view.bounds.size.width || mic.center.x < 0) {
micVelocity.x = -micVelocity.x;
}
if(mic.center.y > self.view.bounds.size.height || mic.center.y < 0) {
micVelocity.y = -micVelocity.y;
}
} else {
if (TapToBegin.hidden) {
TapToBegin.hidden = NO;
}
}
//Collision Detection
if (CGRectIntersectsRect(mic.frame,plosina_a.frame)) {
if (mic.center.y < plosina_a.center.y) {
micVelocity.y = -micVelocity.y;
//NSLog(@"%f %f", mic.center,plosina_b.center);
}
}
if (CGRectIntersectsRect(mic.frame,plosina_b.frame)) {
if (mic.center.y > plosina_b.center.y) {
micVelocity.y = -micVelocity.y;
}
}
if(mic.center.y <= self.view.center.y) {
if(mic.center.x < plosina_b.center.x) {
CGPoint compLocation = CGPointMake(plosina_b.center.x - ObtiznostPocitace, plosina_b.center.y);
plosina_b.center = compLocation;
}
if(mic.center.x > plosina_b.center.x) {
CGPoint compLocation = CGPointMake(plosina_b.center.x + ObtiznostPocitace, plosina_b.center.y);
plosina_b.center = compLocation;
}
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
//jakovždy nakonec uvolníme co sme si obsadili
- (void)dealloc {
[super dealloc];
[mic release];
[plosina_a release];
[plosina_b release];
[hrac_score release];
[pocitac_score release];
[TapToBegin release];
}
@end
main.m - 错误指向的代码
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
调试器吐出的内容:
argc int 1
argv char ** 0xbffff6f4
*argv char * 0xbffff800
pool NSAutoreleasePool * 0x4b29340
NSObject NSObject {...}
_token void * 0x521a200
_reserved3 void * 0x0
_reserved2 void * 0x0
_reserved void * 0x0
retVal int -1073744132
这个(来自调试器控制台)但我认为这不是问题的一部分,但我知道到底是什么。
This GDB was configured as "x86_64-apple-darwin".Attaching to process 11032.
Couldn't register com.yourcompany.pong with the bootstrap server. Error: unknown error code.
This generally means that another instance of this process was already running or is hung in the debugger.sharedlibrary apply-load-rules all
Current language: auto; currently objective-c
(gdb)
请帮助,我尝试修复我在申请中的所有警告,我成功了,但仍然没有。
答案 0 :(得分:0)
制作一个新项目,使其成为基于视图的应用程序,并调用项目iTennis。 在您提到的网站上,http://www.icodeblog.com/2009/01/15/iphone-game-programming-tutorial-part-1/下载它要下载的所有图像文件,并将它们放在项目的资源文件夹中。
之后,打开文件iTennisViewController.xib并将图片链接到您在头文件中声明的IBOutlets。此外,如果您不知道如何执行此操作,我认为网站上有关于如何执行此操作的视频链接。如果您没有看到链接,请转到youtube并在xcode上观看TheNewBoston的视频。他告诉你关于这些东西的基础知识,你应该看他的视频。
现在打开iTennisViewController.m文件,按照发布的确切顺序放入以下代码。
http://staging.icodeblog.com/wp-content/uploads/2009/01/screenshot_061.jpg
http://staging.icodeblog.com/wp-content/uploads/2009/01/screenshot_071.jpg
http://staging.icodeblog.com/wp-content/uploads/2009/01/screenshot_081.jpg
http://staging.icodeblog.com/wp-content/uploads/2009/01/screenshot_091.jpg
http://staging.icodeblog.com/wp-content/uploads/2009/01/screenshot_101.jpg