Skip to content

Commit

Permalink
Fix MotionStreak initializing and avoid trail delay by one frame (#10982
Browse files Browse the repository at this point in the history
)

* Fix MotionStreak initializing and avoid trail delay by one frame

* Read motion streak start position just before rendering

* avoid using public method
  • Loading branch information
jareguo committed Jul 19, 2022
1 parent a8fc3de commit 8505995
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cocos2d/core/components/CCMotionStreak.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var MotionStreak = cc.Class({
ctor () {
this._points = [];
this._lastWPos = new cc.Vec2();
this._lastWPosUpdated = false;
},

properties: {
Expand Down Expand Up @@ -248,8 +249,7 @@ var MotionStreak = cc.Class({
reset () {
this._points.length = 0;
this._assembler && this._assembler._renderData.clear();
this._lastWPos.x = 0;
this._lastWPos.y = 0;
this._lastWPosUpdated = false;
if (CC_EDITOR) {
cc.engine.repaintInEditMode();
}
Expand Down
9 changes: 6 additions & 3 deletions cocos2d/core/renderer/webgl/assemblers/motion-streak.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
****************************************************************************/

import Assembler2D from '../../assembler-2d';
import Mat4 from '../../../value-types/mat4';

const MotionStreak = require('../../../components/CCMotionStreak');
const RenderFlow = require('../../render-flow');
Expand All @@ -49,6 +50,7 @@ let _tangent = cc.v2();
let _miter = cc.v2();
let _normal = cc.v2();
let _vec2 = cc.v2();
let _worldMat = new Mat4();

function normal (out, dir) {
//get perpendicular
Expand Down Expand Up @@ -92,14 +94,14 @@ export default class MotionStreakAssembler extends Assembler2D {
let stroke = comp._stroke / 2;

let node = comp.node;
let matrix = node._worldMatrix.m;
let tx = matrix[12], ty = matrix[13];
node.getWorldMatrix(_worldMat);
let tx = _worldMat.m[12], ty = _worldMat.m[13];

let points = comp._points;
let lastPos = comp._lastWPos;
let fadeTime = comp._fadeTime;

let moved = lastPos.x !== tx || lastPos.y !== ty;
let moved = comp._lastWPosUpdated && (lastPos.x !== tx || lastPos.y !== ty);
if (moved) {
let cur;
let newHead = false;
Expand Down Expand Up @@ -144,6 +146,7 @@ export default class MotionStreakAssembler extends Assembler2D {

lastPos.x = tx;
lastPos.y = ty;
comp._lastWPosUpdated = true;

if (points.length < 2) {
return;
Expand Down

0 comments on commit 8505995

Please sign in to comment.