我正在用Cocos2d在Objective C中開發我的第一個應用程序。我是新來的目標c,但我試圖谷歌周圍,但我無法找到解決這個一般問題的解決方案。Cocos2d初學者objc_msg發送EXC_BAD_ACCESS
-(void)accelerate{
moveSpeed = 720.0/3.0;
[self stopAllActions];
_moving = FALSE;
CCAnimation *walkAnim = [CCAnimation animationWithFrames:_walkAnimFrames delay:0.066f];
self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
CGPoint loc = ccp(500, 200);
[self playerMoveTo:loc];
}
-(void)playerMoveTo:(CGPoint)moveLocation{
CGPoint moveDifference = ccpSub(moveLocation, self.position); //here is EXC_BAD_ACCESS
float distanceToMove = ccpLength(moveDifference);
}
,這就是我所說PLAYER1從我的遊戲場景加速方式:
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
[self.Player1 accelerate];
}
PLAYER1是我gameScene:
//implementation
@synthesize Player1 = _Player1;
//header
@property (nonatomic,retain) TPlayer *Player1;
感謝您的耐心和幫助。我不確定代碼的哪一部分應該放在這裏,所以請告訴我什麼,我會添加它。
西蒙
編輯1: PLAYER1在遊戲場景的初始化函數分配。 TPlayer是CCSprite的子類:
_Player1 = [[TPlayer alloc] initWithSpriteFrameName:@"walk2"];
而且EXC_BAD_ACCESS發生在這條線:
CGPoint moveDifference = ccpSub(moveLocation, self.position);
EXC_BAD_ACCESS在哪一行發生? –
另外你在哪裏分配Player1 –
我剛編輯它 – Simon