CCActionTween(可以时间上连续的改变某个对象指定key对应的属性 改变方式需要自定义 cocos2dx未定义 )
2014-05-21 17:46
609 查看
#ifndef __CCACTIONTWEEN_H__
#define __CCACTIONTWEEN_H__
///怎么通过精灵属性得到相应值啊 ????????
#include "CCActionInterval.h"
NS_CC_BEGIN
class CC_DLL CCActionTweenDelegate
{
public: //太不规范了 不写构造函数(虽然会隐式声明)!!!!!!!!!!!!!!!!!!!!!!!!!!
virtual ~CCActionTweenDelegate() {}
virtual void updateTweenAction(float value, const char* key) = 0;
};
/** CCActionTween
CCActionTween is an action that lets you update any property of an object
//.ActionTween 是一个 action 让允许你更新任何对象的属性
For example, if you want to modify the "width" property of a target from 200 to 300 in 2 seconds, then:
id modifyWidth = [CCActionTween actionWithDuration:2 key:@"width" from:200 to:300];
[target runAction:modifyWidth];
Another example: CCScaleTo action could be rewritten using CCPropertyAction:
// scaleA and scaleB are equivalents
id scaleA = [CCScaleTo actionWithDuration:2 scale:3];
id scaleB = [CCActionTween actionWithDuration:2 key:@"scale" from:1 to:3];
@since v0.99.2
*/
class CC_DLL CCActionTween : public CCActionInterval
{
public:
/** creates an initializes the action with the property name (key), and the from and to(从xx到) parameters(参数). */
static CCActionTween* create(float aDuration, const char* key, float from, float to);
/** initializes the action with the property name (key), and the from and to parameters. */
bool initWithDuration(float aDuration, const char* key, float from, float to);
void startWithTarget(CCNode *pTarget);
void update(float dt);
CCActionInterval* reverse();
std::string m_strKey;
float m_fFrom, m_fTo;
float m_fDelta;
};
// end of actions group
/// @}
NS_CC_END
#endif /* __CCACTIONTWEEN_H__ */
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.cpp
void CCActionTween::startWithTarget(CCNode *pTarget)
{
CCAssert(dynamic_cast<CCActionTweenDelegate*>(pTarget), "target must implement CCActionTweenDelegate");
CCActionInterval::startWithTarget(pTarget);
m_fDelta = m_fTo - m_fFrom;
}
void CCActionTween::update(float dt)
{
dynamic_cast<CCActionTweenDelegate*>(m_pTarget)->updateTweenAction(m_fTo - m_fDelta * (1 - dt), m_strKey.c_str());
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
例子:
class originalTargeted
{
public:
originalTargeted(){ m_map["width"] = 18; }
~originalTargeted(){}
map<string, int> m_map;
};
class CCActionTweenDelegate02 :public cocos2d::CCActionTweenDelegate, public cocos2d::CCNode
{
public:
CCActionTweenDelegate02(originalTargeted* d){ ot = d; }
virtual ~CCActionTweenDelegate02() {}
virtual void updateTweenAction(float value, const char* key);
originalTargeted* ot;
};
_____________________________
main()
{
originalTargeted* test = new originalTargeted;
CCActionTweenDelegate02* s = new CCActionTweenDelegate02(test);
CCActionTween* testaction = CCActionTween::create(2, "width", 1, 2);
s->runAction(testaction);
testaction->update(1); //???为什么runaction 不执行update
}
void CCActionTweenDelegate02::updateTweenAction(float value, const char* key)
{
this->ot->m_map[key] = 12;
}
#define __CCACTIONTWEEN_H__
///怎么通过精灵属性得到相应值啊 ????????
#include "CCActionInterval.h"
NS_CC_BEGIN
class CC_DLL CCActionTweenDelegate
{
public: //太不规范了 不写构造函数(虽然会隐式声明)!!!!!!!!!!!!!!!!!!!!!!!!!!
virtual ~CCActionTweenDelegate() {}
virtual void updateTweenAction(float value, const char* key) = 0;
};
/** CCActionTween
CCActionTween is an action that lets you update any property of an object
//.ActionTween 是一个 action 让允许你更新任何对象的属性
For example, if you want to modify the "width" property of a target from 200 to 300 in 2 seconds, then:
id modifyWidth = [CCActionTween actionWithDuration:2 key:@"width" from:200 to:300];
[target runAction:modifyWidth];
Another example: CCScaleTo action could be rewritten using CCPropertyAction:
// scaleA and scaleB are equivalents
id scaleA = [CCScaleTo actionWithDuration:2 scale:3];
id scaleB = [CCActionTween actionWithDuration:2 key:@"scale" from:1 to:3];
@since v0.99.2
*/
class CC_DLL CCActionTween : public CCActionInterval
{
public:
/** creates an initializes the action with the property name (key), and the from and to(从xx到) parameters(参数). */
static CCActionTween* create(float aDuration, const char* key, float from, float to);
/** initializes the action with the property name (key), and the from and to parameters. */
bool initWithDuration(float aDuration, const char* key, float from, float to);
void startWithTarget(CCNode *pTarget);
void update(float dt);
CCActionInterval* reverse();
std::string m_strKey;
float m_fFrom, m_fTo;
float m_fDelta;
};
// end of actions group
/// @}
NS_CC_END
#endif /* __CCACTIONTWEEN_H__ */
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.cpp
void CCActionTween::startWithTarget(CCNode *pTarget)
{
CCAssert(dynamic_cast<CCActionTweenDelegate*>(pTarget), "target must implement CCActionTweenDelegate");
CCActionInterval::startWithTarget(pTarget);
m_fDelta = m_fTo - m_fFrom;
}
void CCActionTween::update(float dt)
{
dynamic_cast<CCActionTweenDelegate*>(m_pTarget)->updateTweenAction(m_fTo - m_fDelta * (1 - dt), m_strKey.c_str());
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
例子:
class originalTargeted
{
public:
originalTargeted(){ m_map["width"] = 18; }
~originalTargeted(){}
map<string, int> m_map;
};
class CCActionTweenDelegate02 :public cocos2d::CCActionTweenDelegate, public cocos2d::CCNode
{
public:
CCActionTweenDelegate02(originalTargeted* d){ ot = d; }
virtual ~CCActionTweenDelegate02() {}
virtual void updateTweenAction(float value, const char* key);
originalTargeted* ot;
};
_____________________________
main()
{
originalTargeted* test = new originalTargeted;
CCActionTweenDelegate02* s = new CCActionTweenDelegate02(test);
CCActionTween* testaction = CCActionTween::create(2, "width", 1, 2);
s->runAction(testaction);
testaction->update(1); //???为什么runaction 不执行update
}
void CCActionTweenDelegate02::updateTweenAction(float value, const char* key)
{
this->ot->m_map[key] = 12;
}
相关文章推荐
- struts2中用setValue可以改变对象栈中指定属性的值
- 动态方法调用 在Struts2中动态方法调用有三种方式,动态方法调用就是为了解决一个Action对应多个请求的处理,以免Action太多 第一种方式:指定method属性 这种方式我们前面已经用到过
- hibernate 返回对象指定属性,需要返回的列,可以直接返回 对象属性
- 当需要把一个对象的值赋给另一个对象中对应的属性时……
- 【OC复合题】之定义一个学生类,需要有姓名,年龄,考试成绩三个成员属性,创建5个对象,属性可以任意值。(Objective-C)
- 为什么 ActionContext 可以获取域对象对应的 Map
- const定义的对象属性是否可以改变
- ######【spring属性注入(Ioc的DI)总结】:注解方式属性注入,属性名任意.=for理解:Aop注入代理对象时,注入被增强类对象时,属性名为proxy(自定义)。
- Active Server Pages, ASP 0113 (0x80004005)超过了脚本运行的最长时间。可以为 Server.ScriptTimeOut 属性指定新值或更改 IIS 管理工具中的相应值来更改此限制
- TreeSet集合存放自定义类型的对象,可以使用比较器,实现Comparable接口自己设置排序方式
- Android Manifest.xml中需要覆盖应用的model属性可以用replace方式轻易做到
- CCActionEase(可以对动作进行包装 使动作的in和out速度发生改变 使动作更平滑)
- setValueForKeyPath理解。访问设置对象的属性的话可以使用setValue forKey 访问属性的属性forKeyPath
- android开发(26) 和其他应用交换数据方式一,使用intent指定自定义action调用其他程序里的activity,并获得其返回的结果
- 今天无意中发现JavaBean类基本都要求实现了Serializable接口,以前只是知道序列化以后,可以通过io流的方式将对象序列化和反序列化,进行存取,但不知道为什么需要序列化,今天总结一下
- 将时间写在.properties文件中可以随时改变,避免修改后台Action
- json工具处理对象属性时,该属性需要特殊处理时,例如时间本来是yyyy/MM/dd你想转换为yyyy-MM-dd
- ahjesus在asp.net中还可以通过设置HttpCookie对象的过期时间为DateTime.MinValue来指定此Cookies为跟随浏览器生效
- 在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理。 例如: //实例化一个NSDateFormatter对象 NSDateFor
- 自定义对象中文排序,可以指定排序的字段名,较为通用