hello everyone
[Old Post]
i'm working on a map editor and i'm having trouble placing the image on the screen by clicking on the mouse.
what i want exactly is when you left click the mouse on the screen the image will get drawn in that position and stay in that position even if you click again.
My problem is that the image keep following the mouse coordinates instead of taking the last mouse coordinates and set it position there.
can you guys please help me i have been trying to fix this for 2 days and i had no luck.
sorry for being a noob
[New Post]
now i have an array of sprites and i want every time you click on the mouse a sprite will get drawn in that position.
i tried the following but the sprites get drawn on top of each other every time i click the mouse button
bool DrawMe=false;
int index=0;
while(window.IsOpened())
{
sf::Event Event;
while(window.GetEvent(Event))
{
if(Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Left)
{
index++;
DrawMe=true;
}
}
float MouseX = Game.GetInput().GetMouseX();
float MouseY = Game.GetInput().GetMouseY();
//Clear
window.Clear();
//Draw
if(DrawMe==true)
{
for(int i=0; i<=index; i++)
herosprite[i].SetPosition(MouseX,MouseY);
DrawMe=false;
}
for(int i=0; i<=index; i++)
window.Draw(herosprite[i]);
//Display
window.Display();
}
return 0;
}