我已经为iphone启动了一款基于2d平铺的游戏,我将直接跳到我的课程和问题.我现在完全有2级Tile,Table和Base主类Tile
`@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;
Run Code Online (Sandbox Code Playgroud)
履行
-(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];
}
}
在触摸结束回调中调用以下语句时,我的程序崩溃了
Tile *tile = [tableLayer objectAtX:(1) Y:(1)];
Run Code Online (Sandbox Code Playgroud)
我已经阅读了很少的博客但是真的很难理解消息传递背后的概念,请你解释一下应用程序崩溃的原因是什么导致"objc_msgsend".
归档时间: |
|
查看次数: |
5155 次 |
最近记录: |