到眼下我们已经学习了有

坐标系统

内存管理

UI系统

事件处理

几何图形

今天我们来学习动作管理OK

我们来看看类结构图

CCAction   全部动作的基类

以下派生了三个子类:CCFiniteTimeAction,CCFollow,CCSpeed

这些我们先不看  我们主要来介绍一下瞬时动作,

CCActionInstant

瞬时动作 故而 一瞬间就完毕的动作,它没有延迟时间的

好的  開始

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" class HelloWorld : public cocos2d::CCLayer
{
public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init(); // there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::CCScene* scene(); // implement the "static node()" method manually
CREATE_FUNC(HelloWorld);
}; #endif // __HELLOWORLD_SCENE_H__
#include "HelloWorldScene.h"

USING_NS_CC;

CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create(); // 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create(); // add layer as a child to scene
scene->addChild(layer); // return the scene
return scene;
} // on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
} CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCSprite* pSprite1= CCSprite::create("Icon.png");
pSprite1->setPosition(ccp(visibleSize.width/2-pSprite1->getContentSize().width,visibleSize.height/2));
this->addChild(pSprite1); CCSprite* pSprite2= CCSprite::create("Icon.png");
pSprite2->setPosition(ccp(visibleSize.width/2+pSprite1->getContentSize().width,visibleSize.height/2));
this->addChild(pSprite2); return true;
}

我们创建了二个精灵显示,这里主要是为了等下演示翻转动作时候能看出效果来

bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
} CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCSprite* pSprite1= CCSprite::create("Icon.png");
pSprite1->setPosition(ccp(visibleSize.width/2-pSprite1->getContentSize().width,visibleSize.height/2));
this->addChild(pSprite1); //翻转X轴
//參数:true 翻转 false 不翻转
CCActionInstant* pFlipX= CCFlipX::create(true);
pSprite1->runAction(pFlipX);
//翻转Y轴
//參数:true 翻转 false 不翻转
CCActionInstant* pFlipY=CCFlipY::create(true);
pSprite1->runAction(pFlipY); CCSprite* pSprite2= CCSprite::create("Icon.png");
pSprite2->setPosition(ccp(visibleSize.width/2+pSprite1->getContentSize().width,visibleSize.height/2));
this->addChild(pSprite2); return true;
}

我们用精灵1运行动作。精灵2什么都不做,明显就看到差别了

显示隐藏动作:

//隐藏动画
CCActionInstant* pHide= CCHide::create();
pSprite1->runAction(pHide); //显示动画
CCActionInstant* pShow= CCShow::create();
pSprite1->runAction(pShow); //假设是隐藏运行该动作就显示,假设是显示运行动作后就隐藏
CCActionInstant* pToggleVisibility= CCToggleVisibility::create();;
pSprite1->runAction(pToggleVisibility);

移动位置动作:

//參数:须要移动到指定的位置
CCActionInstant* pPlace= CCPlace::create(ccp(visibleSize.width/2-pSprite1->getContentSize().width,visibleSize.height/2-50));
pSprite1->runAction(pPlace);

移除动作:

//參数:是否清理内存,true 清理 false 不清理
//注:这里的參数可不是是否移除咯
CCActionInstant* pRemoveSelf= CCRemoveSelf::create(true);
pSprite1->runAction(pRemoveSelf);

OK   瞬时动作就这些,还有几个神马神马Grid,Bsound神马神马的   都不经常使用。以后用到的时候再暂时发挥吧

总结:

瞬时动作基类  CCActionInstant

翻转动作:CCFlipX,CCFlipY

隐藏显示动作:CCHideCCShow
CCToggleVisibility

移动位置动作:CCPlace

删除操作:CCRemoveSelf

版权声明:本文博主原创文章,博客,未经同意不得转载。

Cocos2D-X2.2.3学习笔记12(瞬间动作)的更多相关文章

  1. Ext.Net学习笔记12:Ext.Net GridPanel Filter用法

    Ext.Net学习笔记12:Ext.Net GridPanel Filter用法 Ext.Net GridPanel的用法在上一篇中已经介绍过,这篇笔记讲介绍Filter的用法. Filter是用来过 ...

  2. SQL反模式学习笔记12 存储图片或其他多媒体大文件

    目标:存储图片或其他多媒体大文件 反模式:图片存储在数据库外的文件系统中,数据库表中存储文件的对应的路径和名称. 缺点:     1.文件不支持Delete操作.使用SQL语句删除一条记录时,对应的文 ...

  3. golang学习笔记12 beego table name `xxx` repeat register, must be unique 错误问题

    golang学习笔记12 beego table name `xxx` repeat register, must be unique 错误问题 今天测试了重新建一个项目生成新的表,然后复制到旧的项目 ...

  4. Spring MVC 学习笔记12 —— SpringMVC+Hibernate开发(1)依赖包搭建

    Spring MVC 学习笔记12 -- SpringMVC+Hibernate开发(1)依赖包搭建 用Hibernate帮助建立SpringMVC与数据库之间的联系,通过配置DAO层,Service ...

  5. Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)'''from ...

  6. springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定

    springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定 标签: springmvc springmvc学习笔记12-springmvc注解开发之包装类型參数绑定 需求 实现方 ...

  7. 并发编程学习笔记(12)----Fork/Join框架

    1. Fork/Join 的概念 Fork指的是将系统进程分成多个执行分支(线程),Join即是等待,当fork()方法创建了多个线程之后,需要等待这些分支执行完毕之后,才能得到最终的结果,因此joi ...

  8. matlab学习笔记12单元数组和元胞数组 cell,celldisp,iscell,isa,deal,cellfun,num2cell,size

    一起来学matlab-matlab学习笔记12 12_1 单元数组和元胞数组 cell array --cell,celldisp,iscell,isa,deal,cellfun,num2cell,s ...

  9. SpringMVC:学习笔记(12)——ThreadLocal实现会话共享

    SpringMVC:学习笔记(12)——ThreadLocal实现会话共享 ThreadLocal ThreadLocal,被称为线程局部变量.在并发编程的情况下,使用ThreadLocal创建的变量 ...

随机推荐

  1. BOM和DOM详解

    DOM介绍 D(文档)可以理解为整个Web加载的网页文档,O(对象)可以理解为类似window对象只来的东西,可以调用属性和方法,这里我们说的是document对象,M(模型)可以理解为网页文档的树形 ...

  2. Android学习----Android架构

    android分为四个层,从高层到低层分别是应用程序层.应用程序框架层.系统运行库层和linux核心层.蓝色的代表java程序,黄色的代码为运行JAVA程序而实现的虚拟机,绿色部分为C/C++语言编写 ...

  3. windows批处理命令之ren

    1.批处理批量修改文件后缀名(假设我需要把一个文件夹中的很多txt文件改为sql文件): 1)在需要被处理的文件的文件夹里先新建一个txt文本,然后在文本中写入: ren *.txt *.sql 2) ...

  4. 外卖的撕‘哔’大战 CSU 1559

                                                      CSU 1559 Time Limit:1000MS     Memory Limit:131072 ...

  5. sqlserver 进行MD5加密

    官方定义函数: HashBytes ( '<algorithm>', { @input | 'input' } )  <algorithm>::= MD2 | MD4 | MD ...

  6. solr拼写检查代码逻辑

    自定义的solr搜索系统作为web应用发布到tomcat后,运行过程中其搜索代码逻辑如下: 用户solr搜索应用发送搜索请求URL,solr应用的org.apache.solr.servlet.Sol ...

  7. NTOPNG修改密码

    感觉这个有点妖,因为在两个实例上修改密码都失败了. 于是,从网上看看是怎么回事, 按以下步骤重置你想要的密码: 1,为密码生成MD5字串: echo -n "your_password&qu ...

  8. linux crontab 计划任务 atd和windows下的计划任务

    crontab 命令 如果发现您的系统里没有这个命令,请安装下面两个软件包. vixie-cron crontabs crontab 是用来让使用者在固定时间或固定间隔执行程序之用,换句话说,也就是类 ...

  9. 百度识图API

    http://stu.baidu.com/ http://www.360doc.com/content/14/0801/17/21412_398653199.shtml http://download ...

  10. 2015WF有感

    World Final题目连接:http://icpc.baylor.edu/worldfinals/problems/icpc2015.pdf 建议:可以倒序阅读来获得最直观的赛场体验... 2:1 ...