Jump to content

problems with phaser 3 polyfills and angular 6


bousing
 Share

Recommended Posts

Hi :)

  I wrote this because I have problems with polyfills and other phaser src. I want make a phaser game with Angular 6 but when I import the library in my component, created the config object and run the phaser's object the browser says  global is not defined at Object../node_modules/phaser/src/polyfills/requestAnimationFrame.js

I declare it (is not the best practice, I know) but other var in other script neither is it declared.. I think theese problems appears because I use Angular and transpile with a different way than babel...I dont know...

can you help me ? Thanks for reading :)

Link to comment
Share on other sites

  • 1 month later...

Phaser 3.11.0 with Angular 6 Workaround

1. install angular project with cli

2. add Phaser to your project with npm

3. copy the phaser.d.ts from the official phaser 3 doc into your src folder

4. modify this files by adding at the begining :

declare interface ActiveXObject {}
declare interface GamepadHapticActuator {}

5. add phaser.js into the angular.json, in the scripts section :

"node_modules/phaser/dist/phaser.js"

This should now works. (but this will need more inspection with ActiveXObject and GamepadHapticActuator).

 

Regards

Link to comment
Share on other sites

  • 2 months later...
On 6/26/2018 at 5:30 AM, bousing said:

Hi :)

  I wrote this because I have problems with polyfills and other phaser src. I want make a phaser game with Angular 6 but when I import the library in my component, created the config object and run the phaser's object the browser says  global is not defined at Object../node_modules/phaser/src/polyfills/requestAnimationFrame.js

I declare it (is not the best practice, I know) but other var in other script neither is it declared.. I think theese problems appears because I use Angular and transpile with a different way than babel...I dont know...

can you help me ? Thanks for reading :)

I faced the same problem and finally found that you can not import definitions from 'phaser' directly in your ts file, just use `Phaser.XXX` instead.

E.g. remove lines such as `import { BlendModes } from 'phaser';` and use `Phaser.BlendModes.XXX` when you need refer BlendModes.

Just point out here for help others. :)

Github Demo

Edited by Chen Wei
add github demo link
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...