对精灵进行分组并移动它们?
我想对从数组中调用的精灵进行分组,以便我可以将它们作为一个组移动。有人告诉我使用 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 作为整行移动,一旦它离开屏幕顶部,我需要它重新出现在屏幕的另一侧,反之亦然,左侧和右侧相同。
i want to group my sprites that i call from an array, so that i can move them as a group. I was told to use cocosnode, but i'm pretty sure he meant ccnode. Here is my code so far:
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);
}
how do I make the ccnode move smoothly. It jumps up a lot but I want a smooth transition up and down.
xxx
xxx
xxx
x are my sprites i am moving my x down and up as a whole column and need to be able to move my x as a whole row as well, and once it goes off the top of the screen i need it to reappear on the opposite side of the screen and vice versa same for left and right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
崩溃的原因可能是
nil
中的 Sprite5、Sprite6、Sprite7、Sprite8 之一。并且拒绝向 CCNode 添加 nil 子节点。在 touchBegan 方法中:
在 TouchMoved 方法中:
Possibly the reason it's crashed is that one of Sprite5, Sprite6, Sprite7, Sprite8 in
nil
. And it's denied to add nil children toCCNode
.In touchBegan method:
in TouchMoved method: