Running GameJS in NW.js or Electron

17 views
Skip to first unread message

ashe...@gmail.com

unread,
Jun 9, 2017, 4:38:29 AM6/9/17
to GameJs
I want to run GameJS in the browser part of either NW.js or Electron, however, I'm running into a problem with the require() method.

In a normal browser, require() would be provided by GameJS as downloaded from the GameJS.org site.  However, in NW.js or Electron require is already defined.

So, when I try to execute require("./gamejs") to load the GameJS javascript into the browser window of NW.js for example, I get hit with:

Error: Synchronous Require not supported

What am I misunderstanding or missing, is it possible to run GameJS in either a NW.js or Electron desktop "browser" window?

Asher

Simon Oberhammer

unread,
Jun 9, 2017, 4:43:08 AM6/9/17
to GameJs
Hello Asher,
I've used NW before and it works. It's probably easiest if you require gamejs as a local NPM package and rely on a module bundler like browserify to output the final JS for your game.

hope that helps
 simon

Asher Wolfstein

unread,
Jun 20, 2017, 12:58:12 AM6/20/17
to GameJs
That's exactly what I ended up doing, in fact...

Hey guys, I've been working on this for about a week-and-a-half, probably two weeks, and I'm somewhat excited about it.

I've always loved the pygame library, and one day I found a very similar library in JavaScript called GameJS... I had just come across Brython a bit earlier and it struck me...

As long as we're using Python in the browser, we can also use it in the context of NodeWebkit, and that opens many doors.

I catalog more of the journey towards producing this library in this blog post: http://wunk.me/announcing-pygjs-pygame-in-your-browsernodewebkit/

I set up a github repository-(ies) documenting my modifications and developments at my github asherwunk account, PYGJS (Pygame in JavaScript) is here: https://github.com/asherwunk/pygjs

There's also a dedicated page on my blog, but for now it just contains the readme, but that may change in the future: http://wunk.me/programming-projects/pygjs/

All in all it's a -working- draft towards using PyGame in the browser with your browser python (brython)

It's NOT an emulator, and won't run pygame constructed games right out of the box, you have to make some browser specific changes to your code, such as preloading and not blocking with an infinite while loop while processing events.

Anyways, just thought I'd throw this up there to show you what *I've* been doing with GameJS,

Thanks!
Asher Wolfstein

P.S. If you like what I've written consider buying me a coffee: http://ko-fi.com/asherwolfstein  (I also have a pattern: https://www.patreon.com/asherwolfstein)
Reply all
Reply to author
Forward
0 new messages