Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phaser 3 tween opacity?

I'm trying to tween a sprite from one point to another and have it fade away while it's moving. I've tried this:

const tween = game.tweens.add({
  targets: [log.sprite],
  x: fire.x,
  y: fire.y + (fire.height * 0.2),
  opacity: 0,
  duration: 300,
  repeat: 0,
  onComplete() {
    destroyLog(log);
    resolve();
  },
});

But this doesn't work. I'm having a lot of trouble finding good API docs for Phaser 3, so I'm not sure where I should be looking for this information.

like image 394
SimpleJ Avatar asked Apr 07 '18 20:04

SimpleJ


People also ask

What is tween in phaser 3?

Tweens. Tween. A Tween is able to manipulate the properties of one or more objects to any given value, based on a duration and type of ease. They are rarely instantiated directly and instead should be created via the TweenManager.

What is phaser3?

Phaser 3 is the new version of the Phaser Game Framework series. It includes a brand-new custom WebGL renderer designed specifically for the needs of modern 2D games. Phaser uses both a Canvas and WebGL renderer internally and automatically switch between them based on browser support.


1 Answers

You probably should use alpha instead of opacity. Below is a working example for Phaser3. The start and end value lambdas are good just for flexibility. I guess you can replace them by values directly. this refers to Phaser.Scene instance.

this.add.tween({
  targets: [sprite],
  ease: 'Sine.easeInOut',
  duration: 1000,
  delay: 0,
  x: {
    getStart: () => startX,
    getEnd: () => endX
  },
  y: {
    getStart: () => startY,
    getEnd: () => endY
  },
  alpha: {
    getStart: () => startAlpha,
    getEnd: () => endAlpha
  },
  onComplete: () => {
    // Handle completion
  }
});

You can easily find helpful usage examples for Phaser 3 by cloning the repo locally and searching for some keywords in the code.

like image 188
samvel1024 Avatar answered Oct 06 '22 11:10

samvel1024