coco2d-x 使用Action中的Animate实现动画效果
来源:互联网 发布:c语言中a=3是什么意思 编辑:程序博客网 时间:2024/05/22 12:50
命令行新建一个工程
cocos new ActionGame -p com.MyCompany.ActionGame -l cpp -d ./MyCompany
新建一个名叫ActionGame的项目,目录在当前目录的MyCompany目录下
使用gedit打开HelloWorldScene.cpp
去掉一些不要的代码,比如显示hello world的字符串等,下面的双斜线的注释为去掉的代码。
准备图片,来源于网络,这些图片规定每个鱼儿的位置,所以应该是顺序排列。
源码:
// on "init" you need to initialize your instancebool HelloWorld::init(){ ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } auto visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object // auto closeItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); // closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object // auto menu = Menu::create(closeItem, NULL); // menu->setPosition(Vec2::ZERO); // this->addChild(menu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label // auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24); // position the label on the center of the screen // label->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer // this->addChild(label, 1); // add "HelloWorld" splash screen" // auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen // sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer // this->addChild(sprite, 0); auto mySprite = Sprite::create("mysprite.png");this->addChild(mySprite);mySprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));// now lets animate the sprite we movedVector<SpriteFrame *> animFrames;animFrames.reserve(12);animFrames.pushBack(SpriteFrame::create("Blue_Front1.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Front2.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Front3.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Left1.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Left2.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Left3.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Back1.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Back2.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Back3.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Right1.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Right2.png", Rect(0, 0, 100, 100)));animFrames.pushBack(SpriteFrame::create("Blue_Right3.png", Rect(0, 0, 100, 100)));// create the animation out of the framesAnimation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);Animate* animate = Animate::create(animation);mySprite->runAction(RepeatForever::create(animate)); return true;}编译生成apk
cocos compile -s ./MyCompany/ActionGame -p android -m debug -o ./MyCompany/ActionGame/bin
安装进入手机
adb install MyCompany/ActionGame/bin/ActionGame-debug.apk
运行效果,显示为动画,截取某个图片。
0 0
- coco2d-x 使用Action中的Animate实现动画效果
- cocos2d-x 使用action实现各种动画效果
- cocos2d-x 使用action实现各种动画效果
- cocos2d-x 使用action实现各种动画效果
- cocos2d-x 使用action实现各种动画效果 .
- jquery animate实现动画效果
- coco2d-x 3.x 实现帧动画
- Jquery使用animate实现css3的transform动画效果
- coco2d-x 实现风雪飘动效果
- coco2d-x 实现风雪飘动效果
- COCO2D-X中ScrollView的使用实现
- jQuery animate 动画效果
- svg animate实现加载中的动画
- jquery中的动画效果方法animate()及其回调函数的使用
- coco2d-x 2.0.4 帧动画 两种实现方式
- coco2d-x使用备忘录
- 实现背景颜色(backgroundColor)的动画效果(animate)
- 用js实现类似jquery里的animate动画效果
- QT_record_not_technicalAriticle
- Java并发编程艺术----读书笔记(二)
- 一次完整的HTTP请求与响应涉及了哪些知识?
- Java中如何判断一个集合中的一个元素不在另一个集合中?把不存在的元素移除
- Json基础(详细讲+案例)
- coco2d-x 使用Action中的Animate实现动画效果
- ftp的学习
- 正则表达式
- JavaScript利用对象去重复值
- MySQL B+树索引和哈希索引的区别
- 图的最小生成树算法
- Spring的AOP原理
- 表达式求值(顺序栈实现)
- 6. ZigZag Conversion