开发者

creating a loop with multiple sprites?

i've got a column of sprites as one sprite goes off the screen i want the same sprite to wrap around the opposite side so that two sprites are showing simultaneously, as one moves of the screen the other comes onto the screen and the other sprite that goes off is no longer visible. I was told to make a ccnode in which to do everything here is my code so far, but none of it works so i think i will need to start from scratch again. Here is a link to my last question on this for more info: When sliding sprite, if sprite disappears off the side, it will wrap around to the opposite side?

here is my code anyways:

    for (int i =0; i<16; ++i) {
        MyNode *currentSprite = [c1array objectAtIndex:i];
        if (currentSprite.contentSize.height>=320 || currentSprite.position.y-currentSprite.contentSize.height/2<=0 ){
            MyNod开发者_开发百科e *Bsprite = currentSprite;
            MyNode *Tsprite = currentSprite;
            Bsprite.scale = 1.0;
            Tsprite.scale = 1.0;

            if(currentSprite.position.y >=253){
            Bsprite.position = ccp(currentSprite.position.x,-35);
                [self addChild:Bsprite];
                Bsprite.visible = TRUE;
            }
            if (currentSprite.position.y <=0) {
                Tsprite.position = ccp(currentSprite.position.x,324);
                [self addChild:Tsprite];
                Tsprite.visible = TRUE;
            }
            MyNode *isChanging;
            if ((Tsprite.visible == TRUE && currentSprite.visible == TRUE) || (Bsprite.visible == TRUE && currentSprite.visible == TRUE)) {
                isChanging = TRUE;
            }
            if (isChanging == FALSE) {
                [self removeChild:Tsprite cleanup:YES];
                [self removeChild:Bsprite cleanup:YES];
            }
        }
    }


BSprite and TSprite are pointers to the same object (currentSprite). You actually need two separate objects, either by cloning currentSprite or by creating another array in the same manner as c1array.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜