我已经为iphone开始了一款基于2d平铺的游戏,我将直接跳到我的课程和问题。我现在完全有2级Tile,Table和Base主类 瓦
`@interface Tile : NSObject {
CCSprite *sprite;
CCSprite *outline;
int row,column;
BOOL highLight;
}
@property (nonatomic , retain)CCSprite *sprite;
@property (nonatomic , retain)CCSprite *outline;
@property (nonatomic, readonly) int row, column;
@property (nonatomic , readwrite)BOOL highLight;
-(id) initWithSpriteName: (NSString*)argSpriteName Row:(int)argRow Column:(int)argColumn Position:(CGPoint)argPosition;
@end`
表
`@interface Table : NSObject {
CCLayer *layer;
CGSize size;
NSArray *icons;
NSMutableArray *content;
}
@property(nonatomic, retain) NSMutableArray *content;
@property(nonatomic, retain) CCLayer *layer;
@property(nonatomic, readonly) CGSize size;
-(id) initWithTableSize:(CGSize)argSize;
-(void)render;
-(Tile *) objectAtX: (int) x Y: (int) y;
`
致电班级(主要)
@interface HelloWorld : CCLayer
{
CGSize size;
Table *tableLayer;
}
@property (retain) Table *tableLayer;
实施
@interface HelloWorld : CCLayer
{
CGSize size;
Table *tableLayer;
}
@property (retain) Table *tableLayer;
在触摸结束回调中调用以下语句时,我的程序崩溃了
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
......
tableLayer = [[Table alloc] initWithTableSize:CGSizeMake(4,7) ];
tableLayer.layer = self;
[tableLayer render];
self.isTouchEnabled = YES;
self.isAccelerometerEnabled = YES;
[self schedule:@selector(render:)];
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 30)];
}
return self;
}
.
.
.
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
CGPoint touchCorrected;
touchCorrected.x = location.x;
touchCorrected.y = 480 - location.y;
int x = (int)(touchCorrected.x/48);
int y = (int)(touchCorrected.y/48);
printf("X = %d Y = %d \n",x,y);
if (x!=0 && y!=0) {
Tile *tile = [tableLayer objectAtX:(1) Y:(1)];
[tile setHighLight:YES];
}
}
我读过很少的博客但是真的很难理解消息传递背后的概念,请你解释一下导致应用程序崩溃的原因是什么“objc_msgsend”。
答案 0 :(得分:7)
这很可能是内存管理错误。我会查看Hamster Emporium's blog post called "So you crashed in objc_msgSend()"。这非常有帮助。