0
votes

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 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

1
What error is it giving you? It might be because you are trying to add tetrisBoard more than once. - tallen11

1 Answers

0
votes

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]];
}