pixijs: cacheAsBitmap and filters bug
There is bug with caching filtered object if it is some out of screen. For example, we have sprite width=100, height=400 with coords x = 100, y = -50. It is -50 pixels out of screen. If it has filter and cacheAsBitmap, there will be wrong output. PIXI version is 5.1.5 Code sample:
app = new PIXI.Application({
width: 210,
height: 400,
listening: false
});
document.body.appendChild(app.view);
points = Array();
points.push(10,10);
points.push(100,10);
points.push(100,200);
points.push(10,400);
var container = new PIXI.Container();
var sprite = new PIXI.Sprite();
var graphics = new PIXI.Graphics();
app.stage.addChild(container);
container.addChild(sprite);
sprite.addChild(graphics);
graphics.lineStyle(2, 0xffffff);
graphics.beginFill(0xFF3300);
graphics.moveTo(points[0], points[1]);
for (var l=2;l<points.length;l+=2) graphics.lineTo(points[l], points[l+1]);
graphics.lineTo(points[0], points[1]);
var graphics2 = new PIXI.Graphics();
graphics2.lineStyle(2, 0xffffff);
graphics2.beginFill(0xFF3300);
graphics2.moveTo(points[0], points[1]);
for (var l=2;l<points.length;l+=2) graphics2.lineTo(points[l], points[l+1]);
graphics2.lineTo(points[0], points[1]);
app.stage.addChild(graphics2);
var blur_filter = new PIXI.filters.BlurFilter(0.5, 1);
blur_filter.repeatEdgePixels = true;
graphics.filters = [blur_filter];
graphics.y = -100;
graphics.x = 100;
container.cacheAsBitmap = true;
app.renderer.render(app.stage);
setInterval(function () {
container.cacheAsBitmap = false;
if (!graphics.filters) graphics.filters = [blur_filter]; else {graphics.filters = null;graphics.y += 5;};
container.cacheAsBitmap = true;
if (graphics.y>10)
{
graphics.y = -100;
}
}, 1000);
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 16 (4 by maintainers)
You can try my
CacheContainer. It has better compatibility with filters and andpixi-layersthancacheAsBitmap. It depends on this PR though, or filter padding will get ignored and thus cropped: https://github.com/pixijs/pixi.js/pull/6306Create a container, add your stuff to it and call
updateCache(true)once to enable caching, then call it again whenever the cache should be updated.@laino
Absolute legend! Just wanted to thank you for this solution!