diff --git a/native/cocos/2d/CCMotionStreak.cpp b/native/cocos/2d/CCMotionStreak.cpp index 1ec9f77961..e5c4d77302 100644 --- a/native/cocos/2d/CCMotionStreak.cpp +++ b/native/cocos/2d/CCMotionStreak.cpp @@ -107,20 +107,10 @@ bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Co _positionR.setZero(); _fastMode = true; - _minSeg = (minSeg == -1.0f) ? stroke/5.0f : minSeg; - _minSeg *= _minSeg; - _stroke = stroke; - _fadeDelta = 1.0f/fade; - _maxPoints = (int)(fade*60.0f)+2; - _nuPoints = 0; - _pointState = (float *)malloc(sizeof(float) * _maxPoints); - _pointVertexes = (Vec2*)malloc(sizeof(Vec2) * _maxPoints); - - _vertices = (Vec2*)malloc(sizeof(Vec2) * _maxPoints * 2); - _texCoords = (Tex2F*)malloc(sizeof(Tex2F) * _maxPoints * 2); - _colorPointer = (GLubyte*)malloc(sizeof(GLubyte) * _maxPoints * 2 * 4); + setMinSeg(minSeg); + setFadeTime(fade); // Set blend mode _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; @@ -220,6 +210,31 @@ void MotionStreak::setTexture(Texture2D *texture) } } +float MotionStreak::getFadeTime() +{ + return 1.0f / _fadeDelta; +} + +void MotionStreak::setFadeTime(float fade) +{ + _fadeDelta = 1.0f/fade; + + _maxPoints = (int)(fade*60.0f)+2; + _nuPoints = 0; + _pointState = (float *)malloc(sizeof(float) * _maxPoints); + _pointVertexes = (Vec2*)malloc(sizeof(Vec2) * _maxPoints); + + _vertices = (Vec2*)malloc(sizeof(Vec2) * _maxPoints * 2); + _texCoords = (Tex2F*)malloc(sizeof(Tex2F) * _maxPoints * 2); + _colorPointer = (GLubyte*)malloc(sizeof(GLubyte) * _maxPoints * 2 * 4); +} + +void MotionStreak::setMinSeg(float minSeg) +{ + _minSeg = (minSeg == -1.0f) ? _stroke / 5.0f : minSeg; + _minSeg *= _minSeg; +} + void MotionStreak::setBlendFunc(const BlendFunc &blendFunc) { _blendFunc = blendFunc; @@ -232,12 +247,12 @@ const BlendFunc& MotionStreak::getBlendFunc() const void MotionStreak::setOpacity(GLubyte opacity) { - CCASSERT(false, "Set opacity no supported"); + CCLOG("Set opacity no supported"); } GLubyte MotionStreak::getOpacity() const { - CCASSERT(false, "Opacity no supported"); + CCLOG("Opacity no supported"); return 0; } @@ -404,4 +419,3 @@ void MotionStreak::draw(Renderer *renderer, const Mat4 &transform, uint32_t flag } NS_CC_END - diff --git a/native/cocos/2d/CCMotionStreak.h b/native/cocos/2d/CCMotionStreak.h index 27c4dbfd02..0dbe387ab7 100644 --- a/native/cocos/2d/CCMotionStreak.h +++ b/native/cocos/2d/CCMotionStreak.h @@ -76,6 +76,26 @@ public: */ void reset(); + /** Get trail fragment fade time, in seconds. + * + * @return float fadeTime. + */ + float getFadeTime(); + /** Sets trail fragment fade time, in seconds. + * + * @param fade. + */ + void setFadeTime(float fade); + /** Get minimum segment size. + * + * @return float minSeg. + */ + inline float getMinSeg() const { return _minSeg; } + /** Sets minimum segment size. + * + * @param minSeg. + */ + void setMinSeg(float minSeg); /** When fast mode is enabled, new points are added faster but with lower precision. * * @return True if fast mode is enabled.