7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CreateJSでcanvasに読み込んだ複数画像をまとめて処理する方法

Posted at

CreateJSを用いてcanvasに読み込んだ複数画像をまとめて処理する方法です。
複数のBitmapオブジェクトをまとめるのに、Containerクラスを使用します。
こちらの応用編

javascript
window.onload = function(){

	var stage = new createjs.Stage('canvas');
	
	// 複数のオブジェクトをまとめるコンテナを生成
	var container = new createjs.Container();
	stage.addChild(container);
	
	var queue = new createjs.LoadQueue();
	
	queue.addEventListener('fileload', function(e){
		if(e.item.type === createjs.LoadQueue.IMAGE){
			var bitmap = new createjs.Bitmap(e.result);
			// コンテナにaddChildする
			container.addChild(bitmap);
		}
	});
	
	queue.addEventListener('complete', function(e){
		// コンテナのalphaを0.5にする
		container.alpha = 0.5;
	});
	
	queue.loadManifest([
		{id: 'image_1', src: 'images/image_1.png'},
		{id: 'image_2', src: 'images/image_2.png'},
		{id: 'image_3', src: 'images/image_3.png'},
		{id: 'image_4', src: 'images/image_4.png'},
		{id: 'image_5', src: 'images/image_5.png'}
	]);
	
	createjs.Ticker.setFPS(30);
	createjs.Ticker.addEventListener('tick', function(){
		stage.update();
	});

}

全ファイルの読み込みが完了した時点で、Containerオブジェクトのalpha値を変更すると、内包されているBitmapオブジェクトのalpha値がまとめて変更されました。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?