Cocos2D-X2.2.3学习笔记12(瞬时动作)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHVjYmxvZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
到眼下我们已经学习了有
坐标系统
内存管理
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创建的变量 ...
随机推荐
- 【JavaScript从入门到精通】第二课
第二课 初探JavaScript魅力-02 变量 说起变量,我们不得不提起我们有一部比较古老的电视剧叫<包青天>.包青天有一把非常厉害的宝剑叫“尚方宝剑”,见到尚方宝剑有如见到皇帝.某种程 ...
- JavaSE-15 Log4j参数详解
一:日志记录器输出级别,共有5级(从前往后的顺序排列) ①fatel:指出严重的错误事件将会导致应用程序的退出 ②error:指出虽然发生错误事件,但仍然不影响系统的继续运行 ③warn:表明会出现潜 ...
- 启发式合并CodeForces - 1009F
E - Dominant Indices CodeForces - 1009F You are given a rooted undirected tree consisting of nn vert ...
- Layui下拉选渲染
下拉选渲染有很多方式,这个比较简单,记录一下: HTML代码如下: <div class="layui-input-inline"> <input type=&q ...
- 配置jdk环境变量和配置的作用
对于JDK要配置三个环境变量,分别是JAVA_HOME.path.classpath 对于我本人电脑来说,配置如下: JAVA_HOME:C:\Program Files\Java\jdk1.8.0_ ...
- js 技巧 (十)广告JS代码效果大全 【3】
3.[允许关闭] 与前面两个代码不同的是,广告图下方增加了一个图片按纽,允许访客点击关闭广告图片,下面文本框中就是实现效果所需代码: var delta=0.015; var coll ...
- android 如何从activity跳转到另一个activity下指定的fragment
思路: 跳转到目标fragment所在的activity,并传递一个flag,来确定要到哪个fragment,根据该flag判断后,跳转到指定的fragment即可. 代码: 当前界面: intent ...
- 立方体 反射 CubeMap
立方体反射(CubeMap) 在虚拟环境中,我们需要模拟材质球反射周围的环境,立方体反射正是让材质球反射出天空盒的背景的方法之一. 原理 当我们观察物体时,物体表面足够光滑,再视线方向和物体相交的点上 ...
- Mvc Action可以通过jsonp方式调取
jsonp其实是一种特殊的数据获取格式,所以在Aicton直接调取的时候肯定会出现问题,下面代码是对于jsonp调取做的处理 protected virtual ActionResult Create ...
- 升级到Offiec 2016后 Power View 不见了的处理方法
好吧 并不是没有了,而只是快捷方式需要手动的调整出来, 过程还是挺复杂,给一个官方文档吧. Turn on Power View in Excel 2016 for Windows https://s ...