Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
loeasy68
GitHub Repository: loeasy68/loeasy68.github.io
Path: blob/main/website/GAUSS/js/anims-manager.js
2941 views
1
var Anim = function(id)
2
{
3
this.id = id;
4
this.frames = new Array();
5
this.loop = true;
6
this.start_idx = 0;
7
this.animInt = null;
8
this.current_frame = this.start_idx;
9
this.frame_rate = 150;
10
this.addFrame = addAnimFrame;
11
this.removeFrame = removeAnimFrame;
12
this.incrCurrIdx = incrCurrFrame;
13
this.play = startRollingFrames;
14
this.stop = stopRollingFrames;
15
};
16
17
var addAnimFrame = function(idx, image)
18
{
19
this.frames[idx] = image;
20
};
21
22
var removeAnimFrame = function(idx)
23
{
24
this.frames.splice(idx, 1);
25
};
26
27
var incrCurrFrame = function()
28
{
29
this.current_frame = (this.current_frame + 1) % this.frames.length;
30
};
31
32
var createNewAnim = function(id)
33
{
34
var newAnim = new Anim(id);
35
editorAnimsList.push(newAnim);
36
editorMapIdAnim[id] = newAnim;
37
};
38
39
var startRollingFrames = function()
40
{
41
if(this.animInt)
42
return;
43
var that = this;
44
this.animInt = setInterval(function()
45
{
46
if(that.loop === false && that.current_frame === that.frames.length - 1)
47
{
48
clearInterval(that.animInt);
49
that.animInt = null;
50
return;
51
}
52
that.incrCurrIdx();
53
}, that.frame_rate);
54
};
55
56
var stopRollingFrames = function()
57
{
58
clearInterval(this.animInt);
59
this.animInt = null;
60
this.current_frame = this.start_idx;
61
};
62
63
var editorAnimsList = [];
64
var editorMapIdAnim = {};
65
var editorAnimsCount = 0;
66
67
var deleteEditorAnim = function(id)
68
{
69
var anim = editorMapIdAnim[id];
70
editorAnimsList.splice(editorCharactersList.indexOf(anim), 1);
71
delete editorMapIdAnim[id];
72
};
73
74
75
76