1

现在我有一个 NSArray 包含我希望精灵跟随的平铺坐标。Sprite 将“跳转”到每个坐标并在移动到数组中的下一个坐标之前执行 CCAction。我不确定如何解决这个问题。有任何想法吗?

4

1 回答 1

1

使用 CCSequence,您可以为要到达的每个点生成一个动作。我的示例假设您正在包装 CGPoint,它非常具有指示性,它可能不会按照您的要求进行操作,但这只是为了给您一个想法:

// I suppose that you wrapped CGPoint with an object able to return the x and y coordinates.
// points contains all these coordinate objects.
NSMutableArray* actions= [[NSMutableArray alloc]initWithCapacity: points.count];
for(NSUInteger i=0; i<points.count; i++)
{
    id coordinate= points[i];
    CGPoint point= CGPointMake(coordinate.x, coordinate.y);
    // Change this code to whatever is needed to initialize the point.
    CCMoveTo* move= [CCMoveTo actionWithDuration: duration position: point];
    // I suggest to compute duration in a way that it depends from the speed, so
    // that the sprite moves with constant speed.
    [actions addObject: move];      
}
CCSequence* sequence= [CCSequence actionsWithArray: actions];
[sprite runAction: sequence];

我已经直接在浏览器中输入了,我只是希望没有语法错误,在这种情况下让我知道。

于 2013-02-16T22:23:48.147 回答