1
SFML不会将子画面移动超过1个像素(即使持有)。它还会在释放正在按住的箭头键时将精灵移回到其设定位置。SFML不能正确移动子画面
void Engine::mainLoop() {
//Loop until window is closed
while (window->isOpen()) {
processInput();
update();
sf::Sprite test;
sf::Texture texTest;
texTest.loadFromFile("img.png");
test.setTexture(texTest);
test.setPosition(50, 50);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up))
test.move(0, -1);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down))
test.move(0, 1);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left))
test.move(-1, 0);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right))
test.move(1, 0);
window->clear(sf::Color::Black);
window->draw(test);
renderFrame();
window->display();
}
}
你总是调用'setPosition'所以它会在你身边50,50 + -1 – vu1p3n0x
我觉得很愚蠢 –