Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MotionStreak initializing and avoid trail delay by one frame #10982

Merged
merged 3 commits into from Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cocos2d/core/components/CCMotionStreak.js
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
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