本文介绍了当滑动精灵时,如果精灵从侧面消失,它会缠绕到对面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 当滑动精灵时,如果sprite从边消失,我想让它包裹到对面,但我不知道如何做,而sprite同时被推离一边我想另一个位你不能看到在对面出现像一个循环某种虫洞事情。 这里是我的代码,但它崩溃,它只传输精灵一旦整个sprite消失了一边。 Loop也需要作为无限循环运行,直到有人退出应用程序。 for(int i = 0; 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]; } } } 解决方案> 这是不可能做到的一个精灵。但是你可以有两个sprite。在常见的情况下,当你的精灵沿屏幕滑动只有一个精灵可见。但是当它到达边界时,第二个也将是可见的。当第二个将完全进入屏幕 - 删除(或隐藏)第一个。 实现这个的最好的方法是创建一个CCNode子类,和第二个sprite,如果需要将交换它们。这样,所有的逻辑都会很简单。你将只使用一个CCNode(子类),不会考虑swaping sprites - 它会由你的类自动完成 EDIT / p> @interface MyNode:CCNode { CCSprite * sprite1; CCSprite * sprite2; CCSprite * currentSprite; bool isChanging; //表示现在有两个sprites可见} @end 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.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 classEDIT@interface MyNode : CCNode{ CCSprite *sprite1; CCSprite *sprite2; CCSprite *currentSprite; bool isChanging; //indicates that now two sprites are visible}@end 这篇关于当滑动精灵时,如果精灵从侧面消失,它会缠绕到对面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-17 21:41