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()
|
2013-07-29 14:07:57 +08:00
|
|
|
: _jsControlled(false)
|
|
|
|
, _owner(NULL)
|
|
|
|
, _sequences(NULL)
|
2013-07-27 21:44:49 +08:00
|
|
|
, _nodeSequences(NULL)
|
|
|
|
, _baseValues(NULL)
|
|
|
|
, _autoPlaySequenceId(0)
|
|
|
|
, _rootNode(NULL)
|
|
|
|
, _rootContainerSize(Size::ZERO)
|
|
|
|
, _delegate(NULL)
|
|
|
|
, _runningSequence(NULL)
|
2013-07-29 14:07:57 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCBAnimationManager::init()
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
_sequences = new Array();
|
|
|
|
_nodeSequences = new Dictionary();
|
|
|
|
_baseValues = new Dictionary();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
_documentOutletNames = new Array();
|
|
|
|
_documentOutletNodes = new Array();
|
|
|
|
_documentCallbackNames = new Array();
|
|
|
|
_documentCallbackNodes = new Array();
|
|
|
|
_keyframeCallbacks = new Array();
|
2013-07-27 22:31:57 +08:00
|
|
|
_keyframeCallFuncs = new Dictionary();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
_target = NULL;
|
|
|
|
_animationCompleteCallbackFunc = NULL;
|
2012-11-01 02:07:33 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBAnimationManager::~CCBAnimationManager()
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
// DictElement *pElement = NULL;
|
2013-07-27 21:44:49 +08:00
|
|
|
// CCDICT_FOREACH(_nodeSequences, pElement)
|
2013-01-23 15:18:13 +08:00
|
|
|
// {
|
2013-06-20 14:15:53 +08:00
|
|
|
// Node *node = (Node*)pElement->getIntKey();
|
2013-01-23 15:18:13 +08:00
|
|
|
// node->release();
|
|
|
|
// }
|
|
|
|
//
|
2013-07-27 21:44:49 +08:00
|
|
|
// CCDICT_FOREACH(_baseValues, pElement)
|
2013-01-23 15:18:13 +08:00
|
|
|
// {
|
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
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
_nodeSequences->release();
|
|
|
|
_baseValues->release();
|
|
|
|
_sequences->release();
|
2012-09-17 14:27:17 +08:00
|
|
|
setRootNode(NULL);
|
|
|
|
setDelegate(NULL);
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
CC_SAFE_RELEASE(_documentOutletNames);
|
|
|
|
CC_SAFE_RELEASE(_documentOutletNodes);
|
|
|
|
CC_SAFE_RELEASE(_documentCallbackNames);
|
|
|
|
CC_SAFE_RELEASE(_documentCallbackNodes);
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
CC_SAFE_RELEASE(_keyframeCallFuncs);
|
2013-07-27 21:44:49 +08:00
|
|
|
CC_SAFE_RELEASE(_keyframeCallbacks);
|
|
|
|
CC_SAFE_RELEASE(_target);
|
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
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _sequences;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setSequences(Array* seq)
|
2012-11-22 15:15:30 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
_sequences = seq;
|
2012-11-22 15:15:30 +08:00
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
int CCBAnimationManager::getAutoPlaySequenceId()
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _autoPlaySequenceId;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::setAutoPlaySequenceId(int autoPlaySequenceId)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
_autoPlaySequenceId = autoPlaySequenceId;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* CCBAnimationManager::getRootNode()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _rootNode;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setRootNode(Node *pRootNode)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
_rootNode = pRootNode;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2012-11-02 08:52:07 +08:00
|
|
|
void CCBAnimationManager::setDocumentControllerName(const std::string &name) {
|
2013-07-27 21:44:49 +08:00
|
|
|
_documentControllerName = name;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string CCBAnimationManager::getDocumentControllerName() {
|
2013-07-27 21:44:49 +08:00
|
|
|
return _documentControllerName;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::addDocumentCallbackNode(Node *node) {
|
2013-07-27 21:44:49 +08:00
|
|
|
_documentCallbackNodes->addObject(node);
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::addDocumentCallbackName(std::string name) {
|
2013-06-20 14:15:53 +08:00
|
|
|
String *tmpName = String::create(name);
|
2013-07-27 21:44:49 +08:00
|
|
|
_documentCallbackNames->addObject(tmpName);
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getDocumentCallbackNames() {
|
2013-07-27 21:44:49 +08:00
|
|
|
return _documentCallbackNames;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getDocumentCallbackNodes() {
|
2013-07-27 21:44:49 +08:00
|
|
|
return _documentCallbackNodes;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::addDocumentOutletNode(Node *node) {
|
2013-07-27 21:44:49 +08:00
|
|
|
_documentOutletNodes->addObject(node);
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::addDocumentOutletName(std::string name) {
|
2013-07-27 21:44:49 +08:00
|
|
|
_documentOutletNames->addObject(String::create(name));
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getDocumentOutletNames() {
|
2013-07-27 21:44:49 +08:00
|
|
|
return _documentOutletNames;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getDocumentOutletNodes() {
|
2013-07-27 21:44:49 +08:00
|
|
|
return _documentOutletNodes;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CCBAnimationManager::getLastCompletedSequenceName() {
|
2013-07-27 21:44:49 +08:00
|
|
|
return _lastCompletedSequenceName;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBAnimationManager::getKeyframeCallbacks() {
|
2013-07-27 21:44:49 +08:00
|
|
|
return _keyframeCallbacks;
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
const Size& CCBAnimationManager::getRootContainerSize()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _rootContainerSize;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setRootContainerSize(const Size &rootContainerSize)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
_rootContainerSize.setSize(rootContainerSize.width, rootContainerSize.height);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCBAnimationManagerDelegate* CCBAnimationManager::getDelegate()
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _delegate;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCBAnimationManager::setDelegate(CCBAnimationManagerDelegate *pDelegate)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
CC_SAFE_RELEASE(dynamic_cast<Object*>(_delegate));
|
|
|
|
_delegate = pDelegate;
|
|
|
|
CC_SAFE_RETAIN(dynamic_cast<Object*>(_delegate));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* CCBAnimationManager::getRunningSequenceName()
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
if (_runningSequence)
|
2013-05-08 15:53:54 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _runningSequence->getName();
|
2013-05-08 15:53:54 +08:00
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _rootContainerSize;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
_nodeSequences->setObject(pSeq, (intptr_t)pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void CCBAnimationManager::setBaseValue(Object *pValue, Node *pNode, const char *propName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Dictionary *props = (Dictionary*)_baseValues->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();
|
2013-07-27 21:44:49 +08:00
|
|
|
_baseValues->setObject(props, (intptr_t)pNode);
|
2013-01-23 15:14:40 +08:00
|
|
|
// pNode->retain();
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
props->setObject(pValue, propName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Object* CCBAnimationManager::getBaseValue(Node *pNode, const char* propName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Dictionary *props = (Dictionary*)_baseValues->objectForKey((intptr_t)pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
return props->objectForKey(propName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2013-07-27 21:44:49 +08:00
|
|
|
CCARRAY_FOREACH(_sequences, pElement)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
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;
|
2013-07-27 21:44:49 +08:00
|
|
|
CCARRAY_FOREACH(_sequences, pElement)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2013-08-05 10:23:41 +08:00
|
|
|
float CCBAnimationManager::getSequenceDuration(const char *pSequenceName)
|
|
|
|
{
|
|
|
|
int id = getSequenceId(pSequenceName);
|
|
|
|
if (id != -1)
|
|
|
|
return getSequence(id)->getDuration();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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-07-27 21:44:49 +08:00
|
|
|
Object* baseValue = _baseValues->objectForKey((intptr_t)fromNode);
|
2012-11-01 02:07:33 +08:00
|
|
|
if(baseValue) {
|
2013-07-27 21:44:49 +08:00
|
|
|
_baseValues->setObject(baseValue, (intptr_t)toNode);
|
|
|
|
_baseValues->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-07-27 21:44:49 +08:00
|
|
|
Object *seqs = _nodeSequences->objectForKey((intptr_t)fromNode);
|
2012-11-01 02:07:33 +08:00
|
|
|
if(seqs) {
|
2013-07-27 21:44:49 +08:00
|
|
|
_nodeSequences->setObject(seqs, (intptr_t)toNode);
|
|
|
|
_nodeSequences->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-07-27 21:44:49 +08:00
|
|
|
ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const char *propName, 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-07-27 21:44:49 +08:00
|
|
|
if (strcmp(propName, "rotationX") == 0)
|
2013-03-20 06:13:00 +08:00
|
|
|
{
|
|
|
|
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
|
|
|
return CCBRotateXTo::create(duration, value->getFloatValue());
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if(strcmp(propName, "rotationY") == 0)
|
2013-03-20 06:13:00 +08:00
|
|
|
{
|
|
|
|
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
|
|
|
return CCBRotateYTo::create(duration, value->getFloatValue());
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "rotation") == 0)
|
2013-03-20 14:25:30 +08:00
|
|
|
{
|
|
|
|
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
|
|
|
return CCBRotateTo::create(duration, value->getFloatValue());
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "opacity") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "color") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
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
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "visible") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "displayFrame") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
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
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "position") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Get position type
|
2013-07-27 21:44:49 +08:00
|
|
|
Array *array = static_cast<Array*>(getBaseValue(pNode, propName));
|
|
|
|
CCBReader::PositionType type = (CCBReader::PositionType)((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// Get relative position
|
2013-07-27 21:44:49 +08:00
|
|
|
Array *value = static_cast<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-27 21:44:49 +08:00
|
|
|
Point absPos = getAbsolutePosition(Point(x,y), type, containerSize, propName);
|
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
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "scale") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Get position type
|
2013-07-27 21:44:49 +08:00
|
|
|
Array *array = (Array*)getBaseValue(pNode, propName);
|
|
|
|
CCBReader::ScaleType type = (CCBReader::ScaleType)((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (type == CCBReader::ScaleType::MULTIPLY_RESOLUTION)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
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-07-27 21:44:49 +08:00
|
|
|
else if(strcmp(propName, "skew") == 0)
|
2013-03-15 08:43:56 +08:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
log("CCBReader: Failed to create animation for property: %s", propName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void CCBAnimationManager::setAnimatedProperty(const char *propName, 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);
|
2013-07-27 21:44:49 +08:00
|
|
|
kf1->setEasingType(CCBKeyframe::EasingType::LINEAR);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// Animate
|
2013-07-27 21:44:49 +08:00
|
|
|
ActionInterval *tweenAction = getAction(NULL, kf1, propName, pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
pNode->runAction(tweenAction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just set the value
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (strcmp(propName, "position") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Get position type
|
2013-07-27 21:44:49 +08:00
|
|
|
Array *array = (Array*)getBaseValue(pNode, propName);
|
|
|
|
CCBReader::PositionType type = (CCBReader::PositionType)((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// 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-27 21:44:49 +08:00
|
|
|
pNode->setPosition(getAbsolutePosition(Point(x,y), type, getContainerSize(pNode->getParent()), propName));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "scale") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-09-18 17:04:10 +08:00
|
|
|
// Get scale type
|
2013-07-27 21:44:49 +08:00
|
|
|
Array *array = (Array*)getBaseValue(pNode, propName);
|
|
|
|
CCBReader::ScaleType type = (CCBReader::ScaleType)((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
setRelativeScale(pNode, x, y, type, propName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if(strcmp(propName, "skew") == 0)
|
2013-03-19 16:33:23 +08:00
|
|
|
{
|
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
|
2013-07-27 21:44:49 +08:00
|
|
|
if (strcmp(propName, "rotation") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
|
|
|
pNode->setRotation(rotate);
|
2013-07-27 21:44:49 +08:00
|
|
|
} else if(strcmp(propName, "rotationX") == 0)
|
2013-03-20 14:25:30 +08:00
|
|
|
{
|
|
|
|
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
|
|
|
pNode->setRotationX(rotate);
|
2013-07-27 21:44:49 +08:00
|
|
|
}else if(strcmp(propName, "rotationY") == 0)
|
2013-03-20 14:25:30 +08:00
|
|
|
{
|
|
|
|
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
|
|
|
pNode->setRotationY(rotate);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "opacity") == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "displayFrame") == 0)
|
2012-09-17 18:49:05 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
((Sprite*)pNode)->setDisplayFrame((SpriteFrame*)pValue);
|
2012-09-17 18:49:05 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "color") == 0)
|
2012-09-17 18:49:05 +08:00
|
|
|
{
|
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
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (strcmp(propName, "visible") == 0)
|
2012-11-01 02:07:33 +08:00
|
|
|
{
|
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
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
log("unsupported property name is %s", propName);
|
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-07-27 21:44:49 +08:00
|
|
|
ActionInterval* CCBAnimationManager::getEaseAction(ActionInterval *pAction, CCBKeyframe::EasingType easingType, 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-07-27 21:44:49 +08:00
|
|
|
if (easingType == CCBKeyframe::EasingType::LINEAR)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return pAction;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::INSTANT)
|
2013-01-21 11:18:06 +08:00
|
|
|
{
|
|
|
|
return CCBEaseInstant::create(pAction);
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::CUBIC_IN)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseIn::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::CUBIC_OUT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseOut::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::CUBIC_INOUT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseInOut::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::BACK_IN)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBackIn::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::BACK_OUT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBackOut::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::BACK_INOUT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBackInOut::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::BOUNCE_IN)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBounceIn::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::BOUNCE_OUT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBounceOut::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::BOUNCE_INOUT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseBounceInOut::create(pAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::ELASTIC_IN)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseElasticIn::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::ELASTIC_OUT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseElasticOut::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (easingType == CCBKeyframe::EasingType::ELASTIC_INOUT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return EaseElasticInOut::create(pAction, fEasingOpt);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
log("CCBReader: Unkown easing type %d", easingType);
|
2012-09-17 14:27:17 +08:00
|
|
|
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-07-27 21:44:49 +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-07-27 21:44:49 +08:00
|
|
|
Array* keyVal = static_cast<Array *>(keyframe->getValue());
|
|
|
|
std::string selectorName = static_cast<String *>(keyVal->objectAtIndex(0))->getCString();
|
|
|
|
CCBReader::TargetType selectorTarget = (CCBReader::TargetType)atoi(static_cast<String *>(keyVal->objectAtIndex(1))->getCString());
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(_jsControlled) {
|
2013-06-20 14:15:53 +08:00
|
|
|
String* callbackName = String::createWithFormat("%d:%s", selectorTarget, selectorName.c_str());
|
2013-07-27 22:31:57 +08:00
|
|
|
CallFunc *callback = ((CallFunc*)(_keyframeCallFuncs->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);
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Object* target = NULL;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
|
|
|
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
|
|
|
|
target = _rootNode;
|
|
|
|
else if (selectorTarget == CCBReader::TargetType::OWNER)
|
2013-07-27 22:31:57 +08:00
|
|
|
target = _owner;
|
2013-07-27 21:44:49 +08:00
|
|
|
|
|
|
|
if(target != NULL)
|
|
|
|
{
|
|
|
|
if(selectorName.length() > 0)
|
|
|
|
{
|
2013-03-19 06:41:47 +08:00
|
|
|
SEL_CallFuncN selCallFunc = 0;
|
|
|
|
|
|
|
|
CCBSelectorResolver* targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
|
2013-03-19 16:33:23 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(targetAsCCBSelectorResolver != NULL)
|
|
|
|
{
|
2013-07-24 17:59:21 +08:00
|
|
|
selCallFunc = targetAsCCBSelectorResolver->onResolveCCBCCCallFuncSelector(target, selectorName.c_str ());
|
2013-03-19 06:41:47 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
|
|
|
|
if(selCallFunc == 0)
|
|
|
|
{
|
2013-03-19 06:41:47 +08:00
|
|
|
CCLOG("Skipping selector '%s' since no CCBSelectorResolver is present.", selectorName.c_str());
|
2013-07-27 21:44:49 +08:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-19 06:41:47 +08:00
|
|
|
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
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
_rootNode->stopAllActions();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
DictElement* pElement = NULL;
|
2013-07-27 21:44:49 +08:00
|
|
|
CCDICT_FOREACH(_nodeSequences, pElement)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
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-07-27 21:44:49 +08:00
|
|
|
Dictionary *nodeBaseValues = (Dictionary*)_baseValues->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)));
|
2013-07-27 21:44:49 +08:00
|
|
|
_rootNode->runAction(completeAction);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// 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) {
|
2013-07-27 21:44:49 +08:00
|
|
|
_rootNode->runAction(action);
|
2013-03-19 06:41:47 +08:00
|
|
|
}
|
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) {
|
2013-07-27 21:44:49 +08:00
|
|
|
_rootNode->runAction(action);
|
2013-03-19 16:33:23 +08:00
|
|
|
}
|
|
|
|
}
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
_runningSequence = getSequence(nSeqId);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (_target)
|
2012-11-01 02:07:33 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
_target->release();
|
2012-11-01 02:07:33 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
_target = target;
|
|
|
|
_animationCompleteCallbackFunc = callbackFunc;
|
2012-11-01 02:07:33 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBAnimationManager::setCallFunc(CallFunc* callFunc, const std::string &callbackNamed) {
|
2013-07-27 22:31:57 +08:00
|
|
|
_keyframeCallFuncs->setObject((Object*)callFunc, callbackNamed);
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
void CCBAnimationManager::sequenceCompleted()
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
const char *runningSequenceName = _runningSequence->getName();
|
|
|
|
int nextSeqId = _runningSequence->getChainedSequenceId();
|
|
|
|
_runningSequence = NULL;
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(_lastCompletedSequenceName != runningSequenceName) {
|
|
|
|
_lastCompletedSequenceName = runningSequenceName;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (_delegate)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-12-13 13:21:58 +08:00
|
|
|
// There may be another runAnimation() call in this delegate method
|
2013-07-27 21:44:49 +08:00
|
|
|
// which will assign _runningSequence
|
|
|
|
_delegate->completedAnimationSequenceNamed(runningSequenceName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (_target && _animationCompleteCallbackFunc) {
|
|
|
|
(_target->*_animationCompleteCallbackFunc)();
|
2012-11-01 02:07:33 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-07-27 22:31:57 +08:00
|
|
|
_spriteFrame = pSpriteFrame;
|
|
|
|
CC_SAFE_RETAIN(_spriteFrame);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBSetSpriteFrame::~CCBSetSpriteFrame()
|
|
|
|
{
|
2013-07-27 22:31:57 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_spriteFrame);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBSetSpriteFrame* CCBSetSpriteFrame::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBSetSpriteFrame();
|
2013-07-27 22:31:57 +08:00
|
|
|
a->initWithSpriteFrame(_spriteFrame);
|
2013-06-19 06:06:53 +08:00
|
|
|
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-07-27 22:31:57 +08:00
|
|
|
((Sprite*)_target)->setDisplayFrame(_spriteFrame);
|
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) {
|
2013-07-27 22:31:57 +08:00
|
|
|
_soundFile = filename;
|
|
|
|
_pitch = pitch;
|
|
|
|
_pan = pan;
|
|
|
|
_gain = gain;
|
2013-03-15 08:43:56 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBSoundEffect* CCBSoundEffect::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBSoundEffect();
|
2013-07-27 22:31:57 +08:00
|
|
|
a->initWithSoundFile(_soundFile, _pitch, _pan, _gain);
|
2013-06-19 06:06:53 +08:00
|
|
|
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-27 22:31:57 +08:00
|
|
|
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(_soundFile.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
|
|
|
{
|
2013-07-27 22:31:57 +08:00
|
|
|
_dstAngle = fAngle;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBRotateTo* CCBRotateTo::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBRotateTo();
|
2013-07-27 22:31:57 +08:00
|
|
|
a->initWithDuration(_duration, _dstAngle);
|
2013-06-19 06:06:53 +08:00
|
|
|
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-07-27 22:31:57 +08:00
|
|
|
_startAngle = _target->getRotation();
|
|
|
|
_diffAngle = _dstAngle - _startAngle;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCBRotateTo::update(float time)
|
|
|
|
{
|
2013-07-27 22:31:57 +08:00
|
|
|
_target->setRotation(_startAngle + (_diffAngle * 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
|
|
|
{
|
2013-07-27 22:31:57 +08:00
|
|
|
_dstAngle = fAngle;
|
2013-03-20 14:25:30 +08:00
|
|
|
|
|
|
|
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;
|
2013-07-27 22:31:57 +08:00
|
|
|
_startAngle = _target->getRotationX();
|
|
|
|
_diffAngle = _dstAngle - _startAngle;
|
2013-03-20 06:13:00 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBRotateXTo* CCBRotateXTo::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBRotateXTo();
|
2013-07-27 22:31:57 +08:00
|
|
|
a->initWithDuration(_duration, _dstAngle);
|
2013-06-19 06:06:53 +08:00
|
|
|
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-07-27 22:31:57 +08:00
|
|
|
_target->setRotationX(_startAngle + (_diffAngle * 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
|
|
|
{
|
2013-07-27 22:31:57 +08:00
|
|
|
_dstAngle = fAngle;
|
2013-03-20 14:25:30 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
CCBRotateYTo* CCBRotateYTo::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new CCBRotateYTo();
|
2013-07-27 22:31:57 +08:00
|
|
|
a->initWithDuration(_duration, _dstAngle);
|
2013-06-19 06:06:53 +08:00
|
|
|
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;
|
2013-07-27 22:31:57 +08:00
|
|
|
_startAngle = _target->getRotationY();
|
|
|
|
_diffAngle = _dstAngle - _startAngle;
|
2013-03-20 06:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCBRotateYTo::update(float time)
|
|
|
|
{
|
2013-07-27 22:31:57 +08:00
|
|
|
_target->setRotationY(_startAngle + (_diffAngle * 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
|