-
Notifications
You must be signed in to change notification settings - Fork 0
/
displayObj.js
67 lines (65 loc) · 1.8 KB
/
displayObj.js
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
var canvas;
var context;
var stageWidth = 1024;
var stageHeight = 768;
var displayObjectList = new Array();
$(document).ready(function () {
canvas = document.getElementById('canvas');
context = canvas.getContext('2d');
});
function Stage2D () {
this.init = function () {
setTimeout(paint, 0);
};
this.addChild = function (child) {
if (indexOf(child) === -1) {
displayObjectList.push(child);
}else {
displayObjectList.splice(indexOf(child), 1);
displayObjectList.push(child);
}
};
this.removeChild = function (child) {
if (indexOf(child) != -1) {
displayObjectList.splice(indexOf(child), 1);
}
};
};
var displayObjectList = new Array();
function indexOf(object) {
for (var i = 0; i < displayObjectList.length; i++) {
if (displayObjectList[i] == object) {
return i;
} else {
return -1;
}
}
};
function paint () {
context.clearRect(0, 0, stageWidth, stageHeight);
context.globalAlpha = 1;
for (var i = 0; i < displayObjectList.length; i++) {
displayObjectList[i].paint();
}
setTimeout(paint, 0);
}
function MoviceClip2D(img, data) {
this.x = 0;
this.y = 0;
this.rotation = 0;
this.scaleX = 1;
this.scaleY = 1;
this.visible = true;
this.alpha = 1;
this.paint = function () {
if (this.visible) {
context.save();
context.globalAlpha = this.alpha;
context.translate(this.x, this.y);
context.rotate(this.rotation * Math.PI / 180);
context.scale(this.scaleX, this.scaleY);
context.drawImage(img, 0, 0, img.width, img.height, -img.width / 2, -img.height/ 2, img.width, img.height);
context.restore();
}
}
}