This forum is read only and just serves as an archive. If you have any questions, please post them on

1 decade ago by relsieg

Hi folks,

if this has already been answered, pls. forward me (havent found it on the board tho :>)
I'm trying to create a puzzle and - as it happens - I have a looot of pieces the player can move. As I don't want to create every single entity by hand, I'm looking for a dynamic way to create them (I've created one entity-JS which kind of fits for alle pieces). I have all the pieces I want to use as PNG-files ( named by numbers, starting with 0 ).
I know there's the spawnEntity-Method but as far as I can see it, you can only give the type and the coords but not the name.
Do I have to override the method or is there already something in the code that I can use?

Cheers from Berlin,

1 decade ago by davidx


This is an example of different animations, but the same logic should hold true for your scenario.

1 decade ago by relsieg

thank you, that helped me (still struggling a bit, but I can see the light at the end).

1 decade ago by Jack9

Use a configuration array.
var conf = [0,0,1,2,1,2,0,3,0,4];

If necessary, nest arrays. If the array can be procedurally generated do that.
var conf = [];
for(var i=0;i<10;i++){
    conf[] = i;

Now that you have this array, you can spawn entities based on the contents.
for(var j=0;j<conf.length;j++){
    entity = this.spawnEntity( EntityPiece, x, y, {name:'entity_num_'+j});

The concept of passing in an arbitrary object to overried default configuration, is used in every javascript framework I know. GL
Page 1 of 1
« first « previous next › last »