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 Bushstar

I am spawning an entity using the init function in main.js. The draw function of the created entity are not being called automatically. Currently I am calling the entities draw function manually from main.js own update function.

What am I doing that is stopping the draw function from being called? With a bit of testing I can see that the update function is not being called either.

I'm creating the entity like this.

this.ammohud = ig.game.spawnEntity(EntityAmmohud, 20, ig.system.height - 170);

I'm creating the entity below. Currently it is an 150px square translucent gray image.

ig.module(
	'game.entities.ammohud'
)
.requires(
	'impact.entity'
)
.defines(function(){
	EntityAmmohud = ig.Entity.extend({
		image: new ig.Image('media/ammohud.png'),
		size: {x: 150, y: 150},
		
		init: function( x, y, settings ) {
			this.pos.x = x;
		    this.pos.y = y;
		    this.parent(x, y, settings);
		},

		draw: function() {
			this.parent();
			this.image.draw(this.pos.x, this.pos.y, 0, 0);
		}
	});
});

1 decade ago by Bushstar

I've fixed it by spawning the ammohud entity from the player entity.

Can anyone explain why entities generated from the init function of the main class do not have their update and draw methods called automatically like other entities?

Perhaps this is something specific to the entity in the code above.

1 decade ago by alexandre

Where is your call to spawnEntity in relation to loadLevel? If before, things will break. Take a look at game.js' loadLevel function and see what it does to the entities property (creates a new one; any entities spawned before loadLevel will be 'forgotten').

1 decade ago by Bushstar

Spot on. I was spawning an entity with no level for it to be attached to.
Page 1 of 1
« first « previous next › last »