Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Mat Groves http://matgroves.com/
- */
- var PIXI = PIXI || {};
- PIXI.StressTest = function(callback)
- {
- this.callback = callback;
- this.stage = new PIXI.Stage(0x123456);
- this.renderer = new PIXI.CanvasRenderer(500, 500);
- document.body.appendChild(this.renderer.view);
- this.renderer.view.style.position = "absolute";
- this.renderer.view.style.left = "-500px";
- this.duration = 3;
- var scope = this;
- var canvas = document.createElement("canvas");
- canvas.width = 52
- canvas.height = 74
- canvas.context = canvas.getContext("2d");
- canvas.context.fillStyle="#FF0000";
- canvas.context.fillRect(0,0,52,74);
- this.texture = PIXI.Texture.fromCanvas(canvas);
- scope.begin();
- // this.texture.baseTexture.addEventListener( 'loaded', function(){ scope.begin()} );
- this.frameRate = [];
- }
- // constructor
- PIXI.StressTest.constructor = PIXI.StressTest;
- PIXI.StressTest.prototype.begin = function()
- {
- this.testSprites = [];
- for (var i=0; i < 300; i++)
- {
- var bunny = new PIXI.Sprite(this.texture);
- bunny.anchor.x = 0.5;
- bunny.anchor.y = 0.5;
- bunny.alpha = .5;
- this.stage.addChild(bunny);
- bunny.position.x = 50 + Math.random() * 400;
- bunny.position.y = 50 + Math.random() * 400;
- this.testSprites.push(bunny);
- };
- this.renderer.render(this.stage);
- this.startTime = Date.now();
- this.lastTime = Date.now();
- var scope = this
- requestAnimFrame(function(){scope.update()});
- }
- PIXI.StressTest.prototype.update = function()
- {
- var currentTime = Date.now();
- for (var i=0; i < this.testSprites.length; i++) {
- this.testSprites[i].rotation += 0.3;
- };
- this.renderer.render(this.stage);
- var diff = currentTime - this.lastTime;
- diff *= 0.06;
- //diff *= 60;
- this.frameRate.push(diff);
- this.lastTime = currentTime;
- var elapsedTime = currentTime - this.startTime;
- if(elapsedTime < this.duration * 1000)
- {
- var scope = this
- requestAnimFrame(function(){scope.update()});
- }
- else
- {
- document.body.removeChild(this.renderer.view);
- this.renderer = null;
- this.result = this.frameRate.length/this.duration;
- if(this.callback)this.callback(this.result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement