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
我覺得很愚蠢 –