Hello, I’ve been trying the offline canvas without the editor and I’m wondering how to attach scripts and make entities on their respective files and instantiating them instead of having everything on one big file.
I’ve seen the engine examples but they also have everything in one file. How should I approach having a player.js, input.js, etc?
Sorry if I’m missing something obvious, I’m new to entity/component based programming
How would I create this entity from the main script/index.html? Or how do I code and attach a script component from another file, for example attaching bulletLogic.js to the entity bullet.
You can put them in same or different files as you wish. Just make sure you load engine first, then script files and then you start you application referencing scripts by names or their function handlers.
The only problem I’m dealing with now is that I can’t seem to use attributes.
I found this answer from some time ago but it’s not working anymore due to the way you attach scripts now:
I havent’t found anything about adding a name to a script in the documentation.
Adding name: “rotate” like in the previous code didn’t work.
I’ve made JSFiddle example, that defines script, and then uses attribute and slider to fiddle with attribute.
You can simply move script definition to another file, and load it later, just using script attribute, or using an asset.