mirror of https://github.com/axmolengine/axmol.git
Merge pull request #7352 from super626/v3
adjust api according feedback
This commit is contained in:
commit
345fb040e7
|
@ -66,12 +66,12 @@ Animate3D* Animate3D::clone() const
|
||||||
auto animate = const_cast<Animate3D*>(this);
|
auto animate = const_cast<Animate3D*>(this);
|
||||||
auto copy = Animate3D::create(animate->_animation);
|
auto copy = Animate3D::create(animate->_animation);
|
||||||
|
|
||||||
copy->_speed = _speed;
|
copy->_absSpeed = _absSpeed;
|
||||||
copy->_weight = _weight;
|
copy->_weight = _weight;
|
||||||
copy->_elapsed = _elapsed;
|
copy->_elapsed = _elapsed;
|
||||||
copy->_start = _start;
|
copy->_start = _start;
|
||||||
copy->_last = _last;
|
copy->_last = _last;
|
||||||
copy->_playBack = _playBack;
|
copy->_playReverse = _playReverse;
|
||||||
copy->setDuration(animate->getDuration());
|
copy->setDuration(animate->getDuration());
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
|
@ -81,7 +81,7 @@ Animate3D* Animate3D::clone() const
|
||||||
Animate3D* Animate3D::reverse() const
|
Animate3D* Animate3D::reverse() const
|
||||||
{
|
{
|
||||||
auto animate = clone();
|
auto animate = clone();
|
||||||
animate->_playBack = !animate->_playBack;
|
animate->_playReverse = !animate->_playReverse;
|
||||||
return animate;
|
return animate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,16 +112,16 @@ void Animate3D::startWithTarget(Node *target)
|
||||||
//! called every frame with it's delta time. DON'T override unless you know what you are doing.
|
//! called every frame with it's delta time. DON'T override unless you know what you are doing.
|
||||||
void Animate3D::step(float dt)
|
void Animate3D::step(float dt)
|
||||||
{
|
{
|
||||||
ActionInterval::step(dt * _speed);
|
ActionInterval::step(dt * _absSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animate3D::update(float t)
|
void Animate3D::update(float t)
|
||||||
{
|
{
|
||||||
if (_target)
|
if (_target && _weight > 0.f)
|
||||||
{
|
{
|
||||||
float transDst[3], rotDst[4], scaleDst[3];
|
float transDst[3], rotDst[4], scaleDst[3];
|
||||||
float* trans = nullptr, *rot = nullptr, *scale = nullptr;
|
float* trans = nullptr, *rot = nullptr, *scale = nullptr;
|
||||||
if (_playBack)
|
if (_playReverse)
|
||||||
t = 1 - t;
|
t = 1 - t;
|
||||||
|
|
||||||
t = _start + t * _last;
|
t = _start + t * _last;
|
||||||
|
@ -149,13 +149,29 @@ void Animate3D::update(float t)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Animate3D::getSpeed() const
|
||||||
|
{
|
||||||
|
return _playReverse ? -_absSpeed : _absSpeed;
|
||||||
|
}
|
||||||
|
void Animate3D::setSpeed(float speed)
|
||||||
|
{
|
||||||
|
_absSpeed = fabsf(speed);
|
||||||
|
_playReverse = speed < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Animate3D::setWeight(float weight)
|
||||||
|
{
|
||||||
|
CCASSERT(weight >= 0.0f, "invalid weight");
|
||||||
|
_weight = fabsf(weight);
|
||||||
|
}
|
||||||
|
|
||||||
Animate3D::Animate3D()
|
Animate3D::Animate3D()
|
||||||
: _speed(1)
|
: _absSpeed(1.f)
|
||||||
, _weight(1.f)
|
, _weight(1.f)
|
||||||
, _start(0.f)
|
, _start(0.f)
|
||||||
, _last(1.f)
|
, _last(1.f)
|
||||||
, _animation(nullptr)
|
, _animation(nullptr)
|
||||||
, _playBack(false)
|
, _playReverse(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "base/ccMacros.h"
|
#include "base/ccMacros.h"
|
||||||
#include "base/CCRef.h"
|
#include "base/CCRef.h"
|
||||||
#include "base/ccTypes.h"
|
#include "base/ccTypes.h"
|
||||||
|
#include "base/CCPlatformMacros.h"
|
||||||
#include "2d/CCActionInterval.h"
|
#include "2d/CCActionInterval.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -66,17 +67,17 @@ public:
|
||||||
|
|
||||||
virtual void update(float t) override;
|
virtual void update(float t) override;
|
||||||
|
|
||||||
/**get & set speed */
|
/**get & set speed, negative speed means playing reverse */
|
||||||
float getSpeed() const { return _speed; }
|
float getSpeed() const;
|
||||||
void setSpeed(float speed) { _speed = speed; }
|
void setSpeed(float speed);
|
||||||
|
|
||||||
/**get & set blend weight*/
|
/**get & set blend weight, weight must positive*/
|
||||||
float getWeight() const { return _weight; }
|
float getWeight() const { return _weight; }
|
||||||
void setWeight(float weight) { _weight = weight; }
|
void setWeight(float weight);
|
||||||
|
|
||||||
/**get & set play back*/
|
/**get & set play reverse*/
|
||||||
bool getPlayBack() const { return _playBack; }
|
CC_DEPRECATED_ATTRIBUTE bool getPlayBack() const { return _playReverse; }
|
||||||
void setPlayBack(bool playBack) { _playBack = playBack; }
|
CC_DEPRECATED_ATTRIBUTE void setPlayBack(bool reverse) { _playReverse = reverse; }
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
|
|
||||||
|
@ -86,11 +87,11 @@ CC_CONSTRUCTOR_ACCESS:
|
||||||
protected:
|
protected:
|
||||||
Animation3D* _animation; //animation data
|
Animation3D* _animation; //animation data
|
||||||
|
|
||||||
float _speed; //playing speed
|
float _absSpeed; //playing speed
|
||||||
float _weight; //blend weight
|
float _weight; //blend weight
|
||||||
float _start; //start time 0 - 1, used to generate sub Animate3D
|
float _start; //start time 0 - 1, used to generate sub Animate3D
|
||||||
float _last; //last time 0 - 1, used to generate sub Animate3D
|
float _last; //last time 0 - 1, used to generate sub Animate3D
|
||||||
bool _playBack; // is playing back
|
bool _playReverse; // is playing reverse
|
||||||
std::map<Bone*, Animation3D::Curve*> _boneCurves; //weak ref
|
std::map<Bone*, Animation3D::Curve*> _boneCurves; //weak ref
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
Animation3D* Animation3D::getOrCreate(const std::string& fileName, const std::string& animationName)
|
Animation3D* Animation3D::create(const std::string& fileName, const std::string& animationName)
|
||||||
{
|
{
|
||||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
|
||||||
std::string key = fullPath + "#" + animationName;
|
std::string key = fullPath + "#" + animationName;
|
||||||
|
|
|
@ -59,8 +59,10 @@ public:
|
||||||
~Curve();
|
~Curve();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**read all animation or only the animation with given animationName? animationName == "" read all.*/
|
/**read all animation or only the animation with given animationName? animationName == "" read the first.*/
|
||||||
static Animation3D* getOrCreate(const std::string& filename, const std::string& animationName = "");
|
static Animation3D* create(const std::string& filename, const std::string& animationName = "");
|
||||||
|
|
||||||
|
CC_DEPRECATED_ATTRIBUTE static Animation3D* getOrCreate(const std::string& filename, const std::string& animationName = ""){ return create(filename, animationName); }
|
||||||
|
|
||||||
/**get duration*/
|
/**get duration*/
|
||||||
float getDuration() const { return _duration; }
|
float getDuration() const { return _duration; }
|
||||||
|
|
|
@ -342,7 +342,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||||
_meshCommand.setDepthTestEnabled(true);
|
_meshCommand.setDepthTestEnabled(true);
|
||||||
if (_skin)
|
if (_skin)
|
||||||
{
|
{
|
||||||
_meshCommand.setMatrixPaletteSize(_skin->getMatrixPaletteSize());
|
_meshCommand.setMatrixPaletteSize((int)_skin->getMatrixPaletteSize());
|
||||||
_meshCommand.setMatrixPalette(_skin->getMatrixPalette());
|
_meshCommand.setMatrixPalette(_skin->getMatrixPalette());
|
||||||
}
|
}
|
||||||
//support tint and fade
|
//support tint and fade
|
||||||
|
|
|
@ -546,24 +546,23 @@ void Sprite3DWithSkinTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
addChild(sprite);
|
addChild(sprite);
|
||||||
sprite->setPosition( Vec2( p.x, p.y) );
|
sprite->setPosition( Vec2( p.x, p.y) );
|
||||||
|
|
||||||
auto animation = Animation3D::getOrCreate(fileName);
|
auto animation = Animation3D::create(fileName);
|
||||||
if (animation)
|
if (animation)
|
||||||
{
|
{
|
||||||
auto animate = Animate3D::create(animation);
|
auto animate = Animate3D::create(animation);
|
||||||
if(std::rand() %3 == 0)
|
bool inverse = (std::rand() % 3 == 0);
|
||||||
{
|
|
||||||
animate->setPlayBack(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int rand2 = std::rand();
|
int rand2 = std::rand();
|
||||||
|
float speed = 1.0f;
|
||||||
if(rand2 % 3 == 1)
|
if(rand2 % 3 == 1)
|
||||||
{
|
{
|
||||||
animate->setSpeed(animate->getSpeed() + CCRANDOM_0_1());
|
speed = animate->getSpeed() + CCRANDOM_0_1();
|
||||||
}
|
}
|
||||||
else if(rand2 % 3 == 2)
|
else if(rand2 % 3 == 2)
|
||||||
{
|
{
|
||||||
animate->setSpeed(animate->getSpeed() - 0.5 * CCRANDOM_0_1());
|
speed = animate->getSpeed() - 0.5 * CCRANDOM_0_1();
|
||||||
}
|
}
|
||||||
|
animate->setSpeed(inverse ? -speed : speed);
|
||||||
|
|
||||||
sprite->runAction(RepeatForever::create(animate));
|
sprite->runAction(RepeatForever::create(animate));
|
||||||
}
|
}
|
||||||
|
@ -652,7 +651,7 @@ void Animate3DTest::addSprite3D()
|
||||||
sprite->setPosition(Vec2(s.width * 4.f / 5.f, s.height / 2.f));
|
sprite->setPosition(Vec2(s.width * 4.f / 5.f, s.height / 2.f));
|
||||||
addChild(sprite);
|
addChild(sprite);
|
||||||
_sprite = sprite;
|
_sprite = sprite;
|
||||||
auto animation = Animation3D::getOrCreate(fileName);
|
auto animation = Animation3D::create(fileName);
|
||||||
if (animation)
|
if (animation)
|
||||||
{
|
{
|
||||||
auto animate = Animate3D::create(animation, 0.f, 1.933f);
|
auto animate = Animate3D::create(animation, 0.f, 1.933f);
|
||||||
|
|
Loading…
Reference in New Issue