Nazariglez / pixi-tween

pixi-tween is a plugin for Pixi.js v3.0.8 or higher to create tween animations.
MIT License
98 stars 39 forks source link

Pixi v5 support #17

Open DimaSamusenko opened 5 years ago

DimaSamusenko commented 5 years ago

Hi! Pixi-Tween 0.2.0 not working with Pixi.js 5.0.0-rc.3

Uncaught ReferenceError: PIXI is not defined at Object../node_modules/pixi-tween/build/pixi-tween.js (pixi-tween.js:formatted:1) at e (pixi-tween.js:formatted:1) at Object. (pixi-tween.js:formatted:1) at e (pixi-tween.js:formatted:1) at Object../node_modules/pixi-tween/build/pixi-tween.js (pixi-tween.js:formatted:1) at e (pixi-tween.js:formatted:1) at pixi-tween.js:formatted:1 at Object../node_modules/pixi-tween/build/pixi-tween.js (pixi-tween.js:formatted:1) at __webpack_require__ (pixi-tween.js:formatted:1) at Module../src/scripts/app/hints_component/limit_hints.js (pixi-tween.js:formatted:1)

Pionniers commented 5 years ago

Hello can anyone help on this I have the same problem

thedrint commented 5 years ago

Same error.

thedrint commented 5 years ago

Hello can anyone help on this I have the same problem

Quick solution is to clone/download files from src/ and import tweenManager from './index'; But in this case webpack show warning on building "export 'tween' (imported as 'PIXI') was not found in 'pixi.js' etc. So if you can live with warnings on build - this is temporary solution.

Pionniers commented 5 years ago

Because PIXI object is not defined when using Pixi.js 5.0.0 the tweenManager cannot read it. I don't know how to export PIXI object to tweenManager library

llorenspujol commented 5 years ago

Yes, pixiJs v5 doesn't add PIXI to the window object. The simplest way to patch it is just add PIXI to the window object manually... like:

import * as PIXI from 'pixi.js';
window['PIXI'] = PIXI;
import 'pixi-tween';

Hope this helps!

ShukantPal commented 4 years ago

Yes, pixiJs v5 doesn't add PIXI to the window object. The simplest way to patch it is just add PIXI to the window object manually... like:

import * as PIXI from 'pixi.js';
window['PIXI'] = PIXI;
import 'pixi-tween';

Hope this helps!

This is actually a troubling advice because Babel will reorder statements between imports to after the imports. This misses the whole point of giving window.PIXI to pixi-tween. Using require in place of import solves the problem: https://github.com/webpack/webpack/issues/1343

const PIXI = require('pixi.js');
window.PIXI = PIXI;
const PixiTween = require('pixi-tween');
tbrebant commented 2 years ago

This problem is still here and it feels very weird to still have to use an ugly workaround (requires in the middle of imports and exposing stuff on window 😞).

An alternative solution I found with webpack is to load the packages dynamically:

import(/* webpackChunkName: "pixi.js" */ 'pixi.js').then((module) => {
  window.PIXI = module; // required for pixi-tween
  import(/* webpackChunkName: "pixi-tween" */ 'pixi-tween').then((module) => {
    // we are ready
  });
});
chung-nguyen commented 1 year ago

The package is not that complicated to re-engineer. The author made it quite clean. I suggest forking it and fix the issue yourself. I would do it if I have some time.

Otherwise, my work around is just simply copy the whole src folder of pixi-tween to your own project and import the file index.js like this:

import * as PIXI from 'pixi.js';
import './lib/pixi-tween';