创建一个包含多个精灵的循环?

发布于 2024-10-27 08:04:34 字数 1621 浏览 0 评论 0原文

我有一列精灵,当一个精灵离开屏幕时,我希望同一个精灵环绕另一侧,以便两个精灵同时显示,当一个精灵移动屏幕时,另一个精灵会出现在屏幕上,另一个精灵会出现在屏幕上熄灭的东西不再可见。到目前为止,我被告知要制作一个 ccnode,在其中执行所有操作都是我的代码,但它们都不起作用,所以我认为我需要再次从头开始。 以下是我关于此问题的最后一个问题的链接,以获取更多信息:当滑动精灵时,如果精灵从一侧消失,它会绕到另一侧?

无论如何,这是我的代码:

    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 ){
            MyNode *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];
            }
        }
    }

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 ){
            MyNode *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];
            }
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

獨角戲 2024-11-03 08:04:34

BSprite 和 TSprite 是指向同一对象(currentSprite)的指针。您实际上需要两个单独的对象,可以通过克隆 currentSprite 或以与 c1array 相同的方式创建另一个数组。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文