SFML и C++ Уроки \ Разработка игр › Форумы › SFML System, Window и другие вопросы › Стрельба из автомата › Ответ в теме: Стрельба из автомата
У вас событийные условия находятся вне обработчика событий.
Попробуй так.
Перенеси эти условия в обработчик событий и добавь герою флаг is_Shoot
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
while (window.pollEvent(event)) { if (event.type == Event::MouseButtonPressed) if (event.key.code == Mouse::Left) is_Shoot = true; if (event.type == Event::MouseButtonReleased) if (event.key.code == Mouse::Left) is_Shoot = false; } if(is_Shoot) timer_Bullet += time; if(timer_Bullet > 150.f) { timer_Bullet = 0.f; Bullet.push_back(new TBullet(weaponsSprite,"MachineBullet",hero.x,hero.y,hero.anim.anim.sprite.getTextureRect().width, hero.anim.anim.sprite.getTextureRect().height, hero.STATE)); --(static_cast<TWeapons*>(Inventory.inventory[2])->ammo); } |