Impact

» Edit Game Info

8 months ago by DominicZelek

Hey guys, I decided to finish a game I started with the impact game engine a few years ago, but I'm having a bit of trouble with the ig.input.state

I followed the tutorial in the book "HTML 5 Game Development" by Jesse Freeman for the most part.

In the tutorial, weapons are created using the ig.input.pressed method, but I would rather use ig.input.state

but when I use input.state the bullets come out one after another incredibly fast. I want to slow it down, but I don't think I really understand how to use timers in impact.

You can play my game in its current state by visiting: http://DominicZelek.com/zombie-house

Any help would be greatly appreciated!! Thanks!

8 months ago by Joncom

Yeah, if you use ig.input.state('ATTACK') in your update function, then it will execute roughly 60 times per second (and spawn as many bullets).

Maybe you want to spawn 4 bullets per second?

EntityPlayer = ig.Entity.extend({
    init: function(x, y, settings) {
        this.parent(x, y, settings);
        this.fireTimer = new ig.Timer(1/4);
    },
    update: function() {
        this.parent();
        if(ig.input.state('ATTACK') && this.fireTimer.delta() >= 0) {
            ig.game.spawnEntity(EntityBullet, this.pos.x, this.pos.y);
            this.fireTimer.reset();
        }
    }
});
Page 1 of 1
« first « previous next › last »

Post Reply

Please login or register to reply.