hexus / phaser-arcade-slopes

:triangular_ruler: A Phaser CE plugin that brings sloped tile collision handling to the Arcade Physics engine
MIT License
126 stars 16 forks source link

SAT is not defined #24

Closed richardhealy closed 7 years ago

richardhealy commented 7 years ago

I've tried to shim phaser-arcade-slopes in my game. I keep getting a:

SAT is not defined

A more full description is found here: http://www.richardhealy.co.uk/blog/phaser-issue-help

And code is found at:

https://github.com/richardhealy/emagine

richardhealy commented 7 years ago

Shim happens here:

https://github.com/richardhealy/emagine/blob/master/helpers/shims/Phaser.js

hexus commented 7 years ago

As we discussed in the Phaser Slack, this is down to the plugin not being built for ES6. Seeing as you're only exporting Phaser there, the code will run but SAT will not be available globally (not everything is kept under one namespace).

This isn't something I'm looking to improve until an ES6 version of Phaser (Lazer) is released.

alvinkeegangoh commented 7 years ago

I ran into this problem as well but I've found a way to solve it. Following the webpack config pattern of the Phaser ES6 Webpack boilerplate, you could add this to the your webpack config file as a rule under module.rules.

    {
      test: /phaser-arcade-slopes\.js$/,
      use: [{
        loader: 'expose-loader',
        options: 'SAT'
      }]
    }

This exposes the SAT as a global variable using the expose-loader.

Make sure to import and register the Arcade Slopes plugin in your level file like so:

import ArcadeSlopes from 'phaser-arcade-slopes'

// in the create function
create () {
    this.game.plugins.add(Phaser.Plugin.ArcadeSlopes)
}

Now you can use the plugin with a ES6 Webpack setup!

hexus commented 7 years ago

Nice! This will suffice until #41 is satisfied. :)