c++ - Shoot button in game is triggering multiple times instead of once when hitting spacebar -


i'm making simple, spaceinvaders-style game. currently, have fire method, set respond spacebar, so:

case vk_space:      tank.fire();      break; 

and fire method, makes off screen bullets appear behind tank , shoot them upward.

void tank::fire() {     //moves bullets behind tank.     bullets[bulletcount].setpos(vector2d (tank_pos.x+20, tank_pos.y+20));      //sets speed vector in motion.     bullets[bulletcount].setspeed(vector2d (0, -350));     bulletcount++; //increment current bullet used. } 

the problem 1 physical hit of spacebar fires more 1 @ time. how 1 ensure 1 fires per press?

how capturing keyboard input? if loop checking key state have boolean represents weather or not new key down or not, clear when notice key isn't down more. if worried os's auto repeat want debouncing, basic idea capture time key down event compare against time future key down events occur can rate limit them.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -