2012-09-17 14:27:17 +08:00
|
|
|
#include "CCBAnimationManager.h"
|
|
|
|
#include "CCBSequence.h"
|
|
|
|
#include "CCBSequenceProperty.h"
|
|
|
|
#include "CCBReader.h"
|
|
|
|
#include "CCBKeyframe.h"
|
|
|
|
#include "CCNode+CCBRelativePositioning.h"
|
|
|
|
#include <string>
|
|
|
|
#include <set>
|
2013-03-15 08:43:56 +08:00
|
|
|
#include "SimpleAudioEngine.h"
|
2013-03-19 06:41:47 +08:00
|
|
|
#include "CCBSelectorResolver.h"
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
using namespace cocos2d;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
NS_CC_EXT_BEGIN
|
|
|
|
|
|
|
|
// Implementation of CCBAinmationManager
|
|
|
|
|
|
|
|
CCBAnimationManager::CCBAnimationManager()
|
|
|
|
: mSequences(NULL)
|
|
|
|
, mNodeSequences(NULL)
|
|
|
|
, mBaseValues(NULL)
|
|
|
|
, mAutoPlaySequenceId(0)
|
|
|
|
, mRootNode(NULL)
|
2013-07-12 14:47:36 +08:00
|
|
|
, mRootContainerSize(Size::ZERO)
|
2012-09-17 14:27:17 +08:00
|
|
|
, mDelegate(NULL)
|
|
|
|
, mRunningSequence(NULL)
|
2013-03-20 10:41:20 +08:00
|
|
|
, jsControlled(false)
|
|
|
|
, mOwner(NULL)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCBAnimationManager::init()
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
mSequences = new Array();
|
|
|
|
mNodeSequences = new Dictionary();
|
|
|
|
mBaseValues = new Dictionary();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
mDocumentOutletNames = new Array();
|
|
|
|
mDocumentOutletNodes = new Array();
|
|
|
|
mDocumentCallbackNames = new Array();
|
|
|
|
mDocumentCallbackNodes = new Array();
|
|
|
|
mKeyframeCallbacks = new Array();
|
|
|
|
mKeyframeCallFuncs = new Dictionary();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2012-11-01 02:07:33 +08:00
|
|
|
mTarget = NULL;
|
|
|
|
mAnimationCompleteCallbackFunc = NULL;
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBAnimationManager::~CCBAnimationManager()
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
// DictElement *pElement = NULL;
|
2013-01-23 15:18:13 +08:00
|
|
|
// CCDICT_FOREACH(mNodeSequences, pElement)
|
|
|
|
// {
|
2013-06-20 14:15:53 +08:00
|
|
|
// Node *node = (Node*)pElement->getIntKey();
|
2013-01-23 15:18:13 +08:00
|
|
|
// node->release();
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// CCDICT_FOREACH(mBaseValues, pElement)
|
|
|
|
// {
|
2013-06-20 14:15:53 +08:00
|
|
|
// Node *node = (Node*)pElement->getIntKey();
|
2013-01-23 15:18:13 +08:00
|
|
|
// node->release();
|
|
|
|
// }
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
mNodeSequences->release();
|
|
|
|
mBaseValues->release();
|
|
|
|
mSequences->release();
|
|
|
|
setRootNode(NULL);
|
|
|
|
setDelegate(NULL);
|
2012-11-26 21:51:05 +08:00
|
|
|
|
|
|
|
CC_SAFE_RELEASE(mDocumentOutletNames);
|
|
|
|
CC_SAFE_RELEASE(mDocumentOutletNodes);
|
|
|
|
CC_SAFE_RELEASE(mDocumentCallbackNames);
|
|
|
|
CC_SAFE_RELEASE(mDocumentCallbackNodes);
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
CC_SAFE_RELEASE(mKeyframeCallFuncs);
|
|
|
|
CC_SAFE_RELEASE(mKeyframeCallbacks);
|
2013-01-23 15:14:40 +08:00
|
|
|
CC_SAFE_RELEASE(mTarget);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getSequences()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return mSequences;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setSequences(Array* seq)
|
2012-11-22 15:15:30 +08:00
|
|
|
{
|
|
|
|
mSequences = seq;
|
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
int CCBAnimationManager::getAutoPlaySequenceId()
|
|
|
|
{
|
|
|
|
return mAutoPlaySequenceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::setAutoPlaySequenceId(int autoPlaySequenceId)
|
|
|
|
{
|
|
|
|
mAutoPlaySequenceId = autoPlaySequenceId;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* CCBAnimationManager::getRootNode()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return mRootNode;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setRootNode(Node *pRootNode)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
mRootNode = pRootNode;
|
|
|
|
}
|
|
|
|
|
2012-11-02 08:52:07 +08:00
|
|
|
void CCBAnimationManager::setDocumentControllerName(const std::string &name) {
|
|
|
|
mDocumentControllerName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCBAnimationManager::getDocumentControllerName() {
|
|
|
|
return mDocumentControllerName;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::addDocumentCallbackNode(Node *node) {
|
2012-11-02 08:52:07 +08:00
|
|
|
mDocumentCallbackNodes->addObject(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::addDocumentCallbackName(std::string name) {
|
2013-06-20 14:15:53 +08:00
|
|
|
String *tmpName = String::create(name);
|
2012-11-02 08:52:07 +08:00
|
|
|
mDocumentCallbackNames->addObject(tmpName);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getDocumentCallbackNames() {
|
2012-11-02 08:52:07 +08:00
|
|
|
return mDocumentCallbackNames;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getDocumentCallbackNodes() {
|
2012-11-02 08:52:07 +08:00
|
|
|
return mDocumentCallbackNodes;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::addDocumentOutletNode(Node *node) {
|
2012-11-02 08:52:07 +08:00
|
|
|
mDocumentOutletNodes->addObject(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::addDocumentOutletName(std::string name) {
|
2013-06-20 14:15:53 +08:00
|
|
|
mDocumentOutletNames->addObject(String::create(name));
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getDocumentOutletNames() {
|
2012-11-02 08:52:07 +08:00
|
|
|
return mDocumentOutletNames;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getDocumentOutletNodes() {
|
2012-11-02 08:52:07 +08:00
|
|
|
return mDocumentOutletNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CCBAnimationManager::getLastCompletedSequenceName() {
|
|
|
|
return lastCompletedSequenceName;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getKeyframeCallbacks() {
|
2013-03-15 08:43:56 +08:00
|
|
|
return mKeyframeCallbacks;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
const Size& CCBAnimationManager::getRootContainerSize()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return mRootContainerSize;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setRootContainerSize(const Size &rootContainerSize)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
mRootContainerSize.setSize(rootContainerSize.width, rootContainerSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBAnimationManagerDelegate* CCBAnimationManager::getDelegate()
|
|
|
|
{
|
|
|
|
return mDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::setDelegate(CCBAnimationManagerDelegate *pDelegate)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
CC_SAFE_RELEASE(dynamic_cast<Object*>(mDelegate));
|
2012-09-17 14:27:17 +08:00
|
|
|
mDelegate = pDelegate;
|
2013-06-20 14:15:53 +08:00
|
|
|
CC_SAFE_RETAIN(dynamic_cast<Object*>(mDelegate));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CCBAnimationManager::getRunningSequenceName()
|
|
|
|
{
|
2013-05-08 15:53:54 +08:00
|
|
|
if (mRunningSequence)
|
|
|
|
{
|
|
|
|
return mRunningSequence->getName();
|
|
|
|
}
|
|
|
|
return NULL;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
const Size& CCBAnimationManager::getContainerSize(Node *pNode)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
if (pNode)
|
|
|
|
{
|
|
|
|
return pNode->getContentSize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return mRootContainerSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// refer to CCBReader::readNodeGraph() for data structure of pSeq
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::addNode(Node *pNode, Dictionary *pSeq)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-01-23 15:14:40 +08:00
|
|
|
// pNode->retain();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2012-09-22 02:02:29 +08:00
|
|
|
mNodeSequences->setObject(pSeq, (intptr_t)pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setBaseValue(Object *pValue, Node *pNode, const char *pPropName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary *props = (Dictionary*)mBaseValues->objectForKey((intptr_t)pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
if (! props)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
props = Dictionary::create();
|
2012-09-22 02:02:29 +08:00
|
|
|
mBaseValues->setObject(props, (intptr_t)pNode);
|
2013-01-23 15:14:40 +08:00
|
|
|
// pNode->retain();
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
props->setObject(pValue, pPropName);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Object* CCBAnimationManager::getBaseValue(Node *pNode, const char* pPropName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary *props = (Dictionary*)mBaseValues->objectForKey((intptr_t)pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
return props->objectForKey(pPropName);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCBAnimationManager::getSequenceId(const char* pSequenceName)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *pElement = NULL;
|
2012-09-17 14:27:17 +08:00
|
|
|
string seqName(pSequenceName);
|
|
|
|
CCARRAY_FOREACH(mSequences, pElement)
|
|
|
|
{
|
2013-07-09 14:29:51 +08:00
|
|
|
CCBSequence *seq = static_cast<CCBSequence*>(pElement);
|
2012-09-17 14:27:17 +08:00
|
|
|
if (seqName.compare(seq->getName()) == 0)
|
|
|
|
{
|
|
|
|
return seq->getSequenceId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBSequence* CCBAnimationManager::getSequence(int nSequenceId)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *pElement = NULL;
|
2012-09-17 14:27:17 +08:00
|
|
|
CCARRAY_FOREACH(mSequences, pElement)
|
|
|
|
{
|
2013-07-09 14:29:51 +08:00
|
|
|
CCBSequence *seq = static_cast<CCBSequence*>(pElement);
|
2012-09-17 14:27:17 +08:00
|
|
|
if (seq->getSequenceId() == nSequenceId)
|
|
|
|
{
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-01 02:07:33 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::moveAnimationsFromNode(Node* fromNode, Node* toNode) {
|
2012-11-01 02:07:33 +08:00
|
|
|
|
|
|
|
// Move base values
|
2013-06-20 14:15:53 +08:00
|
|
|
Object* baseValue = mBaseValues->objectForKey((intptr_t)fromNode);
|
2012-11-01 02:07:33 +08:00
|
|
|
if(baseValue) {
|
|
|
|
mBaseValues->setObject(baseValue, (intptr_t)toNode);
|
|
|
|
mBaseValues->removeObjectForKey((intptr_t)fromNode);
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2013-01-23 15:14:40 +08:00
|
|
|
// fromNode->release();
|
|
|
|
// toNode->retain();
|
2012-11-01 02:07:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Move seqs
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *seqs = mNodeSequences->objectForKey((intptr_t)fromNode);
|
2012-11-01 02:07:33 +08:00
|
|
|
if(seqs) {
|
|
|
|
mNodeSequences->setObject(seqs, (intptr_t)toNode);
|
|
|
|
mNodeSequences->removeObjectForKey((intptr_t)fromNode);
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2013-01-23 15:14:40 +08:00
|
|
|
// fromNode->release();
|
|
|
|
// toNode->retain();
|
2012-11-01 02:07:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
// Refer to CCBReader::readKeyframe() for the real type of value
|
2013-06-20 14:15:53 +08:00
|
|
|
ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const char *pPropName, Node *pNode)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-09-17 18:49:05 +08:00
|
|
|
float duration = pKeyframe1->getTime() - (pKeyframe0 ? pKeyframe0->getTime() : 0);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-03-20 14:25:30 +08:00
|
|
|
if (strcmp(pPropName, "rotationX") == 0)
|
2013-03-20 06:13:00 +08:00
|
|
|
{
|
|
|
|
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
|
|
|
return CCBRotateXTo::create(duration, value->getFloatValue());
|
|
|
|
}
|
|
|
|
else if(strcmp(pPropName, "rotationY") == 0)
|
|
|
|
{
|
|
|
|
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
|
|
|
return CCBRotateYTo::create(duration, value->getFloatValue());
|
|
|
|
}
|
2013-03-20 14:25:30 +08:00
|
|
|
else if (strcmp(pPropName, "rotation") == 0)
|
|
|
|
{
|
|
|
|
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
|
|
|
return CCBRotateTo::create(duration, value->getFloatValue());
|
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
else if (strcmp(pPropName, "opacity") == 0)
|
|
|
|
{
|
|
|
|
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
2013-06-20 14:15:53 +08:00
|
|
|
return FadeTo::create(duration, value->getByteValue());
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (strcmp(pPropName, "color") == 0)
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
Color3BWapper* color = (Color3BWapper*)pKeyframe1->getValue();
|
|
|
|
Color3B c = color->getColor();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return TintTo::create(duration, c.r, c.g, c.b);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (strcmp(pPropName, "visible") == 0)
|
|
|
|
{
|
|
|
|
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
|
|
|
if (value->getBoolValue())
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return Sequence::createWithTwoActions(DelayTime::create(duration), Show::create());
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return Sequence::createWithTwoActions(DelayTime::create(duration), Hide::create());
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strcmp(pPropName, "displayFrame") == 0)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return Sequence::createWithTwoActions(DelayTime::create(duration),
|
|
|
|
CCBSetSpriteFrame::create((SpriteFrame *)pKeyframe1->getValue()));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (strcmp(pPropName, "position") == 0)
|
|
|
|
{
|
|
|
|
// Get position type
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *array = (Array*)getBaseValue(pNode, pPropName);
|
2012-09-17 14:27:17 +08:00
|
|
|
int type = ((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
|
|
|
|
|
|
|
// Get relative position
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *value = (Array*)pKeyframe1->getValue();
|
2012-09-17 14:27:17 +08:00
|
|
|
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
|
|
|
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Size containerSize = getContainerSize(pNode->getParent());
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
Point absPos = getAbsolutePosition(Point(x,y), type, containerSize, pPropName);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return MoveTo::create(duration, absPos);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (strcmp(pPropName, "scale") == 0)
|
|
|
|
{
|
|
|
|
// Get position type
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *array = (Array*)getBaseValue(pNode, pPropName);
|
2012-09-17 14:27:17 +08:00
|
|
|
int type = ((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
|
|
|
|
|
|
|
// Get relative scale
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *value = (Array*)pKeyframe1->getValue();
|
2012-09-17 14:27:17 +08:00
|
|
|
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
|
|
|
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
|
|
|
|
|
|
|
if (type == kCCBScaleTypeMultiplyResolution)
|
|
|
|
{
|
|
|
|
float resolutionScale = CCBReader::getResolutionScale();
|
|
|
|
x *= resolutionScale;
|
|
|
|
y *= resolutionScale;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return ScaleTo::create(duration, x, y);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-03-15 08:43:56 +08:00
|
|
|
else if(strcmp(pPropName, "skew") == 0)
|
|
|
|
{
|
|
|
|
// Get relative skew
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *value = (Array*)pKeyframe1->getValue();
|
2013-03-15 08:43:56 +08:00
|
|
|
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
|
|
|
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return SkewTo::create(duration, x, y);
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLog("CCBReader: Failed to create animation for property: %s", pPropName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setAnimatedProperty(const char *pPropName, Node *pNode, Object *pValue, float fTweenDuration)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-11-01 02:07:33 +08:00
|
|
|
if (fTweenDuration > 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Create a fake keyframe to generate the action from
|
|
|
|
CCBKeyframe *kf1 = new CCBKeyframe();
|
|
|
|
kf1->autorelease();
|
|
|
|
kf1->setValue(pValue);
|
2012-11-01 02:07:33 +08:00
|
|
|
kf1->setTime(fTweenDuration);
|
2012-09-17 14:27:17 +08:00
|
|
|
kf1->setEasingType(kCCBKeyframeEasingLinear);
|
|
|
|
|
|
|
|
// Animate
|
2013-06-20 14:15:53 +08:00
|
|
|
ActionInterval *tweenAction = getAction(NULL, kf1, pPropName, pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
pNode->runAction(tweenAction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just set the value
|
|
|
|
|
|
|
|
if (strcmp(pPropName, "position") == 0)
|
|
|
|
{
|
|
|
|
// Get position type
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *array = (Array*)getBaseValue(pNode, pPropName);
|
2012-09-17 14:27:17 +08:00
|
|
|
int type = ((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
|
|
|
|
|
|
|
// Get relative position
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *value = (Array*)pValue;
|
2012-09-17 14:27:17 +08:00
|
|
|
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
|
|
|
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
pNode->setPosition(getAbsolutePosition(Point(x,y), type, getContainerSize(pNode->getParent()), pPropName));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (strcmp(pPropName, "scale") == 0)
|
|
|
|
{
|
2012-09-18 17:04:10 +08:00
|
|
|
// Get scale type
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *array = (Array*)getBaseValue(pNode, pPropName);
|
2012-09-17 14:27:17 +08:00
|
|
|
int type = ((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
|
|
|
|
|
|
|
// Get relative scale
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *value = (Array*)pValue;
|
2012-09-17 14:27:17 +08:00
|
|
|
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
|
|
|
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
|
|
|
|
|
|
|
setRelativeScale(pNode, x, y, type, pPropName);
|
|
|
|
}
|
2013-03-19 16:33:23 +08:00
|
|
|
else if(strcmp(pPropName, "skew") == 0)
|
|
|
|
{
|
2013-03-15 08:43:56 +08:00
|
|
|
// Get relative scale
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *value = (Array*)pValue;
|
2013-03-15 08:43:56 +08:00
|
|
|
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
|
|
|
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
|
|
|
|
2013-03-19 16:33:23 +08:00
|
|
|
pNode->setSkewX(x);
|
|
|
|
pNode->setSkewY(y);
|
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// [node setValue:value forKey:name];
|
|
|
|
|
2012-09-18 17:04:10 +08:00
|
|
|
// TODO only handle rotation, opacity, displayFrame, color
|
2012-09-17 14:27:17 +08:00
|
|
|
if (strcmp(pPropName, "rotation") == 0)
|
|
|
|
{
|
|
|
|
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
|
|
|
pNode->setRotation(rotate);
|
2013-03-20 14:25:30 +08:00
|
|
|
} else if(strcmp(pPropName, "rotationX") == 0)
|
|
|
|
{
|
|
|
|
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
|
|
|
pNode->setRotationX(rotate);
|
|
|
|
}else if(strcmp(pPropName, "rotationY") == 0)
|
|
|
|
{
|
|
|
|
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
|
|
|
pNode->setRotationY(rotate);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (strcmp(pPropName, "opacity") == 0)
|
|
|
|
{
|
|
|
|
int opacity = ((CCBValue*)pValue)->getByteValue();
|
2013-06-20 14:15:53 +08:00
|
|
|
(dynamic_cast<RGBAProtocol*>(pNode))->setOpacity(opacity);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2012-09-17 18:49:05 +08:00
|
|
|
else if (strcmp(pPropName, "displayFrame") == 0)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
((Sprite*)pNode)->setDisplayFrame((SpriteFrame*)pValue);
|
2012-09-17 18:49:05 +08:00
|
|
|
}
|
|
|
|
else if (strcmp(pPropName, "color") == 0)
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
Color3BWapper *color = (Color3BWapper*)pValue;
|
2013-06-20 14:15:53 +08:00
|
|
|
(dynamic_cast<RGBAProtocol*>(pNode))->setColor(color->getColor());
|
2012-09-17 18:49:05 +08:00
|
|
|
}
|
2012-11-01 02:07:33 +08:00
|
|
|
else if (strcmp(pPropName, "visible") == 0)
|
|
|
|
{
|
2013-01-05 18:35:11 +08:00
|
|
|
bool visible = ((CCBValue*)pValue)->getBoolValue();
|
|
|
|
pNode->setVisible(visible);
|
2012-11-01 02:07:33 +08:00
|
|
|
}
|
|
|
|
else
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-09-17 18:49:05 +08:00
|
|
|
CCLog("unsupported property name is %s", pPropName);
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "unsupported property now");
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setFirstFrame(Node *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *keyframes = pSeqProp->getKeyframes();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
if (keyframes->count() == 0)
|
|
|
|
{
|
|
|
|
// Use base value (no animation)
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *baseValue = getBaseValue(pNode, pSeqProp->getName());
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(baseValue, "No baseValue found for property");
|
2012-09-17 14:27:17 +08:00
|
|
|
setAnimatedProperty(pSeqProp->getName(), pNode, baseValue, fTweenDuration);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use first keyframe
|
|
|
|
CCBKeyframe *keyframe = (CCBKeyframe*)keyframes->objectAtIndex(0);
|
|
|
|
setAnimatedProperty(pSeqProp->getName(), pNode, keyframe->getValue(), fTweenDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ActionInterval* CCBAnimationManager::getEaseAction(ActionInterval *pAction, int nEasingType, float fEasingOpt)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
if (dynamic_cast<Sequence*>(pAction))
|
2013-02-19 12:27:39 +08:00
|
|
|
{
|
|
|
|
return pAction;
|
|
|
|
}
|
|
|
|
|
2013-01-21 11:18:06 +08:00
|
|
|
if (nEasingType == kCCBKeyframeEasingLinear)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return pAction;
|
|
|
|
}
|
2013-01-21 11:18:06 +08:00
|
|
|
else if (nEasingType == kCCBKeyframeEasingInstant)
|
|
|
|
{
|
|
|
|
return CCBEaseInstant::create(pAction);
|
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
else if (nEasingType == kCCBKeyframeEasingCubicIn)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseIn::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingCubicOut)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseOut::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingCubicInOut)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseInOut::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingBackIn)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBackIn::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingBackOut)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBackOut::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingBackInOut)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBackInOut::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingBounceIn)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBounceIn::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingBounceOut)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBounceOut::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingBounceInOut)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBounceInOut::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingElasticIn)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseElasticIn::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingElasticOut)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseElasticOut::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (nEasingType == kCCBKeyframeEasingElasticInOut)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseElasticInOut::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLog("CCBReader: Unkown easing type %d", nEasingType);
|
|
|
|
return pAction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Object* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* channel) {
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
float lastKeyframeTime = 0;
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *actions = Array::create();
|
|
|
|
Array *keyframes = channel->getKeyframes();
|
2013-03-15 08:43:56 +08:00
|
|
|
int numKeyframes = keyframes->count();
|
|
|
|
|
2013-03-19 16:33:23 +08:00
|
|
|
for (int i = 0; i < numKeyframes; ++i) {
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
CCBKeyframe *keyframe = (CCBKeyframe*)keyframes->objectAtIndex(i);
|
|
|
|
float timeSinceLastKeyframe = keyframe->getTime() - lastKeyframeTime;
|
2013-03-19 16:33:23 +08:00
|
|
|
lastKeyframeTime = keyframe->getTime();
|
2013-03-19 06:41:47 +08:00
|
|
|
if(timeSinceLastKeyframe > 0) {
|
2013-06-20 14:15:53 +08:00
|
|
|
actions->addObject(DelayTime::create(timeSinceLastKeyframe));
|
2013-03-19 06:41:47 +08:00
|
|
|
}
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* keyVal = (Array *)keyframe->getValue();
|
|
|
|
std::string selectorName = ((String *)keyVal->objectAtIndex(0))->getCString();
|
|
|
|
int selectorTarget = atoi(((String *)keyVal->objectAtIndex(1))->getCString());
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-03-19 06:41:47 +08:00
|
|
|
if(jsControlled) {
|
2013-06-20 14:15:53 +08:00
|
|
|
String* callbackName = String::createWithFormat("%d:%s", selectorTarget, selectorName.c_str());
|
2013-07-04 17:54:02 +08:00
|
|
|
CallFunc *callback = ((CallFunc*)(mKeyframeCallFuncs->objectForKey(callbackName->getCString())))->clone();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-03-19 06:41:47 +08:00
|
|
|
if(callback != NULL) {
|
|
|
|
actions->addObject(callback);
|
|
|
|
}
|
|
|
|
} else {
|
2013-06-20 14:15:53 +08:00
|
|
|
Object* target = NULL;
|
2013-03-19 06:41:47 +08:00
|
|
|
if(selectorTarget == kCCBTargetTypeDocumentRoot) target = mRootNode;
|
|
|
|
else if (selectorTarget == kCCBTargetTypeOwner) target = mOwner;
|
|
|
|
if(target != NULL) {
|
|
|
|
if(selectorName.length() > 0) {
|
|
|
|
SEL_CallFuncN selCallFunc = 0;
|
|
|
|
|
|
|
|
CCBSelectorResolver* targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
|
2013-03-19 16:33:23 +08:00
|
|
|
|
2013-03-19 06:41:47 +08:00
|
|
|
if(targetAsCCBSelectorResolver != NULL) {
|
2013-06-20 14:15:53 +08:00
|
|
|
selCallFunc = targetAsCCBSelectorResolver->onResolveCCBCallFuncSelector(target, selectorName.c_str ());
|
2013-03-19 06:41:47 +08:00
|
|
|
}
|
|
|
|
if(selCallFunc == 0) {
|
|
|
|
CCLOG("Skipping selector '%s' since no CCBSelectorResolver is present.", selectorName.c_str());
|
|
|
|
} else {
|
2013-06-20 14:15:53 +08:00
|
|
|
CallFuncN *callback = CallFuncN::create(target, selCallFunc);
|
2013-03-19 06:41:47 +08:00
|
|
|
actions->addObject(callback);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CCLOG("Unexpected empty selector.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-15 08:43:56 +08:00
|
|
|
if(actions->count() < 1) return NULL;
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return (Object *) Sequence::create(actions);
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Object* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel) {
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
float lastKeyframeTime = 0;
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *actions = Array::create();
|
|
|
|
Array *keyframes = channel->getKeyframes();
|
2013-03-15 08:43:56 +08:00
|
|
|
int numKeyframes = keyframes->count();
|
|
|
|
|
2013-03-19 16:33:23 +08:00
|
|
|
for (int i = 0; i < numKeyframes; ++i) {
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
CCBKeyframe *keyframe = (CCBKeyframe*)keyframes->objectAtIndex(i);
|
|
|
|
float timeSinceLastKeyframe = keyframe->getTime() - lastKeyframeTime;
|
2013-03-19 16:33:23 +08:00
|
|
|
lastKeyframeTime = keyframe->getTime();
|
2013-03-15 08:43:56 +08:00
|
|
|
if(timeSinceLastKeyframe > 0) {
|
2013-06-20 14:15:53 +08:00
|
|
|
actions->addObject(DelayTime::create(timeSinceLastKeyframe));
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stringstream ss (stringstream::in | stringstream::out);
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* keyVal = (Array*)keyframe->getValue();
|
|
|
|
std::string soundFile = ((String *)keyVal->objectAtIndex(0))->getCString();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
float pitch, pan, gain;
|
2013-06-20 14:15:53 +08:00
|
|
|
ss << ((String *)keyVal->objectAtIndex(1))->getCString();
|
2013-03-15 08:43:56 +08:00
|
|
|
ss >> pitch;
|
|
|
|
ss.flush();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ss << ((String *)keyVal->objectAtIndex(2))->getCString();
|
2013-03-15 08:43:56 +08:00
|
|
|
ss >> pan;
|
|
|
|
ss.flush();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ss << ((String *)keyVal->objectAtIndex(3))->getCString();
|
2013-03-15 08:43:56 +08:00
|
|
|
ss >> gain;
|
|
|
|
ss.flush();
|
|
|
|
|
|
|
|
actions->addObject(CCBSoundEffect::actionWithSoundFile(soundFile, pitch, pan, gain));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(actions->count() < 1) return NULL;
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return (Object *) Sequence::create(actions);
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::runAction(Node *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *keyframes = pSeqProp->getKeyframes();
|
2012-09-17 14:27:17 +08:00
|
|
|
int numKeyframes = keyframes->count();
|
|
|
|
|
|
|
|
if (numKeyframes > 1)
|
|
|
|
{
|
|
|
|
// Make an animation!
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *actions = Array::create();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
CCBKeyframe *keyframeFirst = (CCBKeyframe*)keyframes->objectAtIndex(0);
|
|
|
|
float timeFirst = keyframeFirst->getTime() + fTweenDuration;
|
|
|
|
|
|
|
|
if (timeFirst > 0)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
actions->addObject(DelayTime::create(timeFirst));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < numKeyframes - 1; ++i)
|
|
|
|
{
|
|
|
|
CCBKeyframe *kf0 = (CCBKeyframe*)keyframes->objectAtIndex(i);
|
|
|
|
CCBKeyframe *kf1 = (CCBKeyframe*)keyframes->objectAtIndex(i+1);
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ActionInterval *action = getAction(kf0, kf1, pSeqProp->getName(), pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
// Apply easing
|
|
|
|
action = getEaseAction(action, kf0->getEasingType(), kf0->getEasingOpt());
|
|
|
|
|
|
|
|
actions->addObject(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
FiniteTimeAction *seq = Sequence::create(actions);
|
2012-09-17 14:27:17 +08:00
|
|
|
pNode->runAction(seq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 11:49:20 +08:00
|
|
|
void CCBAnimationManager::runAnimations(const char *pName, float fTweenDuration)
|
|
|
|
{
|
|
|
|
runAnimationsForSequenceNamedTweenDuration(pName, fTweenDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::runAnimations(const char *pName)
|
|
|
|
{
|
|
|
|
runAnimationsForSequenceNamed(pName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::runAnimations(int nSeqId, float fTweenDuraiton)
|
|
|
|
{
|
|
|
|
runAnimationsForSequenceIdTweenDuration(nSeqId, fTweenDuraiton);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::runAnimationsForSequenceIdTweenDuration(int nSeqId, float fTweenDuration)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(nSeqId != -1, "Sequence id couldn't be found");
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
mRootNode->stopAllActions();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
DictElement* pElement = NULL;
|
2012-09-17 14:27:17 +08:00
|
|
|
CCDICT_FOREACH(mNodeSequences, pElement)
|
|
|
|
{
|
2013-07-09 14:40:43 +08:00
|
|
|
Node *node = reinterpret_cast<Node*>(pElement->getIntKey());
|
2012-09-17 14:27:17 +08:00
|
|
|
node->stopAllActions();
|
|
|
|
|
|
|
|
// Refer to CCBReader::readKeyframe() for the real type of value
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary *seqs = (Dictionary*)pElement->getObject();
|
|
|
|
Dictionary *seqNodeProps = (Dictionary*)seqs->objectForKey(nSeqId);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
set<string> seqNodePropNames;
|
|
|
|
|
|
|
|
if (seqNodeProps)
|
|
|
|
{
|
|
|
|
// Reset nodes that have sequence node properties, and run actions on them
|
2013-06-20 14:15:53 +08:00
|
|
|
DictElement* pElement1 = NULL;
|
2012-09-17 14:27:17 +08:00
|
|
|
CCDICT_FOREACH(seqNodeProps, pElement1)
|
|
|
|
{
|
2012-09-18 17:04:10 +08:00
|
|
|
const char *propName = pElement1->getStrKey();
|
2013-07-09 14:40:43 +08:00
|
|
|
CCBSequenceProperty *seqProp = static_cast<CCBSequenceProperty*>(seqNodeProps->objectForKey(propName));
|
2012-09-18 17:04:10 +08:00
|
|
|
seqNodePropNames.insert(propName);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
setFirstFrame(node, seqProp, fTweenDuration);
|
|
|
|
runAction(node, seqProp, fTweenDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the nodes that may have been changed by other timelines
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary *nodeBaseValues = (Dictionary*)mBaseValues->objectForKey(pElement->getIntKey());
|
2012-09-17 14:27:17 +08:00
|
|
|
if (nodeBaseValues)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
DictElement* pElement2 = NULL;
|
2012-09-17 14:27:17 +08:00
|
|
|
CCDICT_FOREACH(nodeBaseValues, pElement2)
|
|
|
|
{
|
2012-09-18 17:04:10 +08:00
|
|
|
if (seqNodePropNames.find(pElement2->getStrKey()) == seqNodePropNames.end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *value = pElement2->getObject();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
2012-09-18 17:04:10 +08:00
|
|
|
setAnimatedProperty(pElement2->getStrKey(), node, value, fTweenDuration);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make callback at end of sequence
|
|
|
|
CCBSequence *seq = getSequence(nSeqId);
|
2013-06-20 14:15:53 +08:00
|
|
|
Action *completeAction = Sequence::createWithTwoActions(DelayTime::create(seq->getDuration() + fTweenDuration),
|
2013-07-16 03:43:22 +08:00
|
|
|
CallFunc::create( CC_CALLBACK_0(CCBAnimationManager::sequenceCompleted,this)));
|
2012-09-17 14:27:17 +08:00
|
|
|
mRootNode->runAction(completeAction);
|
|
|
|
|
|
|
|
// Set the running scene
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
if(seq->getCallbackChannel() != NULL) {
|
2013-06-20 14:15:53 +08:00
|
|
|
Action* action = (Action *)actionForCallbackChannel(seq->getCallbackChannel());
|
2013-03-19 06:41:47 +08:00
|
|
|
if(action != NULL) {
|
|
|
|
mRootNode->runAction(action);
|
|
|
|
}
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(seq->getSoundChannel() != NULL) {
|
2013-06-20 14:15:53 +08:00
|
|
|
Action* action = (Action *)actionForSoundChannel(seq->getSoundChannel());
|
2013-03-19 16:33:23 +08:00
|
|
|
if(action != NULL) {
|
|
|
|
mRootNode->runAction(action);
|
|
|
|
}
|
|
|
|
}
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
mRunningSequence = getSequence(nSeqId);
|
|
|
|
}
|
|
|
|
|
2012-11-28 11:49:20 +08:00
|
|
|
void CCBAnimationManager::runAnimationsForSequenceNamedTweenDuration(const char *pName, float fTweenDuration)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
int seqId = getSequenceId(pName);
|
2012-11-28 11:49:20 +08:00
|
|
|
runAnimationsForSequenceIdTweenDuration(seqId, fTweenDuration);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 11:49:20 +08:00
|
|
|
void CCBAnimationManager::runAnimationsForSequenceNamed(const char *pName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-11-28 11:49:20 +08:00
|
|
|
runAnimationsForSequenceNamedTweenDuration(pName, 0);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::debug()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setAnimationCompletedCallback(Object *target, SEL_CallFunc callbackFunc) {
|
2012-11-01 02:07:33 +08:00
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
target->retain();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTarget)
|
|
|
|
{
|
|
|
|
mTarget->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
mTarget = target;
|
|
|
|
mAnimationCompleteCallbackFunc = callbackFunc;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setCallFunc(CallFunc* callFunc, const std::string &callbackNamed) {
|
|
|
|
mKeyframeCallFuncs->setObject((Object*)callFunc, callbackNamed);
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
void CCBAnimationManager::sequenceCompleted()
|
|
|
|
{
|
2012-12-13 13:21:58 +08:00
|
|
|
const char *runningSequenceName = mRunningSequence->getName();
|
|
|
|
int nextSeqId = mRunningSequence->getChainedSequenceId();
|
|
|
|
mRunningSequence = NULL;
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2012-12-13 13:21:58 +08:00
|
|
|
if(lastCompletedSequenceName != runningSequenceName) {
|
|
|
|
lastCompletedSequenceName = runningSequenceName;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
if (mDelegate)
|
|
|
|
{
|
2012-12-13 13:21:58 +08:00
|
|
|
// There may be another runAnimation() call in this delegate method
|
|
|
|
// which will assign mRunningSequence
|
|
|
|
mDelegate->completedAnimationSequenceNamed(runningSequenceName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2012-11-01 02:07:33 +08:00
|
|
|
if (mTarget && mAnimationCompleteCallbackFunc) {
|
|
|
|
(mTarget->*mAnimationCompleteCallbackFunc)();
|
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
if (nextSeqId != -1)
|
|
|
|
{
|
2012-11-28 11:49:20 +08:00
|
|
|
runAnimationsForSequenceIdTweenDuration(nextSeqId, 0);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 11:18:06 +08:00
|
|
|
// Custom actions
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
/************************************************************
|
|
|
|
CCBSetSpriteFrame
|
|
|
|
************************************************************/
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
CCBSetSpriteFrame* CCBSetSpriteFrame::create(SpriteFrame *pSpriteFrame)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
CCBSetSpriteFrame *ret = new CCBSetSpriteFrame();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithSpriteFrame(pSpriteFrame))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
bool CCBSetSpriteFrame::initWithSpriteFrame(SpriteFrame *pSpriteFrame)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
mSpriteFrame = pSpriteFrame;
|
|
|
|
CC_SAFE_RETAIN(mSpriteFrame);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBSetSpriteFrame::~CCBSetSpriteFrame()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(mSpriteFrame);
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBSetSpriteFrame* CCBSetSpriteFrame::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBSetSpriteFrame();
|
|
|
|
a->initWithSpriteFrame(mSpriteFrame);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBSetSpriteFrame* CCBSetSpriteFrame::reverse() const
|
|
|
|
{
|
|
|
|
// returns a copy of itself
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
void CCBSetSpriteFrame::update(float time)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
((Sprite*)_target)->setDisplayFrame(mSpriteFrame);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
CCBSoundEffect
|
|
|
|
************************************************************/
|
|
|
|
|
|
|
|
CCBSoundEffect* CCBSoundEffect::actionWithSoundFile(const std::string &filename, float pitch, float pan, float gain) {
|
|
|
|
CCBSoundEffect* pRet = new CCBSoundEffect();
|
|
|
|
if (pRet != NULL && pRet->initWithSoundFile(filename, pitch, pan, gain))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-03-19 06:41:47 +08:00
|
|
|
|
|
|
|
CCBSoundEffect::~CCBSoundEffect()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
bool CCBSoundEffect::initWithSoundFile(const std::string &filename, float pitch, float pan, float gain) {
|
|
|
|
mSoundFile = filename;
|
|
|
|
mPitch = pitch;
|
|
|
|
mPan = pan;
|
|
|
|
mGain = gain;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBSoundEffect* CCBSoundEffect::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBSoundEffect();
|
|
|
|
a->initWithSoundFile(mSoundFile, mPitch, mPan, mGain);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBSoundEffect* CCBSoundEffect::reverse() const
|
|
|
|
{
|
|
|
|
// returns a copy of itself
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
void CCBSoundEffect::update(float time)
|
|
|
|
{
|
2013-07-19 07:30:19 +08:00
|
|
|
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(mSoundFile.c_str());
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
/************************************************************
|
|
|
|
CCBRotateTo
|
|
|
|
************************************************************/
|
|
|
|
|
|
|
|
CCBRotateTo* CCBRotateTo::create(float fDuration, float fAngle)
|
|
|
|
{
|
|
|
|
CCBRotateTo *ret = new CCBRotateTo();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(fDuration, fAngle))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCBRotateTo::initWithDuration(float fDuration, float fAngle)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
if (ActionInterval::initWithDuration(fDuration))
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
mDstAngle = fAngle;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBRotateTo* CCBRotateTo::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBRotateTo();
|
|
|
|
a->initWithDuration(_duration, mDstAngle);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBRotateTo* CCBRotateTo::reverse() const
|
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "reverse() is not supported in CCBRotateTo");
|
2013-06-19 06:06:53 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBRotateTo::startWithTarget(Node *pNode)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ActionInterval::startWithTarget(pNode);
|
2013-06-15 14:03:30 +08:00
|
|
|
mStartAngle = _target->getRotation();
|
2012-09-17 14:27:17 +08:00
|
|
|
mDiffAngle = mDstAngle - mStartAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBRotateTo::update(float time)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setRotation(mStartAngle + (mDiffAngle * time))
|
2012-09-18 17:55:03 +08:00
|
|
|
;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-03-20 06:13:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
CCBRotateXTO
|
|
|
|
************************************************************/
|
|
|
|
|
|
|
|
|
2013-03-20 14:25:30 +08:00
|
|
|
CCBRotateXTo* CCBRotateXTo::create(float fDuration, float fAngle)
|
|
|
|
{
|
|
|
|
CCBRotateXTo *ret = new CCBRotateXTo();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(fDuration, fAngle))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCBRotateXTo::initWithDuration(float fDuration, float fAngle)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
if (ActionInterval::initWithDuration(fDuration))
|
2013-03-20 14:25:30 +08:00
|
|
|
{
|
|
|
|
mDstAngle = fAngle;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBRotateXTo::startWithTarget(Node *pNode)
|
2013-03-20 06:13:00 +08:00
|
|
|
{
|
2013-03-20 14:25:30 +08:00
|
|
|
//CCActionInterval::startWithTarget(pNode);
|
2013-06-15 14:03:30 +08:00
|
|
|
_originalTarget = pNode;
|
|
|
|
_target = pNode;
|
|
|
|
_elapsed = 0.0f;
|
|
|
|
_firstTick = true;
|
|
|
|
mStartAngle = _target->getRotationX();
|
2013-03-20 06:13:00 +08:00
|
|
|
mDiffAngle = mDstAngle - mStartAngle;
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBRotateXTo* CCBRotateXTo::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBRotateXTo();
|
|
|
|
a->initWithDuration(_duration, mDstAngle);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBRotateXTo* CCBRotateXTo::reverse() const
|
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "reverse() is not supported in CCBRotateXTo");
|
2013-06-19 06:06:53 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-03-20 06:13:00 +08:00
|
|
|
void CCBRotateXTo::update(float time)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setRotationX(mStartAngle + (mDiffAngle * time))
|
2013-03-20 06:13:00 +08:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
CCBRotateYTO
|
|
|
|
************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-20 14:25:30 +08:00
|
|
|
CCBRotateYTo* CCBRotateYTo::create(float fDuration, float fAngle)
|
|
|
|
{
|
|
|
|
CCBRotateYTo *ret = new CCBRotateYTo();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(fDuration, fAngle))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCBRotateYTo::initWithDuration(float fDuration, float fAngle)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
if (ActionInterval::initWithDuration(fDuration))
|
2013-03-20 14:25:30 +08:00
|
|
|
{
|
|
|
|
mDstAngle = fAngle;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBRotateYTo* CCBRotateYTo::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBRotateYTo();
|
|
|
|
a->initWithDuration(_duration, mDstAngle);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBRotateYTo* CCBRotateYTo::reverse() const
|
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "reverse() is not supported in CCBRotateXTo");
|
2013-06-19 06:06:53 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-03-20 14:25:30 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBRotateYTo::startWithTarget(Node *pNode)
|
2013-03-20 06:13:00 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
// ActionInterval::startWithTarget(pNode);
|
2013-06-15 14:03:30 +08:00
|
|
|
_originalTarget = pNode;
|
|
|
|
_target = pNode;
|
|
|
|
_elapsed = 0.0f;
|
|
|
|
_firstTick = true;
|
|
|
|
mStartAngle = _target->getRotationY();
|
2013-03-20 06:13:00 +08:00
|
|
|
mDiffAngle = mDstAngle - mStartAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBRotateYTo::update(float time)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setRotationY(mStartAngle + (mDiffAngle * time))
|
2013-03-20 06:13:00 +08:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-21 11:18:06 +08:00
|
|
|
/************************************************************
|
|
|
|
CCBEaseInstant
|
|
|
|
************************************************************/
|
2013-06-20 14:15:53 +08:00
|
|
|
CCBEaseInstant* CCBEaseInstant::create(ActionInterval *pAction)
|
2013-01-21 11:18:06 +08:00
|
|
|
{
|
|
|
|
CCBEaseInstant *pRet = new CCBEaseInstant();
|
|
|
|
if (pRet && pRet->initWithAction(pAction))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(pRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBEaseInstant* CCBEaseInstant::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBEaseInstant();
|
|
|
|
a->initWithAction(_inner);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBEaseInstant* CCBEaseInstant::reverse() const
|
|
|
|
{
|
|
|
|
return CCBEaseInstant::create(_inner->reverse());
|
|
|
|
}
|
|
|
|
|
2013-01-21 11:18:06 +08:00
|
|
|
void CCBEaseInstant::update(float dt)
|
|
|
|
{
|
|
|
|
if (dt < 0)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_inner->update(0);
|
2013-01-21 11:18:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_inner->update(1);
|
2013-01-21 11:18:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
NS_CC_EXT_END
|