对精灵进行分组并移动它们?

发布于 2024-10-28 10:52:47 字数 1443 浏览 0 评论 0原文

我想对从数组中调用的精灵进行分组,以便我可以将它们作为一个组移动。有人告诉我使用 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 技术交流群。

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

发布评论

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

评论(1

╄→承喏 2024-11-04 10:52:47

崩溃的原因可能是 nil 中的 Sprite5、Sprite6、Sprite7、Sprite8 之一。并且拒绝向 CCNode 添加 nil 子节点。

在 touchBegan 方法中:

CGPoint touchLocation = ...;
CGPoint referencePoint = ccpSub(touchLocation, myNode.position);
//keep reference point somewhere

在 TouchMoved 方法中:

CGPoint touchLocation = ...;
myNode.position = ccpSub(touchLocation, referencePoint);

Possibly the reason it's crashed is that one of Sprite5, Sprite6, Sprite7, Sprite8 in nil. And it's denied to add nil children to CCNode.

In touchBegan method:

CGPoint touchLocation = ...;
CGPoint referencePoint = ccpSub(touchLocation, myNode.position);
//keep reference point somewhere

in TouchMoved method:

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