我正在制作一个棋盘游戏,当一个人获胜时我希望棋盘重置自己。如果有帮助,我使用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