Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 1635 characters in body
Source Link
AliTeo
  • 35
  • 1
  • 7

Here is my Game.cpp File: EDIT: I pasted the current code:

#include "Game.h" Game::Game() : m_window("Multiplayer Space Shooter Game", sf::Vector2u(800, 600)) { // Setting up class members. m_shipText.loadFromFile("C:\\Users\\AliTeo\\Desktop\\Piksel çalışmaları\\ship_pixel2.png"); m_ship.setTexture(m_shipText); m_ship.setOrigin(m_shipText.getSize().x / 2, m_shipText.getSize().y / 2); m_ship.setPosition(320, 240); } Game::~Game() {} void Game::HandleInputUpdate() { m_window.Update(); // Update window events. m_ship.move(m_speedX, m_speedY); m_ship.setRotation(90 + m_angle); HandleInput(); } void Game::HandleInput() { sf::Mouse m_mouse;  m_angle = atan2(m_mouse.getPosition(m_window&m_window).y - m_ship.getPosition().y, m_mouse.getPosition(&m_window).x - m_ship.getPosition().x); // Error m_angle *= 180 / m_PI; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && m_speedX <= m_speedLimit) { m_speedX += m_acceleration; } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && m_speedX >= -1 * m_speedLimit) {   m_speedX -= m_acceleration; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && m_speedY <= m_speedLimit) { m_speedY += m_acceleration; } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && abs(m_speedY) >= -1 * m_speedLimit) { m_speedY -= m_acceleration; } } void Game::Render() { m_window.BeginDraw(); // Clear. m_window.Draw(m_ship); m_window.EndDraw(); // Display. } Window* Game::GetWindow() { return &m_window; } 
no instance of overloaded function "sf::Mouse::getPosition" matches the argument list 

Game.h:

  #include "Window.h" class Game { public: ... Game();  ~Game(); void HandleInput(); void Update(); void Render(); Window* GetWindow(); private: sf::Sprite m_ship; sf::Texture m_shipText; //sf::MouseVector2i m_mouse;mousePos = sf::Mouse::getPosition(); Window m_window; const float m_PI = 3.1415f; float m_speedX = 0; float m_speedY = 0; float m_acceleration = 0.001f; //float m_friction = 0.001f; float m_speedLimit = 0.5f; float m_angle; }; 

Here is my Game.cpp File:

void Game::HandleInput() { ... m_angle = atan2(m_mouse.getPosition(m_window).y - m_ship.getPosition().y, m_mouse.getPosition().x - m_ship.getPosition().x); // Error m_angle *= 180 / m_PI; ... 
no instance of overloaded function "sf::Mouse::getPosition" matches the argument list 

Game.h:

#include "Window.h" class Game { public: ...  void HandleInput(); void Update(); void Render(); Window* GetWindow(); private: sf::Sprite m_ship; sf::Texture m_shipText; sf::Mouse m_mouse; Window m_window; ... } 

Here is my Game.cpp File: EDIT: I pasted the current code:

#include "Game.h" Game::Game() : m_window("Multiplayer Space Shooter Game", sf::Vector2u(800, 600)) { // Setting up class members. m_shipText.loadFromFile("C:\\Users\\AliTeo\\Desktop\\Piksel çalışmaları\\ship_pixel2.png"); m_ship.setTexture(m_shipText); m_ship.setOrigin(m_shipText.getSize().x / 2, m_shipText.getSize().y / 2); m_ship.setPosition(320, 240); } Game::~Game() {} void Game::Update() { m_window.Update(); // Update window events. m_ship.move(m_speedX, m_speedY); m_ship.setRotation(90 + m_angle); HandleInput(); } void Game::HandleInput() { sf::Mouse m_mouse;  m_angle = atan2(m_mouse.getPosition(&m_window).y - m_ship.getPosition().y, m_mouse.getPosition(&m_window).x - m_ship.getPosition().x); m_angle *= 180 / m_PI; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && m_speedX <= m_speedLimit) { m_speedX += m_acceleration; } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && m_speedX >= -1 * m_speedLimit) {   m_speedX -= m_acceleration; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && m_speedY <= m_speedLimit) { m_speedY += m_acceleration; } else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && abs(m_speedY) >= -1 * m_speedLimit) { m_speedY -= m_acceleration; } } void Game::Render() { m_window.BeginDraw(); // Clear. m_window.Draw(m_ship); m_window.EndDraw(); // Display. } Window* Game::GetWindow() { return &m_window; } 
no instance of overloaded function "sf::Mouse::getPosition" matches the argument list   #include "Window.h" class Game { public: Game();  ~Game(); void HandleInput(); void Update(); void Render(); Window* GetWindow(); private: sf::Sprite m_ship; sf::Texture m_shipText; //sf::Vector2i mousePos = sf::Mouse::getPosition(); Window m_window; const float m_PI = 3.1415f; float m_speedX = 0; float m_speedY = 0; float m_acceleration = 0.001f; //float m_friction = 0.001f; float m_speedLimit = 0.5f; float m_angle; }; 
added 317 characters in body
Source Link
AliTeo
  • 35
  • 1
  • 7

I am trying to write sf::mouse::getPosition(const Window &Relative To) in a function but I can't write the correct argument in it. Why is that?

Here is my Game.cpp File:

void Game::HandleInput() { ... m_angle = atan2(m_mouse.getPosition(m_window).y - m_ship.getPosition().y, m_mouse.getPosition().x - m_ship.getPosition().x); // Error m_angle *= 180 / m_PI; ... 

m_window is a member of Game.h

no instance of overloaded function "sf::Mouse::getPosition" matches the argument list 

Game.h:

#include "Window.h" class Game { public: ... void HandleInput(); void Update(); void Render(); Window* GetWindow(); private: sf::Sprite m_ship; sf::Texture m_shipText; sf::Mouse m_mouse; Window m_window; ... } 

I am trying to write sf::mouse::getPosition(const Window &Relative To) in a function but I can't write the correct argument in it. Why is that?

Here is my Game.cpp File:

void Game::HandleInput() { ... m_angle = atan2(m_mouse.getPosition(m_window).y - m_ship.getPosition().y, m_mouse.getPosition().x - m_ship.getPosition().x); // Error m_angle *= 180 / m_PI; ... 

m_window is a member of Game.h

no instance of overloaded function "sf::Mouse::getPosition" matches the argument list 

I am trying to write sf::mouse::getPosition(const Window &Relative To) in a function but I can't write the correct argument in it. Why is that?

Here is my Game.cpp File:

void Game::HandleInput() { ... m_angle = atan2(m_mouse.getPosition(m_window).y - m_ship.getPosition().y, m_mouse.getPosition().x - m_ship.getPosition().x); // Error m_angle *= 180 / m_PI; ... 

m_window is a member of Game.h

no instance of overloaded function "sf::Mouse::getPosition" matches the argument list 

Game.h:

#include "Window.h" class Game { public: ... void HandleInput(); void Update(); void Render(); Window* GetWindow(); private: sf::Sprite m_ship; sf::Texture m_shipText; sf::Mouse m_mouse; Window m_window; ... } 
Source Link
AliTeo
  • 35
  • 1
  • 7

sf::mouse::getPosition method help

I am trying to write sf::mouse::getPosition(const Window &Relative To) in a function but I can't write the correct argument in it. Why is that?

Here is my Game.cpp File:

void Game::HandleInput() { ... m_angle = atan2(m_mouse.getPosition(m_window).y - m_ship.getPosition().y, m_mouse.getPosition().x - m_ship.getPosition().x); // Error m_angle *= 180 / m_PI; ... 

m_window is a member of Game.h

no instance of overloaded function "sf::Mouse::getPosition" matches the argument list