In the engine
//define the group of keys for shooting
Input.define("shootting", Key.SPACE, Key.DOWN);
In the entity
public var firePeriod:Number = 1; //inverse of fire rate in seconds (one second for shot in this case)
private var _t:Number = 0;
private var _pressed:Boolean = false;
override public function update():void
{
//Detect the key
if (Input.pressed("shooting"))
{
_pressed = true;
}
else if (Input.released("shooting"))
{
_pressed = false;
_t = 0;
}
//Shoot automatically
if (_pressed)
{
_t += FP.elapsed;
if (_t >= firePeriod)
{
shoot(); //function that shoots the projectile.
_t %= firePeriod;
}
}
}
Actually i thought that the documentation for this was good but it seems that i saw it somewere else. I didn’t ment to be rude but it seems that my comment ended up being it and i’m sorry about that (part of that is probably due the fact that english is not my first lenguage). I tried to tell you where you could find the information (which as said i was wrong about it).
But actually your reply wasn’t good ether. Even if i were a really toxic person, there are other people here so you should not be like that for a single reply. This may happen in other forums as well. There are a lot of people in the same place so the probability to find someone you don’t like is high.
PS: BTW, in FlashPunk you don’t work with Sprites
, It works with Entities
. I don’t know if you wrote it wrong or you are really using sprites.