滑动精灵时,如果精灵从一侧消失,它会绕到对面吗?精灵、它会、绕到

由网友(要变得温柔和强大,就算哪天突然孤身一人,也能平静地活下去,不)分享简介:当滑动精灵时,如果精灵从一侧消失,我想让它环绕到另一侧,但我不知道如何在精灵同时被推离一侧时执行此操作我想要另一位你看不到像虫洞一样的循环出现在对面.When sliding sprite, if sprite disappears off the side, i want to make it wrap aroun...

当滑动精灵时,如果精灵从一侧消失,我想让它环绕到另一侧,但我不知道如何在精灵同时被推离一侧时执行此操作我想要另一位你看不到像虫洞一样的循环出现在对面.

When sliding sprite, if sprite disappears off the side, i want to make it wrap around to the opposite side but I do not know how to do this while the sprite is simultaneously being pushed off one side i want the other bit that you can't see to appear on the opposite side like a loop some sort of wormhole thing.

到目前为止,这是我的代码,但它崩溃了,并且只有在整个精灵从侧面消失时才会传输精灵.循环也需要作为无限循环运行,直到有人退出应用程序.

here is my code so far but it crashes and it only transports the sprite once the whole of the sprite disappears of the side. Loop also needs to run as an infinite loop until someone quits the app.

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

推荐答案

不可能只用一个精灵.但是你可以有两个精灵.通常情况下,当您的精灵在屏幕上滑动时,只会看到一个精灵.但是当它到达边界时,第二个也将可见.当第二个完全进入屏幕时 - 删除(或隐藏)第一个.

It is not possible to do with one sprite. But you can have two sprites. In common situation when your sprite is sliding along the screen only one sprite will be visible. But when it reaches the border the second one will be visible too. When the second one will completely enter the screen - remove (or hide) the first one.

实现这一点的最佳方法是创建一个 CCNode 子类,该子类将包含第一个和第二个精灵,并在需要时交换它们.这样,您的所有逻辑都将非常简单.您将只使用一个 CCNode(子类)并且不会考虑交换精灵 - 这将由您的类自动完成

The best way to implement this is to create a CCNode subclass that will contain first and second sprite and will swap them if required. In this way all your logic will be very simple. You will just work with one CCNode (subclass) and will not think about swaping sprites - it will be done automatically by your class

编辑

@interface MyNode : CCNode
{
    CCSprite *sprite1;
    CCSprite *sprite2;
    CCSprite *currentSprite;
    bool isChanging; //indicates that now two sprites are visible
}
@end
阅读全文

相关推荐

最新文章