之前写了个2.14版本的动作变化,见 http://www.cnblogs.com/creeper/p/3531304.html

3.x版本变化了很多,但是核心思想还是没有变化,所以对应3.x版本的改了一下放上来

有空的话把tolua的转换方法也放上来吧:)

 #ifndef __MISC_NODE_CCNUMBER_CHANGE_H__
#define __MISC_NODE_CCNUMBER_CHANGE_H__ #include <vector> #include "2d/CCAction.h"
#include "2d/CCAnimation.h"
#include "2d/CCActionInterval.h"
#include "base/CCProtocols.h"
#include "base/CCVector.h" //NS_CC_BEGIN
USING_NS_CC;
class Node;
class SpriteFrame;
class EventCustom; class NumberChange : public ActionInterval
{
public: static NumberChange* create(float duration, int fromNum, int toNum); virtual NumberChange* clone() const override;
virtual NumberChange* reverse(void) const override;
virtual void startWithTarget(cocos2d::Node *target) override;
virtual void update(float time) override; CC_CONSTRUCTOR_ACCESS:
NumberChange();
virtual ~NumberChange(); /** initializes the action */
bool initWithDuration(float duration, int fromNum, int toNum); protected:
int _fromNum;
int _toNum; private:
CC_DISALLOW_COPY_AND_ASSIGN(NumberChange);
}; //NS_CC_END #endif //__MISC_NODE_CCNUMBER_CHANGE_H__
 #include "2d/CCActionInterval.h"

 #include <stdarg.h>

 #include "2d/CCSprite.h"
#include "2d/CCNode.h"
#include "2d/CCSpriteFrame.h"
#include "2d/CCActionInstant.h"
#include "base/CCDirector.h"
#include "base/CCEventCustom.h"
#include "base/CCEventDispatcher.h"
#include "platform/CCStdC.h"
#include "deprecated/CCString.h"
#include "NumberChange.h" USING_NS_CC;
//NS_CC_BEGIN
NumberChange::NumberChange(){
} NumberChange::~NumberChange(){
} NumberChange* NumberChange::create(float duration, int fromNum, int toNum)
{
NumberChange *ret = new (std::nothrow) NumberChange();
ret->initWithDuration(duration, fromNum, toNum);
ret->autorelease(); return ret;
} bool NumberChange::initWithDuration(float duration, int fromNum, int toNum)
{
if (ActionInterval::initWithDuration(duration))
{
_fromNum = fromNum;
_toNum = toNum;
return true;
} return false;
} NumberChange* NumberChange::clone() const
{
// no copy constructor
auto a = new (std::nothrow) NumberChange();
a->initWithDuration(_duration, _fromNum, _toNum);
a->autorelease();
return a;
} void NumberChange::startWithTarget(cocos2d::Node *target)
{
ActionInterval::startWithTarget(target);
LabelProtocol *pLabel = dynamic_cast<LabelProtocol*>(target);
if (pLabel)
{
std::string numStr = cocos2d::StringUtils::format("%i", _fromNum);
pLabel->setString(numStr.c_str());
}
} NumberChange* NumberChange::reverse() const
{
return NumberChange::create(_duration, _toNum, _fromNum);
} void NumberChange::update(float t)
{
LabelProtocol *pLabel = dynamic_cast<LabelProtocol*>(_target);
if (pLabel)
{
int tempNum = (_toNum - _fromNum) * t;
int num = _fromNum + tempNum;
std::string numStr = cocos2d::StringUtils::format("%i", num);
pLabel->setString(numStr.c_str());
}
} //NS_CC_END

[cocos2dx 3.x]Label类数字变化动作的更多相关文章

  1. [cocos2dx动作]CCLabel类数字变化动作

    cococs2dx的CCLabel类的数字变化动作 介绍: 简单的数字变化动作(适用于CCLabel类对象, 包括CCLabelTTF, CCLabelAtlas, CCLabelBMFont等等) ...

  2. [Quick-x lua]CCLabel类数字变化动作

    之前写了个C++版本的,现在改成lua的, 两者原理是一样,但是动作的执行方式有些微区别 (因为lua无法继承CCActionInterval类,单纯使用lua的话无法调用action的update方 ...

  3. cocos2d-X学习之主要类介绍:动作:CCAction

    引用自:http://www.cnblogs.com/lhming/archive/2012/07/01/2572238.html 类继承图: 主要函数: virtual CCObject *  co ...

  4. 【Cocos2d-X开发学习笔记】第18期:动作类之改变动作对象、函数回调动作以及过程动作的使用

    本系列学习教程使用的是cocos2d-x-2.1.4(最新版为3.0alpha0-pre) ,PC开发环境Windows7,C++开发环境VS2010 一.改变动作执行对象 CCTargetedAct ...

  5. Cocos2d-x 3.0标签类Label

    Cocos2d-x 3.0后推出了新的标签类Label,这种标签通过使用FreeType[1]来使它在不同的平台上有相同的视觉效果.由于使用更快的缓存代理,它的渲染也将更加快速.Label提供了描边和 ...

  6. Cocos2dx源码赏析(4)之Action动作

    Cocos2dx源码赏析(4)之Action动作 本篇,依然是通过阅读源码的方式来简单赏析下Cocos2dx中Action动画的执行过程.当然,这里也只是通过这种方式来总结下对Cocos2dx引擎的理 ...

  7. 关于SWT中的Label类和Text类

    Label类的继承关系图 Label是SWT中最简单的界面组件,给出他的一个实例如下: public class Label1 { public static void main(String[] a ...

  8. 让数字变化炫酷起来,数字滚动Text组件[Unity]

    让数字滚动起来 上周我的策划又提了样需求,当玩家评分发生变动时,屏幕出现人物评分浮层UI,播放评分数字滚动动画.这类数字滚动需求非常常见,我就按一般思路,将startvalue与endvalue每隔一 ...

  9. cocos2d-x实例学习之常用类及其概要作用

    CCLayer,CCScene CCLayer类对应cocos2d-x引擎里的布景.每个游戏场景中都可以有很多层,每一层负责各自的任务,例如专门负责显示背景.专门负责显示道具和专门负责显示人物角色等. ...

随机推荐

  1. $(document).ready() 、 $('#id').load() 、window.onload 的区别

    今天做项目的时候遇到一个问题,结果死在了$(document).ready(). $('#id').load() .window.onload的区别上.然后,就整理一下,这三者的区别. 参考文章:ht ...

  2. 设计模式------Adapter(适配器)

    地址:http://blog.csdn.net/wuzhekai1985/article/details/6665542,仅供学习用. 适配器:STL实现了一种数据结构,称为双端队列(deque),支 ...

  3. 解决Asp.net中的Chart控件运行出现错误提示“ ChartImg.axd 执行子请求时出错”

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABTkAAAJwCAIAAADN5fIdAAAgAElEQVR4nOzdfZAc1X3o/VNFlbcoJf

  4. 通过自关联替代开窗函数实现SQL优化

    数据库环境:SQL SERVER 2005 我们平时都是通过开窗析函数来取代自关联,减少表扫描,从而优化SQL.今天,反其道而行, 用自关联改写开窗函数.我们先来看一下SQL. 原SQL语句 SELE ...

  5. mysql空间数据相关操作

    建表语句: CREATE TABLE ts.points ( name ) NOT NULL, location POINT NOT NULL, description ) ); 添加记录如下: IN ...

  6. ajax跨域请求的解决方案

    一直打算改造一下自己传统做网站的形式. 我是.Net程序员,含辛茹苦数年也没混出个什么名堂. 最近微信比较火, 由于现在大环境的影响和以前工作的总结和经验,我打算自己写一个数据,UI松耦合的比较新潮的 ...

  7. 06_XML的写入_dom4j添加、删除、修改Xml文件内容

    [工程截图] [person.xml]准备一个xml文件 <?xml version="1.0" encoding="UTF-8"?> <st ...

  8. 九度OJ 1528 最长回文子串 -- Manacher算法

    题目地址:http://ac.jobdu.com/problem.php?pid=1528 题目描述: 回文串就是一个正读和反读都一样的字符串,比如"level"或者"n ...

  9. linear-gradient 的“高能”用法

    首先,让我们来了解一下“linear-gradient”的基本用法: 说明:用线性渐变创建图像 语法: <linear-gradient> = linear-gradient([ [ &l ...

  10. 九度OJ1184二叉树

    题目描述: 编一个程序,读入用户输入的一串先序遍历字符串,根据此字符串建立一个二叉树(以指针方式存储).例如如下的先序遍历字符串:ABC##DE#G##F###其中“#”表示的是空格,空格字符代表空树 ...