mirror of https://github.com/axmolengine/axmol.git
Merge pull request #8853 from 2youyouo2/v3_EventFrame
fixed emit frame event
This commit is contained in:
commit
49bd79d14a
|
@ -36,6 +36,7 @@ NS_TIMELINE_BEGIN
|
||||||
Frame::Frame()
|
Frame::Frame()
|
||||||
: _frameIndex(0)
|
: _frameIndex(0)
|
||||||
, _tween(true)
|
, _tween(true)
|
||||||
|
, _enterWhenPassed(false)
|
||||||
, _timeline(nullptr)
|
, _timeline(nullptr)
|
||||||
, _node(nullptr)
|
, _node(nullptr)
|
||||||
{
|
{
|
||||||
|
@ -554,6 +555,7 @@ EventFrame* EventFrame::create()
|
||||||
EventFrame* frame = new (std::nothrow) EventFrame();
|
EventFrame* frame = new (std::nothrow) EventFrame();
|
||||||
if (frame)
|
if (frame)
|
||||||
{
|
{
|
||||||
|
frame->init();
|
||||||
frame->autorelease();
|
frame->autorelease();
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
@ -561,6 +563,11 @@ EventFrame* EventFrame::create()
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EventFrame::init()
|
||||||
|
{
|
||||||
|
_enterWhenPassed = true;
|
||||||
|
}
|
||||||
|
|
||||||
EventFrame::EventFrame()
|
EventFrame::EventFrame()
|
||||||
: _event("")
|
: _event("")
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,6 +54,8 @@ public:
|
||||||
virtual void setTween(bool tween) { _tween = tween; }
|
virtual void setTween(bool tween) { _tween = tween; }
|
||||||
virtual bool isTween() const { return _tween; }
|
virtual bool isTween() const { return _tween; }
|
||||||
|
|
||||||
|
virtual bool isEnterWhenPassed() { return _enterWhenPassed; }
|
||||||
|
|
||||||
virtual void onEnter(Frame *nextFrame) = 0;
|
virtual void onEnter(Frame *nextFrame) = 0;
|
||||||
virtual void apply(float percent) {}
|
virtual void apply(float percent) {}
|
||||||
|
|
||||||
|
@ -68,6 +70,7 @@ protected:
|
||||||
|
|
||||||
unsigned int _frameIndex;
|
unsigned int _frameIndex;
|
||||||
bool _tween;
|
bool _tween;
|
||||||
|
bool _enterWhenPassed;
|
||||||
|
|
||||||
Timeline* _timeline;
|
Timeline* _timeline;
|
||||||
cocos2d::Node* _node;
|
cocos2d::Node* _node;
|
||||||
|
@ -300,6 +303,7 @@ class CC_STUDIO_DLL EventFrame : public Frame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static EventFrame* create();
|
static EventFrame* create();
|
||||||
|
void init();
|
||||||
|
|
||||||
EventFrame();
|
EventFrame();
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,13 @@ void Timeline::binarySearchKeyFrame(int frameIndex)
|
||||||
if(_currentKeyFrameIndex >= _frames.at(0)->getFrameIndex())
|
if(_currentKeyFrameIndex >= _frames.at(0)->getFrameIndex())
|
||||||
needEnterFrame = true;
|
needEnterFrame = true;
|
||||||
|
|
||||||
|
_fromIndex = 0;
|
||||||
|
|
||||||
|
if(length > 1)
|
||||||
|
_toIndex = 1;
|
||||||
|
else
|
||||||
|
_toIndex = 0;
|
||||||
|
|
||||||
from = to = _frames.at(0);
|
from = to = _frames.at(0);
|
||||||
_currentKeyFrameIndex = 0;
|
_currentKeyFrameIndex = 0;
|
||||||
_betweenDuration = _frames.at(0)->getFrameIndex();
|
_betweenDuration = _frames.at(0)->getFrameIndex();
|
||||||
|
@ -151,6 +158,9 @@ void Timeline::binarySearchKeyFrame(int frameIndex)
|
||||||
}
|
}
|
||||||
else if(frameIndex >= _frames.at(length - 1)->getFrameIndex())
|
else if(frameIndex >= _frames.at(length - 1)->getFrameIndex())
|
||||||
{
|
{
|
||||||
|
_fromIndex = (int)(length - 1);
|
||||||
|
_toIndex = 0;
|
||||||
|
|
||||||
from = to = _frames.at(length - 1);
|
from = to = _frames.at(length - 1);
|
||||||
_currentKeyFrameIndex = _frames.at(length - 1)->getFrameIndex();
|
_currentKeyFrameIndex = _frames.at(length - 1)->getFrameIndex();
|
||||||
_betweenDuration = 0;
|
_betweenDuration = 0;
|
||||||
|
@ -171,9 +181,16 @@ void Timeline::binarySearchKeyFrame(int frameIndex)
|
||||||
else
|
else
|
||||||
low=mid+1;
|
low=mid+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_fromIndex = (int)target;
|
||||||
|
|
||||||
from = _frames.at(target);
|
if(length > 1)
|
||||||
to = _frames.at(target+1);
|
_toIndex = (int)(target + 1);
|
||||||
|
else
|
||||||
|
_toIndex = (int)target;
|
||||||
|
|
||||||
|
from = _frames.at(_fromIndex);
|
||||||
|
to = _frames.at(_toIndex);
|
||||||
|
|
||||||
if(target == 0 && _currentKeyFrameIndex<from->getFrameIndex())
|
if(target == 0 && _currentKeyFrameIndex<from->getFrameIndex())
|
||||||
needEnterFrame = true;
|
needEnterFrame = true;
|
||||||
|
@ -191,6 +208,8 @@ void Timeline::binarySearchKeyFrame(int frameIndex)
|
||||||
|
|
||||||
void Timeline::updateCurrentKeyFrame(int frameIndex)
|
void Timeline::updateCurrentKeyFrame(int frameIndex)
|
||||||
{
|
{
|
||||||
|
if(frameIndex > 60)
|
||||||
|
int a = 0;
|
||||||
//! If play to current frame's front or back, then find current frame again
|
//! If play to current frame's front or back, then find current frame again
|
||||||
if (frameIndex < _currentKeyFrameIndex || frameIndex >= _currentKeyFrameIndex + _betweenDuration)
|
if (frameIndex < _currentKeyFrameIndex || frameIndex >= _currentKeyFrameIndex + _betweenDuration)
|
||||||
{
|
{
|
||||||
|
@ -210,10 +229,10 @@ void Timeline::updateCurrentKeyFrame(int frameIndex)
|
||||||
}
|
}
|
||||||
else if(frameIndex >= _frames.at(length - 1)->getFrameIndex())
|
else if(frameIndex >= _frames.at(length - 1)->getFrameIndex())
|
||||||
{
|
{
|
||||||
from = to = _frames.at(length - 1);
|
int lastFrameIndex = _frames.at(length - 1)->getFrameIndex();
|
||||||
_currentKeyFrameIndex = _frames.at(length - 1)->getFrameIndex();
|
if(_currentKeyFrameIndex >= lastFrameIndex)
|
||||||
_betweenDuration = 0;
|
return;
|
||||||
break;
|
frameIndex = lastFrameIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -230,19 +249,25 @@ void Timeline::updateCurrentKeyFrame(int frameIndex)
|
||||||
|
|
||||||
to = _frames.at(_toIndex);
|
to = _frames.at(_toIndex);
|
||||||
|
|
||||||
if (frameIndex == from->getFrameIndex())
|
if(frameIndex == from->getFrameIndex())
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
if(frameIndex > from->getFrameIndex() && frameIndex < to->getFrameIndex())
|
||||||
|
break;
|
||||||
|
if(from->isEnterWhenPassed())
|
||||||
|
from->onEnter(to);
|
||||||
}
|
}
|
||||||
while (frameIndex < from->getFrameIndex() || frameIndex >= to->getFrameIndex());
|
while (true);
|
||||||
|
|
||||||
|
if(_fromIndex == length-1)
|
||||||
|
to = from;
|
||||||
|
|
||||||
_betweenDuration = to->getFrameIndex() - from->getFrameIndex();
|
_betweenDuration = to->getFrameIndex() - from->getFrameIndex();
|
||||||
|
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
_currentKeyFrame = from;
|
_currentKeyFrame = from;
|
||||||
_currentKeyFrame->onEnter(to);
|
_currentKeyFrame->onEnter(to);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue