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

6 years 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.

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

6 years ago by pattentrick

First of, your timer does not have a defined time, what maybe is not what you want.

// timer starts to count from -5
this.timer = new ig.Timer(5);

// timer starts to count from 0
this.timer = new ig.Timer();

You also need to call the delta method to get a value from your timer:

this.timer.delta();

Check if 5 seconds are over:

if( this.timer.delta() >= 5  ){
    // do something
}

For more information about the ImpactJS timer see this old but cool article:

http://www.pointofimpactjs.com/tutorials/view/7/using-impact-timers

6 years ago by levo

Thank you so much!

I was a bit confused on how the timer works but you cleared it up and that article helped out. I was able to get what I want working. My issue was not defining the time of the timer.
Page 1 of 1
« first « previous next › last »