Impact

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

1 decade ago by jeffreybiles

Hey,

I'm wanting to create a dashboard entity so that I don' t have to clutter my main 'draw' function with a dozen more lines of code. So I try to spawn a dashboard entity every time I load a level:
	loadLevel: function( data ) {
		this.parent(data);
		ig.game.spawnEntity(EntityDashboard)
	},

And here is the first trial of my dashboard file:

ig.module(
  'game.entities.dashboard'
)
.requires(
  'impact.entity'
)
.defines(function(){
  EntityDashboard = ig.Entity.extend({
    font: new ig.Font( 'media/helvetica30EEE.png'),
    pos: {x: 5, y: 5},
    spacing: 35,

    draw: function(){
      this.font.draw("$" + ig.game.stats.money, this.pos.x, this.pos.y)
      this.font.draw("+" + ig.game.stats.addition.level, this.pos.x, this.pos.y + this.spacing)
    }
  });
});

When I go into the weltmeister level editor, it recognized dashboard as an entity. However, when I try and play the game it fails during load and gives me this error in the console:

Uncaught ReferenceError: EntityDashboard is not defined

Anyone have ideas on what might be causing this or how to solve it? I've tested this, and I'm able to spawn any of my old entities in that line.

1 decade ago by lachsen

You need to put 'game.entities.dashboard' in the requires() function call in one of your game file (e.g. in your main.js). Otherwise, the source won't be loaded.

It always works in weltmeister, because weltmeister loads all files inside the 'entities' folder automatically.

So maybe that's the problem here?

1 decade ago by jeffreybiles

Brilliant! It works!

I didn't have to load any of my other entities, which is why I was confused... then i realized I don't spawn anything else directly, so there's probably some hidden impact code that loads everything in when starting the game loop.

Thanks much!

1 decade ago by dominic

Yep, have a look at a level file that is saved from Weltmeister. The level data is wrapped in a module that requires all entities found in that level. The file also contains an array of ig.Image instances, so that the tileset images for the background maps are loaded by Impact's pre-loader.

That's why you don't have to require any other entities from that level - they are required when you require the level itself.

Here's the level from the Jump'n'Run demo, for example:

ig.module(
	'game.levels.test'
)
.requires(
	'impact.image',
	'game.entities.player',
	'game.entities.spike'
)
.defines(function(){
	
	LevelTest= /* ... actual level data ... */
	
	LevelTestResources=[
		new ig.Image('media/tiles.png')
	];
});

1 decade ago by jeffreybiles

Of course! This also answers my question of why we have to require levels but not entities.

Loving the framework, by the way. I'm getting this new game off the ground quicker than I thought possible.
Page 1 of 1
« first « previous next › last »