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.


Messages - Bersuli

Pages: [1]
1
General / Re: Sprites-mouse input
« on: June 26, 2021, 11:00:53 pm »
okokok i just did something,it is just half wrong=))

tha board of the game is comeing and going but the x images remain,is there any way i can make the board also stay?
BTW sorry if i am desparing u but i am new to this and really hyped=))

oh and also when an x gets printed it s actually more=)

#include <SFML/Graphics.hpp>
#include<iostream>
using namespace std;
using namespace sf;
int main()
{
   int n = 500;
   RenderWindow window(VideoMode(600, 600), "X & 0 infinit", Style::Close | Style::Resize);
   RectangleShape player(Vector2f(600,600));
   player.setOrigin(0, 0);
   Texture playerTexture;
   playerTexture.loadFromFile("tabla.jpeg");
   player.setTexture(&playerTexture);

   RectangleShape playerx(Vector2f(42, 42));
   playerx.setOrigin(21, 21);
   Texture playerxTexture;
   playerxTexture.loadFromFile("x.png");
   playerx.setTexture(&playerxTexture);

   window.draw(player);
   while (window.isOpen())
   {
      Event evnt;
      while (window.pollEvent(evnt))
      {
         switch (evnt.type)
         {
         case Event::Closed:
            window.close();
            break;
         }

      }
      //window.draw(player);
      if (Mouse::isButtonPressed(Mouse::Left))
      {

         Vector2i mousePos = Mouse::getPosition(window);
         playerx.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));
         //float pozitiex = static_cast<float>(mousePos.x);
         //float pozitiey = static_cast<float>(mousePos.y);
         float x = mousePos.x;
         float y = mousePos.y;
         window.draw(playerx);
         playerx.setPosition(x, y);
      }
      //window.draw(playerx);
      //playerx.setPosition(x, y);
      window.display();
   }

2
General / Re: Sprites-mouse input
« on: June 26, 2021, 10:40:03 pm »
ok so i think i get what u tried to tell me something about a list with the coordinates and then printing the shapes at the respectiv coordinates.
The thing is that the point of the game is to be "infinit" (i hope i got the word right i am not english) it is not really infint but i also don't think that would make much sense in making a list of 200 coordinates for 200 shapes=)))

3
General / Re: Sprites-mouse input
« on: June 26, 2021, 10:32:06 pm »
The thing is my friend i din't understand what u told me to do=))
So i tried something else that i tought might work which is adding a vector2f with the coordinates of the mouse and then draw my image at those coordinates.

this everithing i wrote down,if u want i can send u a picture of the board i am talking about(if it helps u helping me with my problem):

#include <SFML/Graphics.hpp>
#include<iostream>
using namespace std;
using namespace sf;
int main()
{
   int n = 500;
   RenderWindow window(VideoMode(600, 600), "X & 0 infinit", Style::Close | Style::Resize);
   RectangleShape player(Vector2f(600,600));
   player.setOrigin(0, 0);
   Texture playerTexture;
   playerTexture.loadFromFile("tabla.jpeg");
   player.setTexture(&playerTexture);

   RectangleShape playerx(Vector2f(42, 42));
   playerx.setOrigin(21, 21);
   Texture playerxTexture;
   playerxTexture.loadFromFile("x.png");
   playerx.setTexture(&playerxTexture);


   while (window.isOpen())
   {
      Event evnt;
      while (window.pollEvent(evnt))
      {
         switch (evnt.type)
         {
         case Event::Closed:
            window.close();
            break;
         }

      }
      window.draw(player);

      if (Mouse::isButtonPressed(Mouse::Left))
      {

         Vector2i mousePos = Mouse::getPosition(window);
         //playerx.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));
         Vector2f position(mousePos.x, mousePos.y);
         playerx.setPosition(position);
         window.draw(playerx);


      }
      window.display();
   }

   return 0;
}

player is the board and playerx is the X i want to draw multiple times on the mouse click.

4
General / Re: Sprites-mouse input
« on: June 26, 2021, 04:28:07 pm »
ok so i tried something but it doesn't work i don't understand whwat u told me to do exactly=)))
i would be very thankfull if u could show me how to do it.

5
General / Re: Sprites-mouse input
« on: June 26, 2021, 03:04:35 pm »
Ok i will try this and come back.

6
Hey, i don't know the answer to your question, i just wanted to ask if you can tell how to make a grid like that do i need to use like a 2D array or what(i want to make a grid for a texture simillar to a chess table)

7
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