Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Bersuli

Pages: [1]
1
General / Sprites-mouse input
« on: June 25, 2021, 09:17:59 pm »
I need to do something in my code and i need to know if it is possible and if it is maybe you can show me how to do it.I need so that whenever i click mouseleft an image(sprite/texture--i don't know what exactly i am new to sfml) appears on the screen in the place i clicked.I did this but when i release the mouse button the image dissapears.
I need it to stay,because i need to draw multiple of them(and all of them to stay) so i belive for this i should not use window.clear()

this what i did:
//the shape(it is an x image)
RectangleShape playerx(Vector2f(42, 42));
   playerx.setOrigin(21, 21);
   Texture playerxTexture;
   playerxTexture.loadFromFile("x.png");
   playerx.setTexture(&playerxTexture);


if (Mouse::isButtonPressed(Mouse::Left))
      {
      
         Vector2i mousePos = Mouse::getPosition(window);
         playerx.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));
         window.draw(playerx);
      }

please Help


Update:
in my program i have a game that has a texture as the table game wich is like a chess table just bigger.Do i need to make like a 2D array for that texture?
I don't know how to make this either=)))

Pages: [1]
anything