Now you can move the square around with the keyboard.
This commit is contained in:
parent
4cb1465dbc
commit
37199bdd19
2 changed files with 30 additions and 6 deletions
|
@ -30,8 +30,6 @@ void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tic
|
|||
|
||||
void Window_update(sf::RenderWindow &window, sf::Shape &shape) {
|
||||
window.clear();
|
||||
sf::Vector2u size = window.getSize();
|
||||
shape.setPosition(size.x / 2, size.y / 2);
|
||||
window.draw(shape);
|
||||
ImGui::SFML::Render(window);
|
||||
window.display();
|
||||
|
@ -50,6 +48,8 @@ int main() {
|
|||
ImGui_setup(window);
|
||||
|
||||
sf::CircleShape shape(100.f, 4);
|
||||
sf::Vector2u size = window.getSize();
|
||||
shape.setPosition(size.x / 2, size.y / 2);
|
||||
shape.setOrigin(100.f, 100.f);
|
||||
shape.setFillColor(sf::Color(150, 50, 250));
|
||||
shape.setOutlineThickness(10.f);
|
||||
|
@ -72,21 +72,39 @@ int main() {
|
|||
while (window.isOpen()) {
|
||||
sf::Event event;
|
||||
|
||||
// is this a main event loop
|
||||
while (window.pollEvent(event)) {
|
||||
ImGui::SFML::ProcessEvent(window, event);
|
||||
|
||||
if (event.type == sf::Event::Closed) {
|
||||
fmt::print("Exiting...\n");
|
||||
window.close();
|
||||
thread.terminate();
|
||||
switch(event.type) {
|
||||
|
||||
case sf::Event::Closed:
|
||||
fmt::print("Exiting...\n");
|
||||
window.close();
|
||||
thread.terminate();
|
||||
break;
|
||||
case sf::Event::KeyPressed:
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
|
||||
shape.move(-20, 0);
|
||||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
|
||||
shape.move(20, 0);
|
||||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
|
||||
shape.move(0, -20);
|
||||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
|
||||
shape.move(0, 20);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// should this move up to the pollEvent loop?
|
||||
sf::Time since = clock.getElapsedTime();
|
||||
if(since - tick > sf::seconds(1)) {
|
||||
tick = since;
|
||||
}
|
||||
|
||||
|
||||
shape.rotate(1);
|
||||
|
||||
ImGui_update(window, deltaClock, tick);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue