1 decade ago by FriendlyDuck
Hey all, I'm new to impact and am having trouble with spawning an entity in my game. The idea is that when spacebar is pressed, the entity is created. This works, however anywhere between 5 - 8 instances of it appear on the screen! I only want one.
Here's my code:
Here's my code:
ig.module( 'game.entities.player' ) .requires( 'impact.entity' ) .defines(function(){ EntityPlayer = ig.Entity.extend({ size: {x:80, y:80}, maxVel: {x: 100, y: 150}, friction: {x: 600, y: 0}, gravityFactor:0, type: ig.Entity.TYPE.A, zIndex:99, animSheet: new ig.AnimationSheet( 'media/container.png', 80, 80), init: function( x, y, settings ) { this.addAnim('idle', 1, [0]); this.addAnim('containerOpen', 1, [1]); this.parent( x, y, settings ); }, update: function() { // move left or right if (ig.input.state('left')) { this.vel.x = -100; this.currentAnim = this.anims.idle; } if (ig.input.state('right')) { this.vel.x = +100; this.currentAnim = this.anims.idle; } if (ig.input.state('drop')) { this.currentAnim = this.anims.containerOpen; ig.game.spawnEntity( EntityBrick, this.pos.x, this.pos.y, {zIndex:1} ); ig.game.sortEntitiesDeferred(); //for( var i = 0; i < 5; i++ ) { // var e = ig.game.spawnEntity(EntityBrick, this.pos.x, this.pos.y); //} } this.parent(); } }); // Brick Entity EntityBrick = ig.Entity.extend({ size: {x:11, y:7}, type: ig.Entity.TYPE.B, checkAgainst: ig.Entity.TYPE.B, collides: ig.Entity.COLLIDES.ACTIVE, bounciness:0.5, zIndex:99, animSheet: new ig.AnimationSheet('media/brick.png', 11, 7), init: function(x, y, settings) { this.addAnim('idle', 0.5, [0]); this.parent(x, y, settings); } }); });