Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

CoffeeScript + Phaser + Classes


coltonoscopy
 Share

Recommended Posts

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 = Creature

It'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

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

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-app

Using 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

 Share

  • Recently Browsing   0 members

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