创建帧动画

前端之家收集整理的这篇文章主要介绍了创建帧动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

函数只适用于cocos2dx 2.2.5

  1. --创建帧动画
  2. --[[
  3. FrameWidth 帧动画宽
  4. FrameHeight 帧动画高
  5. imageFile 图片文件
  6. 默认循环播放
  7. ]]--
  8. local function createAnim(FrameWidth,FrameHeight,imageFile)
  9. local tex = CCTextureCache:sharedTextureCache():addImage(imageFile)
  10. frame0 = CCSpriteFrame:createWithTexture(tex,CCRectMake(0,FrameWidth,FrameHeight))
  11. frame1 = CCSpriteFrame:createWithTexture(tex,CCRectMake(FrameWidth*1,FrameHeight))
  12. local spriteDog = CCSprite:createWithSpriteFrame(frame0)
  13. spriteDog:setPosition(CCPoint(100,100))
  14. spriteDog:setVisible(true)
  15. animFrames = CCArray:createWithCapacity(2);
  16. animFrames:addObject(frame0);
  17. animFrames:addObject(frame1);
  18. animation = CCAnimation:createWithSpriteFrames(animFrames,0.5)
  19. animate = CCAnimate:create(animation);
  20. spriteDog:runAction(CCRepeatForever:create(animate))
  21. return spriteDog
  22. end

猜你在找的Cocos2d-x相关文章