Moving a sprite revisited

Now that we have a fancy event manager, let's test it fully by moving a sprite to the location of the mouse when the left shift key is held down and the left mouse button is pressed. Add two new data members to your Game class: m_texture and m_sprite. Set them up as discussed in the previous chapters. For our purposes, we'll just be re-using the mushroom graphic from the first few chapters. Now add and implement a new method in your game class called MoveSprite:

void Game::MoveSprite(EventDetails* l_details){ sf::Vector2i mousepos = m_window->GetEventManager()->GetMousePos(m_window->GetRenderWindow()); m_sprite.setPosition(mousepos.x, mousepos.y); std::cout << "Moving sprite to: " << mousepos.x << ":" << mousepos.y << ...

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.