【问题标题】:Cocos2d and iOS: Can't understand use of control points using ccBezierConfigCocos2d 和 iOS:无法理解使用 ccBezierConfig 控制点的使用
【发布时间】:2012-09-14 19:16:07
【问题描述】:

编辑:如果问题写得不好,请查看视频 (3),与本页底部的链接相同。

我正在尝试使用 ccBezierConfig 和 Cocos2D 绘制一个非常简单的贝塞尔曲线。在维基百科上阅读我试图了解一点控制点并找到了这张图片:

http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Bezier_2_big.png/240px-Bezier_2_big.png

如果您查看我从中获取图像的维基百科页面,就会发现一个很酷的动画。看看here

这是我使用的代码:

        CCSprite *r = [CCSprite spriteWithFile:@"hi.png"];
        r.anchorPoint = CGPointMake(0.5f, 0.5f);
        r.position = CGPointMake(0.0f, 200.0f);

        ccBezierConfig bezier;
        bezier.controlPoint_1 = CGPointMake(0.0f, 200.0f);
        bezier.controlPoint_1 = CGPointMake(180.0f, 330.0f);
        bezier.endPosition = CGPointMake(320.0f,200.0f);

        id bezierForward = [CCBezierBy actionWithDuration:1 bezier:bezier];
        [r runAction:bezierForward];
        [self addChild:r z:0 tag:77];

应用程序在纵向模式下运行,我的猜测与1 的控制点相匹配,而我的代码中的控制点是:

sprite.position should correspond to P0
bezier.controlPoint_1 should correspond to P0 
bezier.controlPoint_2 should correspond to P1
bezier.endPosition  should correspond to P2

我确实尝试了两种方法。通过设置精灵的位置和不设置它。

我假设位置应该与维基百科架构1 中的 controlPoint_1 相同,只有三个点。

我得到了一个我不太明白的输出。我制作了一个小视频,是一个私人 youtube 视频:

to see the video click here

【问题讨论】:

  • 顺便说一句,您似乎有一个错字,您分配了两次controlPoint_1

标签: cocos2d-iphone ccsprite uibezierpath


【解决方案1】:

好的,答案很简单……

quadratic Bézier curve不是cocos2d绘制的。相反,请检查 cubic Bézier curve 的同一 wiki 页面。这才是你应该关注的。

  1. 初始位置是精灵的位置 (P0)
  2. 控制点 1 和 2 分别为 P1 和 P2。
  3. 终点就是终点。

不错的视频,顺便说一句,我很喜欢 xD。


来自cocos2d库中CCActionInterval.h文件的证据:

/** An action that moves the target with a cubic Bezier curve by a certain distance.
 */
@interface CCBezierBy : CCActionInterval <NSCopying>
{
    ccBezierConfig config;
    CGPoint startPosition;
}

This link 应该帮助您直观地构建 cubic Bézier curves,而不是调整值并运行应用程序。

【讨论】:

  • 链接失效或者我得到一个 403 :-(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-20
  • 2015-02-19
  • 2012-03-08
  • 2013-08-18
相关资源
最近更新 更多