Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Pixelbox

Create 2D games in JavaScript, made easier · By Cedric Stoquer

Dealing with multiple script files

A topic by Nooh Alavi created Apr 15, 2020 Views: 200 Replies: 3
Viewing posts 1 to 2

So pixelbox.js comes with a main.js script... how do i use multiple js scripts? Like an enemy.js, player.js, etc? Which I can combine in main.js?

(1 edit) (+1)

Yes, you can use require:

var player = require('./player');

and in player.js file, define what you want to export:

module.exports = Player; 

It's also possible to use the "import" syntax of ES6.

Oh, okay! Thank you!

So in player.js you are exporting a class named Player, right?
And are variables defined in player.js accessible in main.js (not just variables in the Player class)?