我想将我从一个数组调用的精灵分组,以便我可以将它们作为一个组移动。有人告诉我使用cocosnode,但我很确定他的意思是ccnode。到目前为止,这是我的代码:
sprites1 = (CCSprite *)[c1array objectAtIndex:0];
sprites2 = (CCSprite *)[c1array objectAtIndex:1];
sprites3 = (CCSprite *)[c1array objectAtIndex:2];
sprites4 = (CCSprite *)[c1array objectAtIndex:3];
sprites5 = (CCSprite *)[c1array objectAtIndex:4];
sprites6 = (CCSprite *)[c1array objectAtIndex:5];
sprites7 = (CCSprite *)[c1array objectAtIndex:6];
sprites8 = (CCSprite *)[c1array objectAtIndex:7];
column1 = [CCNode node];
[column1 addChild:sprites1];
[column1 addChild:sprites2];
[column1 addChild:sprites3];
[column1 addChild:sprites4];
column1.position = ccp(0,0);
[self addChild:column1];
column2 = [CCNode node];
[column2 addChild:sprites5];
[column2 addChild:sprites6];
[column2 addChild:sprites7];
[column2 addChild:sprites8];
column2.position = ccp(30,0);
[self addChild:column2];
//ccotouchmoved code
column1.anchorPoint = ccp(touchLocation.x,touchLocation.y);
if (CGRectContainsPoint(c1,touchLocation)) {
touchLocation.x = column1.position.x;
column1.position = ccp(touchLocation.x,touchLocation.y);
}
如何让ccnode顺利移动。它跳了很多但我希望上下平滑过渡。
XXX
XXX
XXX
x是我的精灵我正在向下移动我的x整个列,并且需要能够将我的x作为整行移动,并且一旦它从屏幕顶部移开,我需要它再次出现在屏幕的另一侧,反之亦然左右。
答案 0 :(得分:0)
可能它崩溃的原因是nil
中的Sprite5,Sprite6,Sprite7,Sprite8之一。并且拒绝将无子女添加到CCNode
。
在touchBegan方法中:
CGPoint touchLocation = ...;
CGPoint referencePoint = ccpSub(touchLocation, myNode.position);
//keep reference point somewhere
TouchMoved方法中的:
CGPoint touchLocation = ...;
myNode.position = ccpSub(touchLocation, referencePoint);