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"
|
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
|
|
|
|
2014-04-09 22:46:41 +08:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <set>
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
using namespace cocos2d;
|
|
|
|
using namespace std;
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d::extension;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocosbuilder {
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// Implementation of CCBAinmationManager
|
|
|
|
|
|
|
|
CCBAnimationManager::CCBAnimationManager()
|
2013-07-29 14:07:57 +08:00
|
|
|
: _jsControlled(false)
|
2013-12-17 14:19:35 +08:00
|
|
|
, _owner(nullptr)
|
2013-07-27 21:44:49 +08:00
|
|
|
, _autoPlaySequenceId(0)
|
2013-12-17 14:19:35 +08:00
|
|
|
, _rootNode(nullptr)
|
2013-07-27 21:44:49 +08:00
|
|
|
, _rootContainerSize(Size::ZERO)
|
2013-12-17 14:19:35 +08:00
|
|
|
, _delegate(nullptr)
|
|
|
|
, _runningSequence(nullptr)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCBAnimationManager::init()
|
|
|
|
{
|
2013-12-17 14:19:35 +08:00
|
|
|
_target = nullptr;
|
|
|
|
_animationCompleteCallbackFunc = nullptr;
|
2012-11-01 02:07:33 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBAnimationManager::~CCBAnimationManager()
|
|
|
|
{
|
2013-12-17 14:19:35 +08:00
|
|
|
// DictElement *pElement = nullptr;
|
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();
|
|
|
|
// }
|
2013-12-10 13:41:51 +08:00
|
|
|
if (_rootNode)
|
|
|
|
{
|
|
|
|
_rootNode->stopAllActions();
|
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-12-17 14:19:35 +08:00
|
|
|
setRootNode(nullptr);
|
|
|
|
setDelegate(nullptr);
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
for (auto iter = _objects.begin(); iter != _objects.end(); ++iter)
|
|
|
|
{
|
|
|
|
for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2)
|
|
|
|
{
|
|
|
|
iter2->second->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
CC_SAFE_RELEASE(_target);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
Vector<CCBSequence*>& 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-12-09 11:45:46 +08:00
|
|
|
void CCBAnimationManager::setSequences(const Vector<CCBSequence*>& 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
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-09 11:45:46 +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-12-09 11:45:46 +08:00
|
|
|
void CCBAnimationManager::addDocumentCallbackNode(Node *node)
|
|
|
|
{
|
|
|
|
_documentCallbackNodes.pushBack(node);
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
void CCBAnimationManager::addDocumentCallbackName(std::string name)
|
|
|
|
{
|
|
|
|
_documentCallbackNames.push_back(Value(name));
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-08-12 11:18:07 +08:00
|
|
|
void CCBAnimationManager::addDocumentCallbackControlEvents(Control::EventType eventType)
|
|
|
|
{
|
2013-12-09 11:45:46 +08:00
|
|
|
_documentCallbackControlEvents.push_back(Value(static_cast<int>(eventType)));
|
2013-08-12 11:18:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
ValueVector& CCBAnimationManager::getDocumentCallbackNames()
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _documentCallbackNames;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
Vector<Node*>& CCBAnimationManager::getDocumentCallbackNodes()
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _documentCallbackNodes;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
ValueVector& CCBAnimationManager::getDocumentCallbackControlEvents()
|
2013-08-12 11:18:07 +08:00
|
|
|
{
|
|
|
|
return _documentCallbackControlEvents;
|
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
void CCBAnimationManager::addDocumentOutletNode(Node *node)
|
|
|
|
{
|
|
|
|
_documentOutletNodes.pushBack(node);
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
void CCBAnimationManager::addDocumentOutletName(std::string name)
|
|
|
|
{
|
|
|
|
_documentOutletNames.push_back(Value(name));
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
ValueVector& CCBAnimationManager::getDocumentOutletNames()
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _documentOutletNames;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
Vector<Node*>& CCBAnimationManager::getDocumentOutletNodes()
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return _documentOutletNodes;
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:45:46 +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-12-09 11:45:46 +08:00
|
|
|
ValueVector& 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)
|
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
CC_SAFE_RELEASE(dynamic_cast<Ref*>(_delegate));
|
2013-07-27 21:44:49 +08:00
|
|
|
_delegate = pDelegate;
|
2014-02-20 10:53:49 +08:00
|
|
|
CC_SAFE_RETAIN(dynamic_cast<Ref*>(_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
|
|
|
}
|
2013-12-17 14:19:35 +08:00
|
|
|
return nullptr;
|
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-12-09 17:45:24 +08:00
|
|
|
void CCBAnimationManager::addNode(Node *pNode, const std::unordered_map<int, Map<std::string, CCBSequenceProperty*>>& seq)
|
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-12-09 17:45:24 +08:00
|
|
|
_nodeSequences[pNode] = seq;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
void CCBAnimationManager::setBaseValue(const Value& value, Node *pNode, const std::string& propName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& props = _baseValues[pNode];
|
|
|
|
props[propName] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value& CCBAnimationManager::getBaseValue(Node *pNode, const std::string& propName)
|
|
|
|
{
|
|
|
|
auto& props = _baseValues[pNode];
|
|
|
|
return props[propName];
|
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void CCBAnimationManager::setObject(Ref* obj, Node *pNode, const std::string& propName)
|
2013-12-09 17:45:24 +08:00
|
|
|
{
|
|
|
|
auto& props = _objects[pNode];
|
|
|
|
auto iter = props.find(propName);
|
|
|
|
if (iter != props.end())
|
|
|
|
iter->second->release();
|
|
|
|
|
|
|
|
props[propName] = obj;
|
|
|
|
obj->retain();
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* CCBAnimationManager::getObject(Node *pNode, const std::string& propName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& props = _objects[pNode];
|
|
|
|
auto iter = props.find(propName);
|
|
|
|
if (iter != props.end())
|
|
|
|
return iter->second;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
return nullptr;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int CCBAnimationManager::getSequenceId(const char* pSequenceName)
|
|
|
|
{
|
|
|
|
string seqName(pSequenceName);
|
2013-12-09 11:45:46 +08:00
|
|
|
for (auto& seq : _sequences)
|
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-12-09 11:45:46 +08:00
|
|
|
for (auto& seq : _sequences)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
if (seq->getSequenceId() == nSequenceId)
|
|
|
|
{
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
}
|
2013-12-17 14:19:35 +08:00
|
|
|
return nullptr;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
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-12-09 17:45:24 +08:00
|
|
|
void CCBAnimationManager::moveAnimationsFromNode(Node* fromNode, Node* toNode)
|
|
|
|
{
|
2012-11-01 02:07:33 +08:00
|
|
|
// Move base values
|
2013-12-09 17:45:24 +08:00
|
|
|
auto baseValueIter = _baseValues.find(fromNode);
|
|
|
|
if(baseValueIter != _baseValues.end())
|
|
|
|
{
|
|
|
|
_baseValues[toNode] = baseValueIter->second;
|
2014-03-20 17:43:44 +08:00
|
|
|
_baseValues.erase(baseValueIter);
|
2013-01-23 15:14:40 +08:00
|
|
|
// fromNode->release();
|
|
|
|
// toNode->retain();
|
2012-11-01 02:07:33 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
auto objIter = _objects.find(fromNode);
|
|
|
|
if (objIter != _objects.end())
|
|
|
|
{
|
|
|
|
_objects[toNode] = objIter->second;
|
2014-03-20 17:43:44 +08:00
|
|
|
_objects.erase(objIter);
|
2013-12-09 17:45:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-01 02:07:33 +08:00
|
|
|
// Move seqs
|
2013-12-09 17:45:24 +08:00
|
|
|
auto seqsIter = _nodeSequences.find(fromNode);
|
|
|
|
if (seqsIter != _nodeSequences.end())
|
|
|
|
{
|
|
|
|
_nodeSequences[toNode] = seqsIter->second;
|
2014-03-20 17:43:44 +08:00
|
|
|
_nodeSequences.erase(seqsIter);
|
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-12-09 17:45:24 +08:00
|
|
|
ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const std::string& 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-12-09 17:45:24 +08:00
|
|
|
if (propName == "rotationX")
|
2013-03-20 06:13:00 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
return CCBRotateXTo::create(duration, pKeyframe1->getValue().asFloat());
|
2013-03-20 06:13:00 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "rotationY")
|
2013-03-20 06:13:00 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
return CCBRotateYTo::create(duration, pKeyframe1->getValue().asFloat());
|
2013-03-20 06:13:00 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "rotation")
|
2013-03-20 14:25:30 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
return CCBRotateTo::create(duration, pKeyframe1->getValue().asFloat());
|
2013-03-20 14:25:30 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "opacity")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
return FadeTo::create(duration, pKeyframe1->getValue().asByte());
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "color")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
auto c = pKeyframe1->getValue().asValueMap();
|
|
|
|
unsigned char r = c["r"].asByte();
|
|
|
|
unsigned char g = c["g"].asByte();
|
|
|
|
unsigned char b = c["b"].asByte();
|
|
|
|
return TintTo::create(duration, r, g, b);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "visible")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
if (pKeyframe1->getValue().asBool())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
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-12-09 17:45:24 +08:00
|
|
|
else if (propName == "displayFrame")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
return Sequence::createWithTwoActions(DelayTime::create(duration),
|
2013-12-09 17:45:24 +08:00
|
|
|
CCBSetSpriteFrame::create(static_cast<SpriteFrame*>(pKeyframe1->getObject())));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "position")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Get position type
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& array = getBaseValue(pNode, propName).asValueVector();
|
|
|
|
CCBReader::PositionType type = (CCBReader::PositionType)array[2].asInt();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// Get relative position
|
2013-12-09 17:45:24 +08:00
|
|
|
auto value = pKeyframe1->getValue().asValueVector();
|
|
|
|
float x = value[0].asFloat();
|
|
|
|
float y = value[1].asFloat();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
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-12-09 17:45:24 +08:00
|
|
|
else if (propName == "scale")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Get position type
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& array = getBaseValue(pNode, propName).asValueVector();
|
|
|
|
CCBReader::ScaleType type = (CCBReader::ScaleType)array[2].asInt();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// Get relative scale
|
2013-12-09 17:45:24 +08:00
|
|
|
auto value = pKeyframe1->getValue().asValueVector();
|
|
|
|
float x = value[0].asFloat();
|
|
|
|
float y = value[1].asFloat();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
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-12-09 17:45:24 +08:00
|
|
|
else if (propName == "skew")
|
2013-03-15 08:43:56 +08:00
|
|
|
{
|
|
|
|
// Get relative skew
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& value = pKeyframe1->getValue().asValueVector();
|
|
|
|
float x = value[0].asFloat();
|
|
|
|
float y = value[1].asFloat();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
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-12-09 17:45:24 +08:00
|
|
|
log("CCBReader: Failed to create animation for property: %s", propName.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-12-17 14:19:35 +08:00
|
|
|
return nullptr;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void CCBAnimationManager::setAnimatedProperty(const std::string& propName, Node *pNode, const Value& value, Ref* obj, 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();
|
2013-12-09 17:45:24 +08:00
|
|
|
|
|
|
|
kf1->setObject(obj);
|
|
|
|
kf1->setValue(value);
|
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-12-17 14:19:35 +08:00
|
|
|
ActionInterval *tweenAction = getAction(nullptr, kf1, propName, pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
pNode->runAction(tweenAction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just set the value
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
if (propName == "position")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Get position type
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& array = getBaseValue(pNode, propName).asValueVector();
|
|
|
|
CCBReader::PositionType type = (CCBReader::PositionType)array[2].asInt();
|
2012-09-17 14:27:17 +08:00
|
|
|
// Get relative position
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& valueVector = value.asValueVector();
|
|
|
|
float x = valueVector[0].asFloat();
|
|
|
|
float y = valueVector[1].asFloat();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
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-12-09 17:45:24 +08:00
|
|
|
else if (propName == "scale")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-09-18 17:04:10 +08:00
|
|
|
// Get scale type
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& array = getBaseValue(pNode, propName).asValueVector();
|
|
|
|
CCBReader::ScaleType type = (CCBReader::ScaleType)array[2].asInt();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// Get relative scale
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& valueVector = value.asValueVector();
|
|
|
|
float x = valueVector[0].asFloat();
|
|
|
|
float y = valueVector[1].asFloat();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
setRelativeScale(pNode, x, y, type, propName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if(propName == "skew")
|
2013-03-19 16:33:23 +08:00
|
|
|
{
|
2013-03-15 08:43:56 +08:00
|
|
|
// Get relative scale
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& valueVector = value.asValueVector();
|
|
|
|
float x = valueVector[0].asFloat();
|
|
|
|
float y = valueVector[1].asFloat();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
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-12-09 17:45:24 +08:00
|
|
|
if (propName == "rotation")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
float rotate = value.asFloat();
|
2012-09-17 14:27:17 +08:00
|
|
|
pNode->setRotation(rotate);
|
2013-12-09 17:45:24 +08:00
|
|
|
} else if(propName == "rotationX")
|
2013-03-20 14:25:30 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
float rotate = value.asFloat();
|
2014-03-14 15:38:43 +08:00
|
|
|
pNode->setRotationSkewX(rotate);
|
2013-12-09 17:45:24 +08:00
|
|
|
}else if(propName == "rotationY")
|
2013-03-20 14:25:30 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
float rotate = value.asFloat();
|
2014-03-14 15:38:43 +08:00
|
|
|
pNode->setRotationSkewY(rotate);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "opacity")
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
unsigned char opacity = value.asByte();
|
2013-12-06 18:07:16 +08:00
|
|
|
pNode->setOpacity(opacity);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "displayFrame")
|
2012-09-17 18:49:05 +08:00
|
|
|
{
|
2014-01-04 09:17:37 +08:00
|
|
|
static_cast<Sprite*>(pNode)->setSpriteFrame(static_cast<SpriteFrame*>(obj));
|
2012-09-17 18:49:05 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "color")
|
2012-09-17 18:49:05 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
auto c = value.asValueMap();
|
|
|
|
unsigned char r = c["r"].asByte();
|
|
|
|
unsigned char g = c["g"].asByte();
|
|
|
|
unsigned char b = c["b"].asByte();
|
2013-12-10 18:03:41 +08:00
|
|
|
pNode->setColor(Color3B(r, g, b));
|
2012-09-17 18:49:05 +08:00
|
|
|
}
|
2013-12-09 17:45:24 +08:00
|
|
|
else if (propName == "visible")
|
2012-11-01 02:07:33 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
bool visible = value.asBool();
|
2013-01-05 18:35:11 +08:00
|
|
|
pNode->setVisible(visible);
|
2012-11-01 02:07:33 +08:00
|
|
|
}
|
|
|
|
else
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
log("unsupported property name is %s", propName.c_str());
|
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-12-08 22:17:54 +08:00
|
|
|
auto& keyframes = pSeqProp->getKeyframes();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-12-08 22:17:54 +08:00
|
|
|
if (keyframes.empty())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Use base value (no animation)
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& baseValue = getBaseValue(pNode, pSeqProp->getName());
|
|
|
|
auto obj = getObject(pNode, pSeqProp->getName());
|
|
|
|
CCASSERT(!baseValue.isNull(), "No baseValue found for property");
|
|
|
|
setAnimatedProperty(pSeqProp->getName(), pNode, baseValue, obj, fTweenDuration);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use first keyframe
|
2013-12-08 22:17:54 +08:00
|
|
|
CCBKeyframe *keyframe = keyframes.at(0);
|
2013-12-09 17:45:24 +08:00
|
|
|
setAnimatedProperty(pSeqProp->getName(), pNode, keyframe->getValue(), keyframe->getObject(), fTweenDuration);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
Sequence* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* channel) {
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
float lastKeyframeTime = 0;
|
|
|
|
|
2013-11-28 11:04:39 +08:00
|
|
|
Vector<FiniteTimeAction*> actions;
|
2013-12-08 22:17:54 +08:00
|
|
|
auto& keyframes = channel->getKeyframes();
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t numKeyframes = keyframes.size();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-11-18 14:12:07 +08:00
|
|
|
for (long i = 0; i < numKeyframes; ++i)
|
2013-07-27 21:44:49 +08:00
|
|
|
{
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-12-08 22:17:54 +08:00
|
|
|
CCBKeyframe *keyframe = keyframes.at(i);
|
2013-03-15 08:43:56 +08:00
|
|
|
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-12-05 10:35:10 +08:00
|
|
|
actions.pushBack(DelayTime::create(timeSinceLastKeyframe));
|
2013-03-19 06:41:47 +08:00
|
|
|
}
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& keyVal = keyframe->getValue().asValueVector();
|
|
|
|
std::string selectorName = keyVal[0].asString();
|
|
|
|
CCBReader::TargetType selectorTarget = (CCBReader::TargetType)keyVal[1].asInt();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(_jsControlled) {
|
2013-12-09 18:17:04 +08:00
|
|
|
std::stringstream callbackName;
|
|
|
|
callbackName << static_cast<int>(selectorTarget);
|
|
|
|
callbackName << ":" + selectorName;
|
|
|
|
|
|
|
|
auto callback = _keyframeCallFuncs.at(callbackName.str());
|
2013-11-18 14:12:07 +08:00
|
|
|
if (nullptr != callback)
|
|
|
|
{
|
2013-12-09 18:17:04 +08:00
|
|
|
CallFunc* callbackClone = callback->clone();
|
2013-11-18 14:12:07 +08:00
|
|
|
|
2013-12-17 14:19:35 +08:00
|
|
|
if (callbackClone != nullptr)
|
2013-12-09 18:17:04 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
actions.pushBack(callbackClone);
|
2013-11-18 14:12:07 +08:00
|
|
|
}
|
2013-03-19 06:41:47 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* target = nullptr;
|
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
|
|
|
|
2013-12-17 14:19:35 +08:00
|
|
|
if(target != nullptr)
|
2013-07-27 21:44:49 +08:00
|
|
|
{
|
|
|
|
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-12-17 14:19:35 +08:00
|
|
|
if(targetAsCCBSelectorResolver != nullptr)
|
2013-07-27 21:44:49 +08:00
|
|
|
{
|
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
|
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
auto savedTarget = std::make_shared<Vector<Ref*>>();
|
2013-12-10 20:33:21 +08:00
|
|
|
savedTarget->pushBack(target);
|
|
|
|
|
|
|
|
auto callback = CallFuncN::create([savedTarget, selCallFunc](Node* sender){
|
|
|
|
auto t = savedTarget->at(0);
|
|
|
|
(t->*selCallFunc)(sender);
|
|
|
|
});
|
|
|
|
|
2013-12-05 10:35:10 +08:00
|
|
|
actions.pushBack(callback);
|
2013-03-19 06:41:47 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-19 06:41:47 +08:00
|
|
|
CCLOG("Unexpected empty selector.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-17 14:19:35 +08:00
|
|
|
if(actions.size() < 1) return nullptr;
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
return Sequence::create(actions);
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
Sequence* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel) {
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
float lastKeyframeTime = 0;
|
|
|
|
|
2013-11-28 11:04:39 +08:00
|
|
|
Vector<FiniteTimeAction*> actions;
|
2013-12-08 22:17:54 +08:00
|
|
|
auto& keyframes = channel->getKeyframes();
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t numKeyframes = keyframes.size();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-12-08 22:17:54 +08:00
|
|
|
for (int i = 0; i < numKeyframes; ++i)
|
|
|
|
{
|
|
|
|
CCBKeyframe *keyframe = keyframes.at(i);
|
2013-03-15 08:43:56 +08:00
|
|
|
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-12-05 10:35:10 +08:00
|
|
|
actions.pushBack(DelayTime::create(timeSinceLastKeyframe));
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stringstream ss (stringstream::in | stringstream::out);
|
2013-12-09 17:45:24 +08:00
|
|
|
auto& keyVal = keyframe->getValue().asValueVector();
|
|
|
|
std::string soundFile = keyVal[0].asString();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
float pitch, pan, gain;
|
2013-12-09 17:45:24 +08:00
|
|
|
ss << keyVal[1].asString();
|
2013-03-15 08:43:56 +08:00
|
|
|
ss >> pitch;
|
|
|
|
ss.flush();
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
ss << keyVal[2].asString();
|
2013-03-15 08:43:56 +08:00
|
|
|
ss >> pan;
|
|
|
|
ss.flush();
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
ss << keyVal[3].asString();
|
2013-03-15 08:43:56 +08:00
|
|
|
ss >> gain;
|
|
|
|
ss.flush();
|
|
|
|
|
2013-12-05 10:35:10 +08:00
|
|
|
actions.pushBack(CCBSoundEffect::actionWithSoundFile(soundFile, pitch, pan, gain));
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
2013-12-17 14:19:35 +08:00
|
|
|
if(actions.size() < 1) return nullptr;
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-11-28 11:04:39 +08:00
|
|
|
return 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-12-08 22:17:54 +08:00
|
|
|
auto& keyframes = pSeqProp->getKeyframes();
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t numKeyframes = keyframes.size();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
if (numKeyframes > 1)
|
|
|
|
{
|
|
|
|
// Make an animation!
|
2013-11-28 11:04:39 +08:00
|
|
|
Vector<FiniteTimeAction*> actions;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-12-08 22:17:54 +08:00
|
|
|
CCBKeyframe *keyframeFirst = keyframes.at(0);
|
2012-09-17 14:27:17 +08:00
|
|
|
float timeFirst = keyframeFirst->getTime() + fTweenDuration;
|
|
|
|
|
|
|
|
if (timeFirst > 0)
|
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
actions.pushBack(DelayTime::create(timeFirst));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
for (ssize_t i = 0; i < numKeyframes - 1; ++i)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-08 22:17:54 +08:00
|
|
|
CCBKeyframe *kf0 = keyframes.at(i);
|
|
|
|
CCBKeyframe *kf1 = keyframes.at(i+1);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
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());
|
|
|
|
|
2013-12-05 10:35:10 +08:00
|
|
|
actions.pushBack(action);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 11:04:39 +08:00
|
|
|
auto 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-12-09 17:45:24 +08:00
|
|
|
for (auto nodeSeqIter = _nodeSequences.begin(); nodeSeqIter != _nodeSequences.end(); ++nodeSeqIter)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
Node *node = nodeSeqIter->first;
|
2012-09-17 14:27:17 +08:00
|
|
|
node->stopAllActions();
|
|
|
|
|
|
|
|
// Refer to CCBReader::readKeyframe() for the real type of value
|
2013-12-09 17:45:24 +08:00
|
|
|
auto seqs = nodeSeqIter->second;
|
|
|
|
auto seqNodeProps = seqs[nSeqId];
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
std::set<std::string> seqNodePropNames;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
if (!seqNodeProps.empty())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Reset nodes that have sequence node properties, and run actions on them
|
2013-12-09 17:45:24 +08:00
|
|
|
for (auto iter = seqNodeProps.begin(); iter != seqNodeProps.end(); ++iter)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
const std::string propName = iter->first;
|
|
|
|
CCBSequenceProperty *seqProp = iter->second;
|
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-12-09 17:45:24 +08:00
|
|
|
auto& nodeBaseValues = _baseValues[node];
|
|
|
|
|
|
|
|
if (!nodeBaseValues.empty())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
for (auto iter = nodeBaseValues.begin(); iter != nodeBaseValues.end(); ++iter)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
if (seqNodePropNames.find(iter->first) == seqNodePropNames.end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
setAnimatedProperty(iter->first, node, iter->second, nullptr, fTweenDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& nodeObject = _objects[node];
|
|
|
|
|
|
|
|
if (!nodeObject.empty())
|
|
|
|
{
|
|
|
|
for (auto iter = nodeObject.begin(); iter != nodeObject.end(); ++iter)
|
|
|
|
{
|
|
|
|
if (seqNodePropNames.find(iter->first) == seqNodePropNames.end())
|
|
|
|
{
|
|
|
|
setAnimatedProperty(iter->first, node, Value(), iter->second, 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
|
|
|
|
2013-12-17 14:19:35 +08:00
|
|
|
if(seq->getCallbackChannel() != nullptr) {
|
2013-06-20 14:15:53 +08:00
|
|
|
Action* action = (Action *)actionForCallbackChannel(seq->getCallbackChannel());
|
2013-12-17 14:19:35 +08:00
|
|
|
if(action != nullptr) {
|
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
|
|
|
}
|
|
|
|
|
2013-12-17 14:19:35 +08:00
|
|
|
if(seq->getSoundChannel() != nullptr) {
|
2013-06-20 14:15:53 +08:00
|
|
|
Action* action = (Action *)actionForSoundChannel(seq->getSoundChannel());
|
2013-12-17 14:19:35 +08:00
|
|
|
if(action != nullptr) {
|
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()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void CCBAnimationManager::setAnimationCompletedCallback(Ref *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-12-09 18:17:04 +08:00
|
|
|
void CCBAnimationManager::setCallFunc(CallFunc* callFunc, const std::string &callbackNamed)
|
|
|
|
{
|
|
|
|
_keyframeCallFuncs.insert(callbackNamed, callFunc);
|
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();
|
2013-12-17 14:19:35 +08:00
|
|
|
_runningSequence = nullptr;
|
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-10-22 15:56:35 +08:00
|
|
|
if (nextSeqId != -1)
|
|
|
|
{
|
|
|
|
runAnimationsForSequenceIdTweenDuration(nextSeqId, 0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-01-04 09:17:37 +08:00
|
|
|
static_cast<Sprite*>(_target)->setSpriteFrame(_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();
|
2013-12-17 14:19:35 +08:00
|
|
|
if (pRet != nullptr && pRet->initWithSoundFile(filename, pitch, pan, gain))
|
2013-03-15 08:43:56 +08:00
|
|
|
{
|
|
|
|
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;
|
2014-03-14 15:38:43 +08:00
|
|
|
_startAngle = _target->getRotationSkewX();
|
2013-07-27 22:31:57 +08:00
|
|
|
_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)
|
|
|
|
{
|
2014-03-14 15:38:43 +08:00
|
|
|
_target->setRotationSkewX(_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;
|
2014-03-14 15:38:43 +08:00
|
|
|
_startAngle = _target->getRotationSkewY();
|
2013-07-27 22:31:57 +08:00
|
|
|
_diffAngle = _dstAngle - _startAngle;
|
2013-03-20 06:13:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCBRotateYTo::update(float time)
|
|
|
|
{
|
2014-03-14 15:38:43 +08:00
|
|
|
_target->setRotationSkewY(_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|