forked from yinhui1129754/CppFishingCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsprite.cpp
More file actions
126 lines (118 loc) · 2.86 KB
/
Copy pathsprite.cpp
File metadata and controls
126 lines (118 loc) · 2.86 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "../stdafx.h"
#include "sprite.h"
sprite::sprite(int x, int y) {
this->x = x;
this->y = y;
this->initG_x();
this->initG_y();
}
sprite::sprite(DemoApp * app, WCHAR * url, string spriteType, int w2, int h2)
{
this->img = app->content->getSoucre(url);
if (w2 == -1) {
this->width = (int)this->img->GetSize().width;
}
else {
this->width = w2;
}
if (h2 == -1) {
this->height = (int)this->img->GetSize().height;
}
else {
this->height = h2;
}
}
sprite::sprite(DemoApp * app, ID2D1Bitmap *url, string spriteType, int w2, int h2)
{
this->img = url;
if (w2 == -1) {
this->width = (int)this->img->GetSize().width;
}
else {
this->width = w2;
}
if (h2 == -1) {
this->height = (int)this->img->GetSize().height;
}
else {
this->height = h2;
}
}
float sprite::getTxtWidth(DemoApp * app) {
D2D1_SIZE_F size = {0,0};
// string d = this->txt;
LPWSTR d = g_chartowchar2(this->txt.c_str());
app->content->getTextInfo(d, size);
return size.width;
};
float sprite::getTxtHeight(DemoApp * app) {
D2D1_SIZE_F size = { 0,0 };
LPWSTR d = g_chartowchar2(this->txt.c_str());
app->content->getTextInfo(d, size);
return size.height;
};
sprite::~sprite()
{
}
void sprite::render(DemoApp * app) {
if (!this->visible) {
return;
}
if (this->spriteType == "animateSprite") {
unsigned int len = this->frameArr.size();
if (this->speedNowTime + app->msTime >= this->speedTime) {
this->speedNowTime = 0;
if (this->nowFrame <len -1) {
this->nowFrame++;
}
else {
if (this->loop > 0) {
this->loop--;
}
if (this->loop == 0) {
this->amtEnd(this);
}
else {
this->nowFrame = 0;
}
}
}
else {
this->speedNowTime += app->msTime;
}
if (len >= 0 ) {
this->frame = &(this->frameArr[this->nowFrame]);
}
else {
this->frame = NULL;
}
}
int x1 = 0;
int y1 = 0;
//绘制自己的变换情况
app->content->save();
if (this->angle != 0) {
app->content->rotate(this->angle, this->g_x+this->getWidth()*this->pivot.x , this->g_y+this->getHeight()*this->pivot.y );
}
if (this->frame != NULL) {
app->content->drawImage(this->img, this->g_x+ x1, this->g_y+y1, this->width*this->zoom, this->height*this->zoom,this->frame);
}
else if (this->spriteType == "fillSprite") {
app->content->fillImage(this->img, this->g_x+ x1, this->g_y+ y1, this->width*this->zoom, this->height*this->zoom);
}
else if (this->spriteType == "textSprite") {
app->content->strokeStyle(this->rgb, this->alpha);
app->content->drawText(this->txt,this->g_x,this->g_y,this->width,this->height);
}
else {
app->content->drawImage(this->img, this->g_x+ x1, this->g_y+ y1, this->width*this->zoom, this->height*this->zoom);
}
app->content->restore();
//递归绘制所有子元素
unsigned int len = this->children.size();
for (unsigned int i = 0;i < len;i++) {
if (this->children[i]->children.size() > 0) {
this->children[i]->render(app);
}
}
}