9 years ago by tobika
Hi there,
I started a project (just for the fun, not productive) in es6 with modules and everything. (mainly some background game logic)
Importing classes with
The whole thing is compiled with babel and some sort of babelfy(browserfy) for the modules into one big js file.
https://github.com/babel/babelify
Now I want to use the impact engine for this project, ideally imported as a es6 module file so it can interact with all the other game logic I already created.
I succeeded in creating one main.js file with my game main module.
In this file I can import any other es6 modules and use them directly in the impact code.
Now the tricky part.
I can use the impact internal require for impact modules because I still load the impact lib and it's a global variable.
But I can not use the internal require for entities because impact will try to load the actual file at this path. (The idea was that everything is compiled in one file to be able to use the es6 modules)
My solution that works for the moment but everything has to be in one file.
As I said, I succeeded in creating my main game module. If I want I cant create all the entities I need in the same module block by creating the variables inside the module.
I tried to create a real entity module in another file but I somehow can't export the right variable to reuse it in the the main game loop.
If I use the js console in the browser I see that the entity module was correctly register withing ig.modules but my main class can't get the 'EntityPlayer' variable because it wasn't required in the right way.
Sorry for this messy post. I was playing around 2 hours yesterday with this problem and just wanted to write about it in case somebody has already experience with it.
In any case, it's just a test project so if there is no real solution, no worries ;-)
Thanks,
Tobias
I started a project (just for the fun, not productive) in es6 with modules and everything. (mainly some background game logic)
Importing classes with
import Game from './game';
The whole thing is compiled with babel and some sort of babelfy(browserfy) for the modules into one big js file.
https://github.com/babel/babelify
Now I want to use the impact engine for this project, ideally imported as a es6 module file so it can interact with all the other game logic I already created.
I succeeded in creating one main.js file with my game main module.
In this file I can import any other es6 modules and use them directly in the impact code.
Now the tricky part.
I can use the impact internal require for impact modules because I still load the impact lib and it's a global variable.
But I can not use the internal require for entities because impact will try to load the actual file at this path. (The idea was that everything is compiled in one file to be able to use the es6 modules)
My solution that works for the moment but everything has to be in one file.
As I said, I succeeded in creating my main game module. If I want I cant create all the entities I need in the same module block by creating the variables inside the module.
var EntityPlayer = ig.Entity.extend({
I tried to create a real entity module in another file but I somehow can't export the right variable to reuse it in the the main game loop.
If I use the js console in the browser I see that the entity module was correctly register withing ig.modules but my main class can't get the 'EntityPlayer' variable because it wasn't required in the right way.
Sorry for this messy post. I was playing around 2 hours yesterday with this problem and just wanted to write about it in case somebody has already experience with it.
In any case, it's just a test project so if there is no real solution, no worries ;-)
Thanks,
Tobias