这是我的代码。在此我的应用程序在“CheckIntersectOrNot”方法处崩溃。在此方法中,它在“[self DifferentColorBalls:loBall];”行崩溃。在这我也使用异常它不起作用。
-(void)CheckIntersectOrNot:(BallImage *)loBall{
BallImage *loTar = (BallImage *)[self getChildByTag:200];
if (CGRectIntersectsRect([loTar boundingBox], [loBall boundingBox])) {
[loTar stopAllActions];
checkCollsionEnable = YES;
if (loTar.BallColor == loBall.BallColor) {
//same color
[self SameColorBall:loBall TargetBall:loTar];
}
else{
//different color balls
@try {
if (loBall != nil ) {
[loBall retain];
if (GameOverCompleted == 2) {
return;
}
[self DifferentColorBalls:loBall];
}
}
@catch (NSException *exception) {
NSLog(@"exception:%@",exception);
}
}
checkCollsionEnable = NO;
}
}
-(void)DifferentColorBalls:(BallImage *)loBall{
if (GameOverCompleted == 2 ) {
return;
}
[[SimpleAudioEngine sharedEngine] playEffect:@"BallSound2.wav"];
@try {
CGPoint tarPoint;
BallImage *loTar = (BallImage *)[self getChildByTag:200];
int index = [self.mBallImageArray indexOfObject:loBall];
tarPoint = loBall.position;
int ballangle = loBall.ballAngle;
int ballDirection = loBall.BallDirection;
for (int i = index; i>= 0; i--) {
BallImage *loba = [self.mBallImageArray objectAtIndex:i];
[self Movenext:loba];
}
[loTar setTag:-1];
loTar.BallAnimationEnable = 1;
loTar.position = tarPoint;
loTar.ballAngle = ballangle;
loTar.BallDirection = ballDirection;
@try {
if (loTar != nil) {
[self.mBallImageArray insertObject:loTar atIndex:++index];
}
}
@catch (NSException *exception) {
NSLog(@"differnet loTar ball :%@",exception);
}
[self CreteTargetBallImage];
}
@catch (NSException *exception) {
NSLog(@"exception DifferentColorBalls :%@",exception);
}
@finally {
}
}
-(void)Movenext:(BallImage *)loBall{
int loop = loBall.contentSize.width/AnimationMoveLength;
for (int i = 0; i<loop; i++) {
@try {
[self BallNextposition:loBall];
}
@catch (NSException *exception) {
NSLog(@"Movenext exception :%@",exception);
}
}
}
-(void)BallNextposition:(BallImage *)loBall{
[self DisableForBallAnimation:loBall];
if (!loBall.BallAnimationEnable) {
return;
}
if (loBall.BallForwardEnable == 0) {
[self MoveBackPosition:loBall];
return;
}
CGPoint point1, point2, point3;
CGPoint ballPosition = loBall.position;
CGRect BoxRect = CGRectMake(40, 40, 22, 244);
CGRect BoxRect2 = CGRectMake(40, 0, 100, 40);
CGRect BoxRect3 = CGRectMake(94, 40, 22, 207);
CGRect BoxRect4 = CGRectMake(94, 245, 100, 44);
CGRect BoxRect12 = CGRectMake(363, 10, 80, 34);
CGRect BoxRect13 = CGRectMake(418, 40, 24, 233);
CGRect BoxRect14 = CGRectMake(405, 272, 50, 50);
if (CGRectContainsPoint(BoxRect, ballPosition) && loBall.BallDirection == 0) {
point1 = CGPointMake(50, 283);
point2 = CGPointMake(50, 40);
loBall.position = [self DrawStrightLine:point1 SecondPoint:point2 BallMovementlength:AnimationMoveLength t:loBall.ballAngle];
loBall.ballAngle++;
if (CGRectContainsPoint(BoxRect2, loBall.position)) {
loBall.ballAngle = 1;
loBall.BallDirection = 1;
}
}
else if (CGRectContainsPoint(BoxRect2, ballPosition) && loBall.BallDirection == 1) {
point1 = CGPointMake(50, 40);
point2 = CGPointMake(77, 10);
point3 = CGPointMake(104, 40);
loBall.position = [self DrawCurve:point1 secondPoint:point2 thirdPoint:point3 BallMovementlength:AnimationMoveLength t:loBall.ballAngle];
loBall.ballAngle++;
if (CGRectContainsPoint(BoxRect3, loBall.position)) {
loBall.ballAngle = 1;
loBall.BallDirection = 2;
}
}
else if (CGRectContainsPoint(BoxRect13, ballPosition) && loBall.BallDirection == 13){
// AnimationMoveLength = 4;
// loBall.BallForwardEnable = 0;
GameOverCompleted = 2;
[self GameOver];
[self RemoveBallsFromBG:loBall];
}
else{
NSLog(@"loBall.position:%@",NSStringFromCGPoint(loBall.position));
}
}
-(void)RemoveBallsFromBG:(BallImage *)loBall{
[loBall runAction:[CCScaleTo actionWithDuration:0.1 scale:.1]];
[self.mBallImageArray removeObject:loBall];
[self removeChild:loBall cleanup:YES];
loBall = nil;
BallImage *loTarSpr = (BallImage *)[self getChildByTag:200];
[self removeChild:loTarSpr cleanup:YES];
loTarSpr = nil;
if ([self.mBallImageArray count] == 0) {
[self unscheduleAllSelectors];
[self LossGame];
}
}
-(void)GameOver{
static int i = 0;
if (i == 0) {
i++;
for (int loop = 0; loop < [self.mBallImageArray count]; loop++) {
BallImage *loBall = [self.mBallImageArray objectAtIndex:loop];
loBall.BallAnimationEnable = 1;
}
[self unscheduleAllSelectors];
[self schedule:@selector(MoveBall:)];
}
if ([self.mBallImageArray count] == 0) {
[self LossGame];
[self unscheduleAllSelectors];
i = 0;
}
}
-(void)WinGame{
GameOverCompleted = 2;
NSLog(@"WinGame");
[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
[CommonUserDetails sharedUserDetails].GameWinOrNot = 1;
[CommonUserDetails sharedUserDetails].GameScore = TotalScore;
[[CommonUserDetails sharedUserDetails].HighScoreArray addObject:[NSString stringWithFormat:@"%d",TotalScore]];
if ([[CommonUserDetails sharedUserDetails].HighScoreArray count] > 50) {
[[CommonUserDetails sharedUserDetails].HighScoreArray removeObjectAtIndex:0];
}
[[CommonUserDetails sharedUserDetails] saveToUserDefaults];
[self unscheduleAllSelectors];
[[CCDirector sharedDirector] replaceScene:[GameOverScene node]];
}
-(void)LossGame{
GameOverCompleted = 2;
[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
[CommonUserDetails sharedUserDetails].GameWinOrNot = 0;
[CommonUserDetails sharedUserDetails].GameScore = TotalScore;
[[CommonUserDetails sharedUserDetails].HighScoreArray addObject:[NSString stringWithFormat:@"%d",TotalScore]];
if ([[CommonUserDetails sharedUserDetails].HighScoreArray count] > 50) {
[[CommonUserDetails sharedUserDetails].HighScoreArray removeObjectAtIndex:0];
}
[[CommonUserDetails sharedUserDetails] saveToUserDefaults];
[self unscheduleAllSelectors];
[[CCDirector sharedDirector] replaceScene:[GameOverScene node]];
NSLog(@"Loss Game");
}
任何人请帮我解决这个问题。为什么它会崩溃并对此问题提出任何建议非常感谢