Alright, I've done it! as I have said I put multiple selection on top of every selection in the game. So there is no longer need for a single click. Every time I press click, I draw a very small box on size ( 1, 1) and never renders it if bounding box is on this size. But each entity detects collision on this very small box. At the same time if I move the mouse while holding the left click I am able to draw the bounding box and select multiple unit at once.
This actually works and of course it is not the best solution but it gets the job done. Thank you guys for giving me tips. Actually, as I have posted it, I am asking about doing this not using interval time. But thanks for verifying my first thought it seems to be very legit solution.
Here is the snippet on how I have done it:
My SelectionHighlighter.cpp
void SelectionHighligher::calculateHighlight( sf::RenderWindow * window )
{
mousePosition = sf::Mouse::getPosition( *window );
float width = window->mapPixelToCoords( mousePosition ).x;
float height = window->mapPixelToCoords( mousePosition ).y;
width = width - mousePositionOnDrag.x + 1.0f;
height = height - mousePositionOnDrag.y + 1.0f;
highlight.setPosition( sf::Vector2f( mousePositionOnDrag ) );
highlight.setSize( sf::Vector2f( width , height ) );
}
void SelectionHighligher::drawHighlight( sf::RenderWindow * window )
{
if( highlight.getSize().x != 1.0f && highlight.getSize().y != 1.0f )
window->draw( highlight );
}
From the main application class
if( sf::Mouse::isButtonPressed( sf::Mouse::Button::Left ) )
{
highlight.calculateHighlight( &window );
selection.detectMultipleObjectSelection( highlight.getHighlightBounds() , &window );
selection.selectMultiple();
}
I just have to refactor this. Thank you very much!
~Cheers!
Neon Warge