Skip to content

Commit

Permalink
Fixes for v4 and v5
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Jul 19, 2019
1 parent 8e3f5a2 commit 99d3a29
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
53 changes: 27 additions & 26 deletions src/BunnyMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,26 @@ BunnyMark.prototype.ready = function(startBunnyCount)
options.powerPreference = this.value;
});

if (PIXI.autoDetectRenderer) {
this.renderer = PIXI.autoDetectRenderer(
this.bounds.right,
this.bounds.bottom,
options
);
Object.assign(options, {
width: this.bounds.right,
height: this.bounds.bottom,
});

// Add fewer bunnies for the canvas renderer
if (this.renderer instanceof PIXI.CanvasRenderer)
{
this.amount = 5;
this.renderer.context.mozImageSmoothingEnabled = false;
this.renderer.context.webkitImageSmoothingEnabled = false;
}
try {
this.renderer = PIXI.autoDetectRenderer(options);
}
// Support for v5
else if (PIXI.Renderer) {
this.renderer = new PIXI.Renderer(
this.bounds.right,
this.bounds.bottom,
options
);
catch(err)
{
alert(err.message);
return;
}

// Add fewer bunnies for the canvas renderer
if (PIXI.CanvasRenderer && this.renderer instanceof PIXI.CanvasRenderer)
{
this.amount = 5;
this.renderer.context.mozImageSmoothingEnabled = false;
this.renderer.context.webkitImageSmoothingEnabled = false;
}

// The current stage
Expand All @@ -157,14 +155,17 @@ BunnyMark.prototype.ready = function(startBunnyCount)

// Get bunny textures
this.textures = Resources.map(function(a){
return PIXI.Texture.fromImage(a, null, 1);
return PIXI.Texture.from(a);
});

var gl = this.renderer.gl;
this.textures.length = Math.min(
gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS),
this.textures.length
);
if (this.renderer.gl)
{
var gl = this.renderer.gl;
this.textures.length = Math.min(
gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS),
this.textures.length
);
}

// Create the sounder
this.counter = $("#counter");
Expand Down
13 changes: 10 additions & 3 deletions src/VersionChooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ var VersionChooser = function(domElementSelector)
this.timeout = null;

/**
* Path for loading PIXI from the CDN
* Path for loading PIXI from the CDN, v5+
* @type {String}
*/
this.cdnTemplate = '//d157l7jdn8e5sf.cloudfront.net/${tag}/pixi.js';
this.cdnTemplate = '//pixijs.download/${tag}/pixi-legacy.min.js';

/**
* Path for loading PIXI from the CDN, v4 and below
* @type {String}
*/
this.cdnTemplate4 = '//pixijs.download/${tag}/pixi.min.js';

/**
* The input for bunny count
Expand Down Expand Up @@ -198,7 +204,8 @@ VersionChooser.prototype.displayTags = function()
VersionChooser.prototype.start = function(tag)
{
var script = $('<script></script>');
var src = this.cdnTemplate.replace('${tag}', tag);
var template = tag.indexOf('v4') === 0 ? this.cdnTemplate4 : this.cdnTemplate;
var src = template.replace('${tag}', tag);
script.prop('src', src);

this.addScript(script);
Expand Down

0 comments on commit 99d3a29

Please sign in to comment.