1

I have been working my way through the melonJS tutorial while keeping my application in mind in the back of my head.

I want to be able to add entities programmatically rather than specifying them in the .tmx file that gets loaded in for each level. Is this possible in melonJS or must entities be specified using the tiled editor? This seems rather restrictive.

Or is melonJS just the wrong framework for such a task, and if so is there another framework that might work better than just drawing on a canvas?

Dan
  • 9,391
  • 5
  • 41
  • 73
Tore
  • 1,236
  • 2
  • 11
  • 21

1 Answers1

6

you can add objects programmatically. Here are some writes about it.

To resume, you can do this:

In your Screen function, add "classes" to the pool of melon:

onResetEvent: function() {
  // tell the entity pool what classes it needs to work with
  me.pool.register('main', game.MainEntity, true);
},

then,when you need to create a new object of that type from the pool

var mainObject = me.pool.pull('main', 100, 100, otherData);

and when you need to add it to the game call this.

me.game.world.add(mainObject);

finally if you need to remove it.

me.game.world.removeChild(mainObject);

Some more info about the pool

This is still compatible with the new version of MelonJS 2.0.x

Martin
  • 189
  • 2
  • 10