December 2015
Beginner to intermediate
522 pages
11h 21m
English
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 << ...Read now
Unlock full access