您的位置:首页 > 移动开发 > Cocos引擎

Ubuntu Cocos2dx 学习笔记——纹理动画

2014-04-14 19:17 405 查看
转载请标明出处:http://blog.csdn.net/tim_shadow/article/details/23698909

1.图片资源



2.图片处理工具

Linux下面没有强大的PhotoShop ,但是 GIMP 也可以顺利完成基本的图片处理;
安装方式:
sudo apt-get install gimp
GIMP 的使用方式,自行摸索,这里不做说明

3.关键代码 

CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
//载入纹理
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage(
"bird_fly.png");
//设定小鸟纹理的宽度和高度
float height = texture->getContentSize().height / 3;
float width = texture->getContentSize().width;
CCAnimation* animation = CCAnimation::create();
//设置间隔时间
animation->setDelayPerUnit(0.15f);
//添加精灵帧
for (int i = 0; i < 3; i++) {
animation->addSpriteFrameWithTexture(texture
//         x0,y0      , width, height
CCRectMake(0, height*i, width, height));
}
CCAnimate* animate = CCAnimate::create(animation);
CCSprite*fish = CCSprite::create();
fish->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
fish->runAction(CCRepeatForever::create(animate));
addChild(fish);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: