SFML community forums

General => SFML projects => Topic started by: imekon on November 04, 2015, 01:40:32 pm

Title: SFML with JavaScript, Box2D...
Post by: imekon on November 04, 2015, 01:40:32 pm
I've been poking around GameMaker Studio, Construct 2 and Clickteam Fusion 2.5 and started wondering how hard it would be to make a 2d game engine.

My reason for doing this was all of the above engines are fine, but they get in the way a bit, as I'd rather write code than visually program. GameMaker is unique in that it has a script language. Fusion has JavaScript for plugins.

I looked briefly at SDL but chose to use SFML instead (classes not C functions). I bolted a Lua interpreter on at first, but after reading "why everyone should learn javascript" (http://blog.monitor.us/2014/08/why-everyone-should-learn-javascript/), I thought, why not?

I got hold of duktape, a JavaScript engine and swapped out Lua. Now Lua is fine, but JavaScript is better (IMHO) as it's more C/C++ like.

I added Box2d physics and created my first couple of demos: a simple block game (http://imgur.com/a/z7IrB) and a physics demo.

So where am I going with this? Am I trying to make a game? I'm interested in Match3 type games and procedural generation... so that's why I'm doing this.

Oh yeah, and writing code like this is fun.
Title: Re: SFML with JavaScript, Box2D...
Post by: eXpl0it3r on November 04, 2015, 02:03:26 pm
Can you elaborate a bit on how your "bridge" to JavaScript looks like and what you can do solely in JavaScript?
Title: Re: SFML with JavaScript, Box2D...
Post by: imekon on November 04, 2015, 02:16:27 pm
I used duktape (duktape.org) to provide the embedded JavaScript. I originally used Lua but switched to duktape (JavaScript) as it's more C/C++ like. In fact, duktape is very similar to Lua in the C code.

The JavaScript behind each 'game' has at least two functions - initialise and run that get called by the engine.

I keep time consuming operations in C++ but let the JavaScript do the higher level stuff, like creation etc.

To create a box (32 x 32) with physics, you'd do something like

Code: [Select]
function initialise()
{
    box = GameObject.textureObject(1);    // create a sprite with texture index 1
    box.setOrigin(16, 16);                           // important for Box2D physics
    box.setPosition(100, 100);                    // set the position
    Physics.createDynamicBox(box, { density: 1, friction: 0.6 });
}
Title: Re: SFML with JavaScript, Box2D...
Post by: Tank on November 04, 2015, 04:17:40 pm
This is quite nice, and I haven't heard of Duktape yet. Would be nice to the code, if this is by any chance open.
Title: Re: SFML with JavaScript, Box2D...
Post by: imekon on November 04, 2015, 05:46:51 pm
It's not open source yet, but could be - if I can work out how to bring together SFML, Box2D, Duktape and the rest into one Git project.

SFGUI - maybe I should replace my crude console implementation with that for logging...
Title: Re: SFML with JavaScript, Box2D...
Post by: Jesper Juhl on November 04, 2015, 07:02:51 pm
It's not open source yet, but could be - if I can work out how to bring together SFML, Box2D, Duktape and the rest into one Git project
One option would be git submodule :
 https://git-scm.com/book/en/v2/Git-Tools-Submodules
 https://git-scm.com/docs/git-submodule
Title: Re: SFML with JavaScript, Box2D...
Post by: FRex on November 04, 2015, 11:58:51 pm
Quote
Now Lua is fine, but JavaScript is better (IMHO) as it's more C/C++ like.
Squirrel and AngelScript (and maybe a few others) are meant to fill the role of "more C++ like Lua like scripting", not JavaScript.
Title: Re: SFML with JavaScript, Box2D...
Post by: GraphicsWhale on November 05, 2015, 09:32:40 pm
I've been poking around GameMaker Studio, Construct 2 and Clickteam Fusion 2.5 and started wondering how hard it would be to make a 2d game engine.

You've completely underestimated the complexity of those engines.

Squirrel and AngelScript (and maybe a few others) are meant to fill the role of "more C++ like Lua like scripting", not JavaScript.

I wouldn't make a game relying mostly on Squirrel or Angelscript, though. Neither have a large community or has a proven JIT compiler available for it.
Title: Re: SFML with JavaScript, Box2D...
Post by: Tank on November 10, 2015, 08:31:59 am
And starting with ECMAScript2015 the language is indeed getting better. :P
Title: Re: SFML with JavaScript, Box2D...
Post by: imekon on November 10, 2015, 02:17:14 pm
And starting with ECMAScript2015 the language is indeed getting better. :P

Duktape is V5 with some bits of V6...  :-[
Title: Re: SFML with JavaScript, Box2D...
Post by: eugustus on December 29, 2016, 01:34:01 am
Hello.

Progress? Why not implement berkelium?

I found with links but i don't try it yet..

https://github.com/Yours3lf/gl_browser_gui (https://github.com/Yours3lf/gl_browser_gui)
https://github.com/ThomasColliers/glexp-gui (https://github.com/ThomasColliers/glexp-gui)


Sorry for bad english