Cocos2D-X2.2.3学习笔记12(瞬间动作)
到眼下我们已经学习了有
坐标系统
内存管理
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(瞬间动作)的更多相关文章
- Ext.Net学习笔记12:Ext.Net GridPanel Filter用法
Ext.Net学习笔记12:Ext.Net GridPanel Filter用法 Ext.Net GridPanel的用法在上一篇中已经介绍过,这篇笔记讲介绍Filter的用法. Filter是用来过 ...
- SQL反模式学习笔记12 存储图片或其他多媒体大文件
目标:存储图片或其他多媒体大文件 反模式:图片存储在数据库外的文件系统中,数据库表中存储文件的对应的路径和名称. 缺点: 1.文件不支持Delete操作.使用SQL语句删除一条记录时,对应的文 ...
- golang学习笔记12 beego table name `xxx` repeat register, must be unique 错误问题
golang学习笔记12 beego table name `xxx` repeat register, must be unique 错误问题 今天测试了重新建一个项目生成新的表,然后复制到旧的项目 ...
- Spring MVC 学习笔记12 —— SpringMVC+Hibernate开发(1)依赖包搭建
Spring MVC 学习笔记12 -- SpringMVC+Hibernate开发(1)依赖包搭建 用Hibernate帮助建立SpringMVC与数据库之间的联系,通过配置DAO层,Service ...
- Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)
#!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)'''from ...
- springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定
springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定 标签: springmvc springmvc学习笔记12-springmvc注解开发之包装类型參数绑定 需求 实现方 ...
- 并发编程学习笔记(12)----Fork/Join框架
1. Fork/Join 的概念 Fork指的是将系统进程分成多个执行分支(线程),Join即是等待,当fork()方法创建了多个线程之后,需要等待这些分支执行完毕之后,才能得到最终的结果,因此joi ...
- 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 ...
- SpringMVC:学习笔记(12)——ThreadLocal实现会话共享
SpringMVC:学习笔记(12)——ThreadLocal实现会话共享 ThreadLocal ThreadLocal,被称为线程局部变量.在并发编程的情况下,使用ThreadLocal创建的变量 ...
随机推荐
- android 中Log - 简单使用
例如,我们可以使用'Log.d'进行Debug,在java代码中输入Log.d(String tag, String message),tag为自己命名的tag,message为待输出的信息.然后打开 ...
- 程序里面的system.out.println()输出到其他位置,不输出到tomcat控制台。
设置startup.bat: call "%EXECUTABLE%" run %CMD_LINE_ARGS% >> ..\logs\kongzitai.txt 将sys ...
- Linux网络配置命令ifconfig输出信息解析
eth0 Link encap:Ethernet HWaddr 00:1e:4f:e9:c2:84 inet addr:128.224.163.153 Bcast:128.224.163 ...
- HashMap、HashTable学习
HashMap: HashMap 继承于AbstractMap,实现了Map.Cloneable.java.io.Serializable接口. HashMap 的实现不是同步的,这意味着它不是线程安 ...
- 【USACO 2.4.1】两只塔姆沃斯牛
[题目描述] 两只牛逃跑到了森林里.农夫John开始用他的专家技术追捕这两头牛.你的任务是模拟他们的行为(牛和John). 追击在10x10的平面网格内进行.一个格子可以是: 一个障碍物, 两头牛(它 ...
- Cookie、LocalStorge、SesstionStorge 的区别和用法
前言 总括:详细讲述Cookie.LocalStorge.SesstionStorge的区别和用法. 1. 各种存储方案的简单对比 Cookies:浏览器均支持,容量为4KB UserData:仅IE ...
- JQUERY1.9学习笔记 之基本过滤器(十二) 根元素选择器
根元素选择器 描述:选择文档的根节点元素.jQuery( ":root" ) 例:显示文档根节点标签名. <!DOCTYPE html><html lang=&q ...
- 文成小盆友python-num7 -常用模块补充 ,python 牛逼的面相对象
本篇内容: 常用模块的补充 python面相对象 一.常用模块补充 1.configparser模块 configparser 用于处理特定格式的文件,起内部是调用open()来实现的,他的使用场景是 ...
- Oracle开启归档
#查看数据库是否为归档模式select name ,log_mode from v$database; #改变归档模式到非归档模式shutdown normal/immediate; #关闭数据库st ...
- codevs 1017 乘积最大
1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描 ...