Browse Source

remove onevent from background

master
sauer2 2 years ago
parent
commit
9654c7b423
3 changed files with 11 additions and 13 deletions
  1. 5
    11
      background.cpp
  2. 1
    1
      background.hpp
  3. 5
    1
      main.cpp

+ 5
- 11
background.cpp View File

@@ -54,16 +54,10 @@ namespace Proto4 {
target.draw(bg1Sprite);
}

void Background::onEvent(sf::Event& event) {
switch (event.type) {
case sf::Event::Resized:
bg0View.setSize(event.size.width, event.size.height);
bg1View.setSize(event.size.width, event.size.height);
bg0Sprite.setTextureRect(sf::IntRect(0, 0, event.size.width + 2 * bg0Size, event.size.height + 2 * bg0Size));
bg1Sprite.setTextureRect(sf::IntRect(0, 0, event.size.width + 2 * bg1Size, event.size.height + 2 * bg1Size));
break;
default:
break;
}
void Background::resize(sf::Event& resizeEvent) {
bg0View.setSize(resizeEvent.size.width, resizeEvent.size.height);
bg1View.setSize(resizeEvent.size.width, resizeEvent.size.height);
bg0Sprite.setTextureRect(sf::IntRect(0, 0, resizeEvent.size.width + 2 * bg0Size, resizeEvent.size.height + 2 * bg0Size));
bg1Sprite.setTextureRect(sf::IntRect(0, 0, resizeEvent.size.width + 2 * bg1Size, resizeEvent.size.height + 2 * bg1Size));
}
}

+ 1
- 1
background.hpp View File

@@ -11,7 +11,7 @@ namespace Proto4 {
public:
void init(sf::Texture bg0, sf::Texture bg1, sf::View &gameView);
void update(sf::View &gameView, sf::RenderTarget &window);
void onEvent(sf::Event& event);
void resize(sf::Event& resizeEvent);

private:
sf::Sprite bg0Sprite;

+ 5
- 1
main.cpp View File

@@ -76,7 +76,11 @@ namespace Proto4 {
// poll for events and pass them to components
sf::Event event;
while (window.pollEvent(event)) {
background.onEvent(event);
//switch (event.type) {
//case sf::Event::Resized:
if (event.type == sf::Event::Resized) {
background.resize(event);
}
state = menu.onEvent(event);
game.onEvent(event);
}

Loading…
Cancel
Save