Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2d iphone Cocos2d和iOS:如何使用UIBezierPath为CCSprite移动设置动画?_Cocos2d Iphone_Sprite_Uibezierpath_Ccsprite_Cgpath - Fatal编程技术网

Cocos2d iphone Cocos2d和iOS:如何使用UIBezierPath为CCSprite移动设置动画?

Cocos2d iphone Cocos2d和iOS:如何使用UIBezierPath为CCSprite移动设置动画?,cocos2d-iphone,sprite,uibezierpath,ccsprite,cgpath,Cocos2d Iphone,Sprite,Uibezierpath,Ccsprite,Cgpath,我发现可以教你如何在CoreAnimation中使用UIBezierPath。这是因为CAKeyframeAnimation对象具有名为path的属性,该属性的类型为CGPath,并且UIBezierPath对象具有CGPath属性 我想知道如何让一个CCSprite沿着CGPath移动 在CGPath中有一个函数CGPathGetCurrentPoint,它将帮助我获取路径中的当前点,但我找不到类似“移动到下一点”的内容 我的伪代码的工作原理如下: Create a CCSprite subc

我发现可以教你如何在CoreAnimation中使用UIBezierPath。这是因为CAKeyframeAnimation对象具有名为path的属性,该属性的类型为CGPath,并且UIBezierPath对象具有CGPath属性

我想知道如何让一个CCSprite沿着CGPath移动

在CGPath中有一个函数CGPathGetCurrentPoint,它将帮助我获取路径中的当前点,但我找不到类似“移动到下一点”的内容

我的伪代码的工作原理如下:

Create a CCSprite subclass with a UIBezierPaths property
Initialize the UIBezierPaths instance

Allocate the CCSprite subclass in a layer
schedule updates
In update method
     Reposition the CCSprite sublcass instance by getting the CGPathGetCurrentPoint to CGPathGetCurrentPoint
     Move the path forward by calling "move to next point"

你知道这样行不行吗?这是一种有效的方法吗?

不确定您想做什么,但这就是我在Cocos2D中沿贝塞尔路径移动一些精灵的方法:

- (CCBezierTo*)bezierMoveTo:(CGPoint)destination node:(CCNode*)node duration:(float)d {

 static ccBezierConfig bzPaths[5] = {
    {{1050, 900}, {1200, 1400}, {1100, 900}},
    {{1100, 750}, {1300, 1550}, {1650, 500}},
    {{800, 850}, {500, 1100}, {400, 700}},
    {{700, 700}, {1500, 1200}, {400, 900}},
    {{900, 650}, {100, 900}, {900, 400}}
 };
 ccBezierConfig bezierOne;
 bezierOne = bzPaths[PATH_INDEX];
 return [CCBezierTo actionWithDuration:d bezier:bezierOne];
}
然后可以在精灵上运行返回的操作。在我的例子中,我有一组静态路径,我随机选择一个。在您的情况下,似乎希望在自定义精灵中存储路径。除此之外,一切都应该有效


如果您想构建更复杂的路径,只需使用一系列的
ccBezierConfig
CCBezierBy

非常感谢。我已经验证了ccBezierConfig只有2个控制点和1个端点。有没有办法使用从UIBezierPaths对象派生的ccBezierConfig生成更复杂的路径?我的主题不清楚,所以我可能会说些愚蠢的话。但在我看来,ccBezierConfig只是一个子路径的配置,而UIBezierPath定义了一个更复杂的对象。这有意义吗?如果你想做复杂的动作,你会混合不同的ccBezierConfig吗?谢谢:)…PS:一旦我对此有了想法(从UIBezierPath开始),我会再次接受答案,因为这是我最初的问题,我需要知道这是否可行。如果不可能,我会再次接受答案。很抱歉,请参阅我的编辑:您可以使用
CCBezierBy
通过指定
ccBezierConfig
序列来构建复杂路径。谢谢Sergio,再次抱歉,您没有接受它。我只是想确定这是正确的方法:)。对我来说非常有用。谢谢!!我和他们玩了一点,但我不能安静地理解控制点和起始位置的用法。我在这里添加了一个问题,甚至在youtube上制作了一段视频。有什么建议吗:)?