我正在製作一個棋盤遊戲,當一個人獲勝時我希望棋盤重置自己。如果有幫助,我使用iPhone的cocos2d。我有一個重置所有變量和塊數組的重置方法。它在下一次重置一次後,一個人獲勝並不會重置主板。有想法該怎麼解決這個嗎? 這是.m文件中的方法。 //方法Cocos-2d iphone重置遊戲板
-(void) resetGame {
self.isTouchEnabled = YES;
if((self=[super init])) {
self.isTouchEnabled = YES;
turn = 2;
pieces = [[NSMutableArray alloc] initWithObjects:
[[Piece alloc] pieceWithType:1 player:1 row:1 col:3], // bSphere1
[[Piece alloc] pieceWithType:1 player:1 row:2 col:3], // bSphere2
[[Piece alloc] pieceWithType:2 player:1 row:1 col:2], // bSquare1
[[Piece alloc] pieceWithType:2 player:1 row:3 col:3], // bSquare2
[[Piece alloc] pieceWithType:2 player:1 row:0 col:3], // bSquare3
[[Piece alloc] pieceWithType:1 player:2 row:0 col:4], // wSphere1
[[Piece alloc] pieceWithType:1 player:2 row:2 col:4], // wSphere2
[[Piece alloc] pieceWithType:2 player:2 row:1 col:4], // wSquare1
[[Piece alloc] pieceWithType:2 player:2 row:3 col:4], // wSquare2
[[Piece alloc] pieceWithType:2 player:2 row:2 col:5], // wSquare3
nil];
// add background before pieces
CCSprite *bg = [CCSprite spriteWithFile:@"grid.png"];
[bg setPosition:ccp(240, 160)];
[self addChild:bg z:0];
// add all the pieces
for(Piece *piece in pieces) {
[self addChild:piece];
}
}
}
你在哪裏發佈Piece對象? – LearnCocos2D 2012-08-12 09:19:39
由於@ LearnCocos2D提到,在重置方法中沒有用於釋放先前塊的代碼。 (即用清理從父層刪除舊的子件) – giorashc 2012-08-13 06:21:36