coltonoscopy Posted October 15, 2015 Share Posted October 15, 2015 Hey guys! So I'm trying to write a CoffeeScript + Phaser game running on Node Webkit and have had no problems until trying to write classes that extend Phaser functionality when included in separate files. Something like the following:class Creature extends Phaser.Sprite constructor: (x, y, sheet) -> @health = 10 @stats = attack: 10, defense: 10, magic: 10, speed: 10 Phaser.Sprite.call @, game, x, y, sheet game.add.existing @module.exports.Creature = CreatureIt's saying that Phaser is not defined when this class is required and used by my main script, which makes sense because it's not been included in the file... However, my main script doesn't include Phaser either, uses Phaser of course, and doesn't have this problem. Does this have anything to do with the fact that my main script is included in the HTML document itself and thus doesn't need to include Phaser for that reason? Some insight would be greatly helpful and appreciated! Thank you very much for your time and help! Best,Colton Link to comment Share on other sites More sharing options...
jmp909 Posted October 15, 2015 Share Posted October 15, 2015 I don't use CoffeeScript , but I assume you would need to require 'Phaser' ?http://willyg302.github.io/blog/posts/2015-02-08-html5-games-with-phaser-parse-and-coffeescript/ Link to comment Share on other sites More sharing options...
coltonoscopy Posted October 15, 2015 Author Share Posted October 15, 2015 I don't use CoffeeScript , but I assume you would need to require 'Phaser' ?http://willyg302.github.io/blog/posts/2015-02-08-html5-games-with-phaser-parse-and-coffeescript/Doing that then seems to break 'document' being found; does that happen to have anything to do with the fact that I'm using Node Webkit? Thank you for your help! Link to comment Share on other sites More sharing options...
coltonoscopy Posted October 15, 2015 Author Share Posted October 15, 2015 Doing that then seems to break 'document' being found; does that happen to have anything to do with the fact that I'm using Node Webkit? Thank you for your help!I think I know what the problem is based on this SO question:http://stackoverflow.com/questions/29944526/how-do-you-correctly-import-react-into-a-node-webkit-appUsing NW and requiring modules puts NW in "Node" mode instead of browser mode, where "document" is unavailable; the solution is to bundle everything up using Browserify. Link to comment Share on other sites More sharing options...
coltonoscopy Posted October 15, 2015 Author Share Posted October 15, 2015 Using Browserify and coffeeify together to bundle everything into one file helped fix the problem. Link to comment Share on other sites More sharing options...
Recommended Posts