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

Transform effect leaves a trail when using the image layer. #286

Open
keithudev opened this issue Oct 21, 2024 · 1 comment
Open

Transform effect leaves a trail when using the image layer. #286

keithudev opened this issue Oct 21, 2024 · 1 comment
Labels
help wanted Extra attention is needed priority:high type:bug Something isn't working

Comments

@keithudev
Copy link

When I want to use the transform effect, to make it move from one side to the other, it leaves a trail. The previous frame should be cleared when moving.

const cursorLayer = new etro.layer.Image({
	source: cursorImage,
	startTime: 0,
	duration: video.duration,
	destHeight: 32,
	destWidth: 22,
	x: (canvas.width - canvas.width / 1.1) / 2,
	y: (canvas.height - canvas.height / 1.1) / 2,
	width: canvas.width / 1.1,
	height: canvas.height / 1.1,
});

const cursorEffect = new etro.effect.Transform({
	matrix: new etro.KeyFrame(...cursorKeyframes),
})

cursorLayer.effects.push(cursorEffect);
movie.layers.push(cursorLayer);
@keithudev
Copy link
Author

I have managed to make it work, creating a new effect that removes the previous frame, here is the code in case anyone is interested:

import etro from 'etro';

export interface TransformOptions {
  x: etro.Dynamic<number>;
  y: etro.Dynamic<number>;
}
export class Cursor extends etro.effect.Visual {
  x: etro.Dynamic<number>
  y: etro.Dynamic<number>

  constructor (options: TransformOptions) {
    super();

    this.x = options.x;
    this.y = options.y;
  }

  apply (target: any, reltime: number): void {
    const cctx = target.cctx;
    const canvas = target.canvas;
    const x = etro.val(this, 'x', reltime)
    const y = etro.val(this, 'y', reltime)

    const tmpCanvas = document.createElement('canvas');
    tmpCanvas.width = canvas.width;
    tmpCanvas.height = canvas.height;
    const tmpCtx = tmpCanvas.getContext('2d');


    tmpCtx?.drawImage(canvas, 0, 0, canvas.width, canvas.height);

    cctx.clearRect(0, 0, canvas.width, canvas.height);

    cctx.translate(x, y);

    cctx.drawImage(tmpCanvas, 0, 0);

    cctx.restore();
  }
}

@clabe45 clabe45 added priority:high help wanted Extra attention is needed type:bug Something isn't working labels Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed priority:high type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants