-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu_scene.h
67 lines (57 loc) · 1.23 KB
/
menu_scene.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include "scene.h"
#include "scene_manager.h"
extern SceneManager scene_manager;
class MenuScene :public Scene {
public:
MenuScene() {
window = new Window();
//×ÊÔ´¼ÓÔØ
img_menu = IMG_LoadTexture(window->get_render(), "resource/start_menu.png");
};
~MenuScene() = default;
void on_enter() {
SDL_Log("[Game Scene] -> Menu Scene");
SDL_ShowWindow(window->get_window());
};
void on_exit() {
SDL_HideWindow(window->get_window());
}
void on_update() {
};
void on_draw() {
SDL_Rect rect{0,0,window->get_size().x,window->get_size().y};
SDL_RenderCopy(window->get_render(), img_menu, 0, &rect);
SDL_RenderPresent(window->get_render());//ÉúЧ
};
void on_input() {
//ʼþ
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
running = 0;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_ESCAPE:
running = 0;
break;
case SDLK_SPACE:
scene_manager.switch_to(SceneManager::SceneType::Game);
break;
default:
break;
}
}
}
};
void on_destroy() {
SDL_HideWindow(window->get_window());
SDL_DestroyTexture(img_menu);
delete this;
}
private:
Window* window = nullptr;
SDL_Texture* img_menu;
};