1 decade ago by levo
So here is my base class enemy and I have a variable this.timer, that gets created when I spawn an enemy. Then the second block of code is a enemy-line, which is a child to the parent. I spawn a 'enemy-line' which loads and everything, it moves with the path function but when I console.log(this.timer) the third block of code gets outputted. The timer just breaks and puts in really odd numbers.
What I want this to do is when I spawn an enemy it starts a timer for I can shoot bullets every 5 seconds or whatever time interval.
I assumed this would of work because the timer doesn't start until the object is spawned but when it starts it just gives the timer messed up values.
What I want this to do is when I spawn an enemy it starts a timer for I can shoot bullets every 5 seconds or whatever time interval.
I assumed this would of work because the timer doesn't start until the object is spawned but when it starts it just gives the timer messed up values.
ig.module( 'game.entities.enemy' ) .requires( 'impact.entity' ) .defines(function(){ EntityEnemy = ig.Entity.extend({ size: {x:32, y:32}, // Animation sheet being assigned, type default as blue animSheet: new ig.AnimationSheet('media/EnemyAnimation.png', 32 ,32), Type: 'Blue', init: function(x, y, settings){ this.parent(x, y, settings); // Animation sheets, either blue or red, 0.1 is speed this.addAnim( 'Blue', 0.1, [0,1,2,3]); this.addAnim( 'Red', 0.1, [4,5,6,7]); this.timer = new ig.Timer(); } }); });
ig.module( 'game.entities.enemy-line' ) .requires( 'game.entities.enemy' ) .defines(function(){ EntityEnemyLine = EntityEnemy.extend({ update: function(){ // Sets the Animation when spawned this.currentAnim = this.anims[this.Type]; this.path(); this.shoot(); this.parent(); }, path: function(){ this.vel.x = 10; this.vel.y = 10; }, shoot: function(){ console.log(this.timer); } }); });
Class {base: 5e-324, last: 5e-324, target: 0, pausedAt: 0, init: function…} base: 5e-324 last: 5e-324 target: 0