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(瞬时动作)的更多相关文章

  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. ASP.NET自学之路(转载)

    第一步 掌握一门NET面向对象语言,C#或VB.NET 我强烈反对在没系统学过一门面向对象(OO)语言的前提下去学ASP.NET. ASP.NET是一个全面向对象的技术,不懂OO,那绝对学不下去! 第 ...

  2. html引用ttf字体文件

    在样式表如此定义: @font-face { font-family: MyFontName;//自定义字体名称 src: url(../Gloss_And_Bloom.ttf) } 然后,具体使用: ...

  3. 防止asp.net连续点击按钮重复提交

    1.在Page_Load中添加如下代码: protected void Page_Load(object sender, EventArgs e) { this.btnEdit.Attributes[ ...

  4. css滚动条样式修改

    .activeMoreBankList{ height: 188px; overflow-y: auto;} /*滚动条样式*/.activeMoreBankList::-webkit-scrollb ...

  5. js页面跳转定位

    A页面 <!DOCTYPE html> <html> <head> <meta name="viewport" content=" ...

  6. MFC定时器的使用

    巧妙地使用定时器能达到意想不到的效果,写界面的时候能实现渐变,也能帮助多线程控制等我们知道,在VC的MFC中,已经为我们封装好了很多全面和强大的函数集,所以在MFC编程时,巧妙地调用MFC函数库可以为 ...

  7. NOIp十连测 涂色游戏

    [问题描述]小A 和小B 在做游戏.他们找到了一个n 行m 列呈网格状的画板.小A 拿出了p 支不同颜色的画笔,开始在上面涂色.看到小A 涂好的画板,小B 觉得颜色太单调了,于是把画板擦干净,希望涂上 ...

  8. ubuntu环境安装docker

    查看已安装的docker apt list docker* 如果已安装,并且需要卸载,则执行以下命令: apt remove docker* 更新apt索引 apt update apt需要支持HTT ...

  9. Java 读取linux上的文件

    今天遇到一个问题,在Windows环境上开发,测试环境和正式环境服务器都是linux: 一个导出表格的功能,在本地没问题,发布到linux服务器就报找不到文件问题,但是模板文件已经在linux下了.刚 ...

  10. thinkphp5 框架修改的地方

    框架修改的地方 vendor/topthink/think-captcha/src/Captcha.php api验证码入库 196行 $img_code = strtoupper(implode(' ...