forked from pixijs/pixijs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
133 lines (113 loc) · 4.14 KB
/
index.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
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
127
128
129
130
131
132
133
describe('Example 1 - Basics', function () {
'use strict';
var baseUri = '/base/test/functional/example-1-basics';
var expect = chai.expect;
var currentFrame = 0;
var frameEvents = {};
var stage;
var renderer;
var bunny;
function onFrame(frame, callback) {
frameEvents[frame] = callback;
}
function animate() {
currentFrame += 1;
window.requestAnimFrame( animate );
// just for fun, lets rotate mr rabbit a little
bunny.rotation += 0.1;
// render the stage
renderer.render(stage);
if (frameEvents[currentFrame])
frameEvents[currentFrame](currentFrame);
}
function initScene() {
// create an new instance of a pixi stage
stage = new PIXI.Stage(0x66FF99);
// create a renderer instance
renderer = PIXI.autoDetectRenderer(400, 300);
console.log('Is PIXI.WebGLRenderer: ' + (renderer instanceof PIXI.WebGLRenderer));
// add the renderer view element to the DOM
document.body.appendChild(renderer.view);
window.requestAnimFrame( animate );
// create a texture from an image path
var texture = PIXI.Texture.fromImage(baseUri + '/bunny.png');
// create a new Sprite using the texture
bunny = new PIXI.Sprite(texture);
// center the sprites anchor point
bunny.anchor.x = 0.5;
bunny.anchor.y = 0.5;
// move the sprite t the center of the screen
bunny.position.x = 200;
bunny.position.y = 150;
stage.addChild(bunny);
}
it('assets loaded', function (done) {
var loader = new PIXI.AssetLoader([
baseUri + '/bunny.png',
baseUri + '/frame-30.png',
baseUri + '/frame-60.png',
baseUri + '/frame-90.png'
]);
// loader.on('onProgress', function (event) {
// console.log(event.content);
// });
loader.on('onComplete', function () {
done();
initScene();
});
loader.load();
});
it('frame 30 should match', function (done) {
this.timeout(700);
onFrame(30, function () {
var str = renderer.view.toDataURL('image/png');
//console.log('<img src="' + str + '" />');
resemble(str)
.compareTo(baseUri + '/frame-30.png')
.onComplete(function (data) {
expect(data).to.be.an('object');
expect(data.isSameDimensions).to.equal(true);
expect(data.misMatchPercentage).to.be.below(0.2);
done();
});
});
});
it('frame 60 should match', function (done) {
this.timeout(1200);
onFrame(60, function () {
var str = renderer.view.toDataURL('image/png');
//console.log('<img src="' + str + '" />');
resemble(str)
.compareTo(baseUri + '/frame-60.png')
.onComplete(function (data) {
expect(data).to.be.an('object');
expect(data.isSameDimensions).to.equal(true);
expect(data.misMatchPercentage).to.be.below(0.2);
done();
});
});
});
it('frame 90 should match', function (done) {
this.timeout(1700);
onFrame(90, function () {
var str = renderer.view.toDataURL('image/png');
//console.log('<img src="' + str + '" />');
resemble(str)
.compareTo(baseUri + '/frame-90.png')
.onComplete(function (data) {
expect(data).to.be.an('object');
expect(data.isSameDimensions).to.equal(true);
expect(data.misMatchPercentage).to.be.below(0.2);
done();
});
});
});
// it('capture something', function (done) {
// this.timeout(2000000);
// onFrame(30, function () {
// var img = new Image();
// img.src = renderer.view.toDataURL('image/png');
// document.body.appendChild(img);
// });
// });
});