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 {
54 54
         target.draw(bg1Sprite);
55 55
     }
56 56
 
57
-    void Background::onEvent(sf::Event& event) {
58
-        switch (event.type) {
59
-        case sf::Event::Resized:
60
-            bg0View.setSize(event.size.width, event.size.height);
61
-            bg1View.setSize(event.size.width, event.size.height);
62
-            bg0Sprite.setTextureRect(sf::IntRect(0, 0, event.size.width + 2 * bg0Size, event.size.height + 2 * bg0Size));
63
-            bg1Sprite.setTextureRect(sf::IntRect(0, 0, event.size.width + 2 * bg1Size, event.size.height + 2 * bg1Size));
64
-            break;
65
-        default:
66
-            break;
67
-        }
57
+    void Background::resize(sf::Event& resizeEvent) {
58
+        bg0View.setSize(resizeEvent.size.width, resizeEvent.size.height);
59
+        bg1View.setSize(resizeEvent.size.width, resizeEvent.size.height);
60
+        bg0Sprite.setTextureRect(sf::IntRect(0, 0, resizeEvent.size.width + 2 * bg0Size, resizeEvent.size.height + 2 * bg0Size));
61
+        bg1Sprite.setTextureRect(sf::IntRect(0, 0, resizeEvent.size.width + 2 * bg1Size, resizeEvent.size.height + 2 * bg1Size));
68 62
     }
69 63
 }

+ 1
- 1
background.hpp View File

@@ -11,7 +11,7 @@ namespace Proto4 {
11 11
       public:
12 12
         void init(sf::Texture bg0, sf::Texture bg1, sf::View &gameView);
13 13
         void update(sf::View &gameView, sf::RenderTarget &window);
14
-        void onEvent(sf::Event& event);
14
+        void resize(sf::Event& resizeEvent);
15 15
 
16 16
       private:
17 17
         sf::Sprite bg0Sprite;

+ 5
- 1
main.cpp View File

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

Loading…
Cancel
Save