all. I have some function that add sprite to layer
-(void)drawBoard {
for (int y = 0; y < 18; y++) {
for (int x = 0; x < 12; x ++) {
if (tetrisBoard[x][y] != NULL) {
[self addChild:tetrisBoard[x][y]];
}
}
}
}
But when I call this function next time my app just freezes. I think开发者_如何学C it freezes because i already have the same sprite on layer. How can i check all child on my layer and if i have the same child on layer, then do nothing ? Thanks
You can get an NSArray of the children of the layer, so you could do a check like this:
if ([[self children] containsObject:tetrisBoard[x][y]]) {
[self addChild:tetrisBoard[x][y]];
}
精彩评论