菜鸟教程小白 发表于 2022-12-11 22:33:45

iphone - 在 cocos2d 中为图层路径添加动画


                                            <p><p>所以我在 cocos2d 上,但在我使用普通的 ios 应用程序之前,我有这个代码:</p>

<pre><code>-(void)viewDidLoad
{
    rootLayer = [ init];
    ;
    roundPath = CGPathCreateMutable();

    CGPathMoveToPoint(roundPath, nil, center.x , center.y - 35);
    CGPathAddArcToPoint(roundPath, nil, center.x + 35, center.y - 35, center.x + 35, center.y + 35, 35);
    CGPathAddArcToPoint(roundPath, nil, center.x + 35, center.y + 35, center.x - 35, center.y + 35, 35);
    CGPathAddArcToPoint(roundPath, nil, center.x - 35, center.y + 35, center.x - 35, center.y, 35);
    CGPathAddArcToPoint(roundPath, nil, center.x - 35, center.y - 35, center.x, center.y - 35, 35);

    CGPathCloseSubpath(roundPath);

    //Box Path

    boxPath = CGPathCreateMutable();

    CGPathMoveToPoint(boxPath, nil, center.x , center.y - 35);
    CGPathAddArcToPoint(boxPath, nil, center.x + 35, center.y - 35, center.x + 35, center.y + 35, 4.7);
    CGPathAddArcToPoint(boxPath, nil, center.x + 35, center.y + 35, center.x - 35, center.y + 35, 4.7);
    CGPathAddArcToPoint(boxPath, nil, center.x - 35, center.y + 35, center.x - 35, center.y, 4.7);
    CGPathAddArcToPoint(boxPath, nil, center.x - 35, center.y - 35, center.x, center.y - 35, 4.7);

    CGPathCloseSubpath(boxPath);
    shapeLayer = ;

    shapeLayer.path = boxPath;

    ;
}

-(void)startAnimation
{   
    CABasicAnimation *animation = ;

    animation.duration = 2.0;

    animation.repeatCount = HUGE_VALF;

    animation.autoreverses = YES;

    animation.timingFunction = ;

    animation.fromValue = (id)boxPath;

    animation.toValue = (id)roundPath;

    ;
}
</code></pre>

<p>但是我没有找到在cocos2d上做<code>boxpath</code>到<code>roundpath</code>动画的方法,不知道CCAction用什么。有谁能够帮我 ?对不起我的英语我是法国人:/</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>据我所知,Cocos2d 中没有直接接口(interface)可以使用 Apple 的 CoreAnimation 库中的 CGPaths。 </p>

<hr/>

<p><strong>EDIT1:</strong>对不起,我误解了你的问题! Cocos2d 没有提供任何工具来动画/变形从由路径定义的一个形状到由不同路径定义的另一个形状。您要么需要创建自己的继承自 CCNode 的自定义类,要么使用 Cocos2d 以外的其他库。如果您确实创建了自己的 CCNode 子类,那么现有的 Cocos2dAction /动画工具可能会有用...... </p>

<hr/>

<p><strong>EDIT2:</strong>如果您了解如何进行子类化,那么这里有一个链接,其中包含您想要在 CCNode 的子类中覆盖哪些方法的基础知识:<a href="http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:draw_update" rel="noreferrer noopener nofollow">http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:draw_update</a> </p>

<p>此外,cocos2d 编程指南通常会有所帮助:<a href="http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index" rel="noreferrer noopener nofollow">http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index</a> </p>

<p>如果您不了解如何子类化(例如,从现有 <code>class</code> 继承新的 <code>class</code>),那么我建议您了解 Object 的这一部分面向编程使用更简单的问题! </p>

<hr/>

<p><罢工>
我相信您最好的选择是查看 <code>CCSequence</code>(这是一种 <code>CCAction</code>)并用一系列 <code>CCMoveTo</code> 或 <code> 填充它>CCMoveBy</code>Action 。 </strike></p><strike>

</strike><p><strike>教程链接:<a href="http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:actions_composition" rel="noreferrer noopener nofollow">http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:actions_composition</a>
</strike></p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 在 cocos2d 中为图层路径添加动画,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/10093470/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/10093470/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 在 cocos2d 中为图层路径添加动画