I am struggling with a shadow that appears in front of an object is moving. I use SFML/Graphics.hpp to create the object. You can move the object using the WASD keys. I don't have any idea how to solve it. I tried change speed, it worked, but object has less speed and also the shadow was there still. I tried round object's coordinates, it didn't work. I guess maybe it is monitor, he can not change between colours as object change it's position?

I am attending the code in C++:

#include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <iostream> #include <conio.h> using namespace std; using namespace sf; void main() { RenderWindow window(VideoMode::getDesktopMode(), "slova", Style::Resize | Style::Close); CircleShape rectangle(50.f); rectangle.setFillColor(Color(0, 150, 150)); rectangle.setPosition({200.f,100.f}); auto WindowHandle = window.getNativeHandle(); window.setVerticalSyncEnabled(true); int celyVstup = 0; int rychlost = 300; Clock clock; vector<int> seznam_obdelniku; while (window.isOpen()) { float x = 0; float y = 0; while (const optional event = window.pollEvent()) { if (event->is<Event::Closed>()) { window.close(); } if (const auto MouseEvent = event->getIf<Event::MouseButtonPressed>()) { Vector2f mousePos = window.mapPixelToCoords(MouseEvent->position); if (rectangle.getGlobalBounds().contains(mousePos)) { cout << "button has just pressed" << endl; } } } float dt = clock.restart().asSeconds(); if (Keyboard::isKeyPressed(Keyboard::Key::W)) { y = -rychlost*(dt); } if (Keyboard::isKeyPressed(Keyboard::Key::S)) { y = rychlost * (dt); } if (Keyboard::isKeyPressed(Keyboard::Key::D)) { x = rychlost * (dt); } if (Keyboard::isKeyPressed(Keyboard::Key::A)) { x = -rychlost * (dt); } rectangle.move({ round(x),round(y) }); if (_kbhit()) { int vstup = _getch(); if (vstup == '\r') { seznam_obdelniku.push_back(celyVstup); cout << celyVstup << endl; celyVstup = 0; } else { celyVstup = vstup+celyVstup; } } window.clear(Color::Black); window.draw(rectangle); window.display(); } for (const auto& hodnota : seznam_obdelniku) { cout << hodnota << " "; } }

genpfault's user avatar

genpfault

52.3k12 gold badges94 silver badges153 bronze badges

Marek's user avatar

New contributor

Marek is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.