开发者

problem with drawing sprite

开发者 https://www.devze.com 2023-03-05 20:21 出处:网络
all. I have some function that add sprite to layer -(void)drawBoard { for (int y = 0; y < 18; y++) {

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

精彩评论

暂无评论...
验证码 换一张
取 消