Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PIXI.js how can I increase the brightness of a sprite?

Tags:

pixi.js

I have a sprite created through new PIXI.Sprite.fromImage(path), how can I increase the brightness of it in realtime?

like image 816
Julio Rodrigues Avatar asked Apr 02 '14 12:04

Julio Rodrigues


1 Answers

You can do this using the PIXI ColorMatrixFilter:

var colorMatrix =  [
    1,0,0,0,
    0,1,0,0,
    0,0,1,0,
    0,0,0,1
];
var filter = new PIXI.ColorMatrixFilter();
filter.matrix = colorMatrix;
stage.filters = [filter];

Darker:

var colorMatrix =  [
    1,0,0,-0.5,
    0,1,0,-0.5,
    0,0,1,-0.5,
    0,0,0,1
];

Lighter:

var colorMatrix =  [
    1,0,0,0.5,
    0,1,0,0.5,
    0,0,1,0.5,
    0,0,0,1
];

See a quick demo here: http://codepen.io/ianmcgregor/pen/LcjBw

like image 185
imcg Avatar answered Sep 28 '22 11:09

imcg