[Cocos2d-x开发问题-3] cocos2dx动画Animation介绍

        Cocos2d-x为了减少开发难度,对于动画的实现採用的帧动画的方案。这也就是说Cocos2d-x中的动画是帧动画。

帧动画的原理相信大家都不陌生,就是多张图片循环播放以实现动画的效果。

一个简单的动画动画实现例如以下:

    player = cc.Sprite:create("image/player.png")
    player:setPosition(-width/4,0)
    local animation = cc.Animation:create()
    animation:addSpriteFrameWithFile("image/player.png")
    animation:addSpriteFrameWithFile("image/player_2.png")
    animation:addSpriteFrameWithFile("image/player_3.png")
    animation:setDelayPerUnit(0.1)
    animation:setLoops(-1)
    local action = cc.Animate:create(animation)
    player:runAction(action)
        这是一段lua代码,从代码中不难看出,这里面动画的每一帧都是一张图片,在实际的操作中这种操作方式会带来较多的性能损耗,因此我们通常会将全部的图片通过plist组织起来。组成一张大的图片,这样每个动画帧都通过plist中记录的坐标范围信息从这张大的图片中获得自己须要的那一部分纹理。这样来提高动画的性能。

原文地址:https://www.cnblogs.com/blfshiye/p/5090731.html