-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_hello_world.cpp
More file actions
60 lines (48 loc) · 1.58 KB
/
1_hello_world.cpp
File metadata and controls
60 lines (48 loc) · 1.58 KB
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
#include <game/window.h>
#include <game/scene.h>
#include <game/image.h>
// We will need scene to exend to setup our custom things
class MyScene : public Scene {
using Scene::Scene;
public:
// We will store our loaded image here
Image* image;
// Here we store what we need to crop from image
SDL_Rect frame;
// Here we store where and what size we need to display
SDL_FRect position;
virtual void prepare() {
// Load the image
image = new Image(renderer, "doc/images/planet.png");
// The image is sprite sheet
// But we only need first frame from it
frame.x = 0;
frame.y = 0;
frame.w = 100;
frame.h = 100;
// Scale the frame a bit from its original size
position.w = 200;
position.h = 200;
}
virtual void update(State* state) {
// Here we center image based on scene width and height
// No matter window size it will always stay in center
position.x = this->width/2 - position.w/2;
position.y = this->height/2 - position.h/2;
}
virtual void render(State* state) {
clear();
// Here we specify what to render from image with &frame
// and where to render on scene with &position
image->render(&frame, &position);
present();
}
};
int main(int argc, char** argv){
// Just create the window
Window* window = new Window("Hello World", 800, 600);
// Pass our scene instanse
window->setScene(new MyScene(window->window));
// Do the thing
return window->run();
}