-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmycanvas.h
53 lines (38 loc) · 1.05 KB
/
mycanvas.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
#ifndef MYCANVAS_H
#define MYCANVAS_H
#include "qsfmlcanvas.h"
#define DEGREES_PER_SECOND (180)
class MyCanvas : public QSFMLCanvas
{
public :
MyCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size) :
QSFMLCanvas(Parent, Position, Size)
{
}
private :
void OnInit()
{
// Load the image
myTexture.loadFromFile("peace.png");
// Setup the sprite
mySprite.setTexture(myTexture);
mySprite.setOrigin(myTexture.getSize().x / 2.0, myTexture.getSize().y / 2.0);
mySprite.setPosition(myTexture.getSize().x / 2.0, myTexture.getSize().y / 2.0);
}
void OnUpdate()
{
// Clear screen
clear(sf::Color(128, 0, 0));
sf::Time time = myClock.getElapsedTime();
myClock.restart();
auto rotation = time.asSeconds() * DEGREES_PER_SECOND;
// Rotate the sprite
mySprite.rotate(rotation);
// Draw it
draw(mySprite);
}
sf::Sprite mySprite;
sf::Texture myTexture;
sf::Clock myClock;
};
#endif // MYCANVAS_H