【问题标题】:how to move multiple sprite in cocos2d?如何在 cocos2d 中移动多个精灵?
【发布时间】:2014-06-18 12:22:03
【问题描述】:

我想一次移动一个精灵......但是当我像这种方法移动精灵时,其他精灵的位置..我没有触及它的位置是自动互换的......我在 SpriteIconArray 中有四个精灵并且在 PointArray 中的 SameNumber 位置。请帮帮我。

CCLOG(@"%.f,%.f",touchLocation.x,touchLocation.y);
int k=0;
for (CCSprite *sprite in spriteIconArray)
{
    if (CGRectContainsPoint(sprite.boundingBox, touchLocation))
    {
        if (k==0)
        {
            sprite.position=touchLocation;
            sprite.zOrder=INT_MAX;
            k++;
        }
        else
        {
            sprite.position=CGPointFromString([pointArray objectAtIndex:sprite.tag]);
        }

    }

}

【问题讨论】:

  • 这个问题很难解释,请试着重新表述一下。

标签: ios cocos2d-iphone


【解决方案1】:

in.h 定义 NSInteger SpriteTag

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {

for (CCSprite *sprite in spriteIconArray)
{
    if (CGRectContainsPoint(sprite.boundingBox, touchLocation))
    {
        SpriteTag=sprite.tag;
        OriginalPoint=sprite.position;
    }
}

}

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event

{

for (CCSprite *sprite in spriteIconArray)
{

    if (sprite.tag==SpriteTag)
    {
         sprite.position=touchLocation;
         sprite.zOrder=INT_MAX;
    }

}

}

【讨论】:

    【解决方案2】:

    您可以使用以下代码:-

    id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width/2, actualY)];
    id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
    [target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
    

    您可以有 3 种不同的纹理,这些纹理是在生成精灵时随机分配的,因此只应用了 3 张图像。

    【讨论】:

    • @YvesLeBorg..我的朋友也有同样的问题。我从这个论坛得到了在 ios 中使用精灵的解决方案。我知道这个问题有点不清楚
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多