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();
}
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();
}