I really wish I could just solve this myself but working with non-Cartesian coordinate system plus a few other things can confuse the hell out of me
I'm working on a map editor that I want to be able to handle quite a few tiles. I've already set it up so that it won't render anything that is outside the view of the window. I can also get the tile the mouse is on by some simple math. (Use the mouses position to know what the index should be). However holding the mouse and moving it more than medium speed will still leave many gaps. I've been wanting to use a line algorithm to solve this, however I'm confusing the hell out of myself I feel like.
Current implementation I have going it seems like it sort of does what its supposed to, but horribly. If I move the mouse just somewhat fast it's not that big a deal but if I move the mouse very fast it does odd things like this.
The most top right tile and the very bottom left tile, I went in a mostly straight diagonal line between the two, never releasing the mouse. So yeah what I'm doing now definitely doesn't work.
Here's the code I've got trying to deal with this. Note that I'm not worried about views yet, it's not on my to do list currently.
void Map::handleClick(sf::RenderWindow & WINDOW,std::string tile)
{
sf::Vector2i mp = sf::Mouse::getPosition(WINDOW);
sf::Vector2f mousePosition = static_cast<sf::Vector2f>(mp);
if(lastTile != NULL) // When the mouse is released lastTile gets reset to NULL
{
int x= lastTile->getPosition().x;
int y = lastTile->getPosition().y;
int x2 = Map::getTileByCoords(mousePosition).getPosition().x;
int y2 = Map::getTileByCoords(mousePosition).getPosition().y;
int dx = x - x2; int dy = y - y2;
for(int i = x/16; i != x2/16;)
{
int cy = (i*(dy/dx))*16;
Map::assignTile(Map::getTileByCoords(i*16,y),tile);
if(i > x2/16)
{
i --;
}
else{ i++; }
}
}
Map::assignTile(Map::getTileByCoords(mousePosition),tile);
Map::lastTile = &Map::getTileByCoords(mousePosition);
}