CreateJSでfilterを使う

ハマったので備忘録としてメモ


var bounds = target.getTransformedBounds();

//何度もfilterを変更する場合は先にcacheをしておく
target.cache(bounds.x, bounds.y, bounds.width, bounds.height);



var matrix = new createjs.ColorMatrix().adjustBrightness(-80);
target.filters = [
  new createjs.ColorMatrixFilter(matrix)
];

//cacheがアップデートされないとfilterが反映されないのでupdate
target.updateCache();


targetはDisplayObjectを親としているものであればOK!(Bitmapはもちろん、MovieClipなど...)

1回しかfilterをかけない場合は、filtersを設定したあとに


target.cache(bounds.x, bounds.y, bounds.width, bounds.height);

をやってあげれば良いが、変更を何度もしたい場合は最初にcacheしておいて変更するたびにupdateCache()しないとうまくいかないので注意