-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathViewportClasses.cpp
More file actions
41 lines (35 loc) · 1 KB
/
ViewportClasses.cpp
File metadata and controls
41 lines (35 loc) · 1 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
#include "Common.h"
#include "Helpers.h"
/*
* Animation
*/
void Animation::apply(Tile & tile, double time, int frameOffset)
{
const int tileCount = width * height;
if (tileCount > 1) {
int tileIndex = int(time * speed) + frameOffset;
// _ - ^ _ - ^ ...
if (mode == AM_LOOP)
tileIndex = signmod(tileIndex, tileCount);
// _ - ^ - _ - ...
else if (mode == AM_PINGPONG) {
tileIndex = signmod(tileIndex, 2 * tileCount - 2);
if (tileIndex >= tileCount)
tileIndex = 2 * tileCount - tileIndex - 2;
}
// _ - ^ ^ ^ ...
else if (mode == AM_ONCE) {
tileIndex = min(tileCount - 1, tileIndex);
}
// Y first, then X
if (columnMajor) {
tile.x += tileIndex / height;
tile.y += tileIndex % height;
}
// X first, then Y
else {
tile.x += tileIndex % width;
tile.y += tileIndex / width;
}
}
}