Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <p><a class="link" href="https://naruhodo.repop.jp/javascript-createjs-image-load/" target="_blank">CreateJS Image Load | なるほど。</a></p>
<canvas id="main" width="500" height="300"></canvas>
              
            
!

CSS

              
                .link{
padding:5px;
text-decoration:none;
}
              
            
!

JS

              
                //ファイル情報の保存先
let images = [];

function lorder(){

 //manifestに読み込むファイルを指定
let manifest=[
{src:"https://naruhodo.repop.jp/wp-content/uploads/2018/01/kitarou.png",id:"kitarou"},
{src:"https://naruhodo.repop.jp/wp-content/uploads/2018/01/medamaoyaji.png",id:"medamaoyaji"}
];

let loader = new createjs.LoadQueue(false);
   //読み込むmanifestを指定
    loader.loadManifest(manifest,true);
   //個別ロード中の処理をfileload関数に定義
    loader.addEventListener("fileload", fileload);
   //全てのファイルロード完了後の処理をcomplete関数に定義
    loader.addEventListener("complete", complete);
  
  function fileload(event){
    //ファイルの種類が画像だった場合に配列imageに格納
  if (event.item.type == "image"){
    images[event.item.id] = event.result;
  }
}

  //ファイルロードが完了したらfileloadとcompleteを削除してinit()を実行
function complete (event) {
event.target.removeEventListener("fileload",fileload);
event.target.removeEventListener("complete",complete);
init();
}
}

function init() {
//canvas id mainをstageに設定
let stage = new createjs.Stage("main");
//背景にする四角形を作成
let bg = new createjs.Shape();
//背景にする四角形の色と位置・サイズを指定
bg.graphics.beginFill("black").drawRect(0, 0, 500, 300);
//背景にする四角形をstageに追加
stage.addChild(bg);

//画像を定義して配置
let kitarou = new createjs.Bitmap(images["kitarou"]);
stage.addChild(kitarou);
kitarou.x = 50;
kitarou.y = 50;
kitarou.scaleX = 0.2;
kitarou.scaleY = 0.2;

//画像を定義して配置
let medamaoyaji = new createjs.Bitmap(images["medamaoyaji"]);
stage.addChild(medamaoyaji);
medamaoyaji.x = 300;
medamaoyaji.y = 160;
medamaoyaji.scaleX = 0.1;
medamaoyaji.scaleY = 0.1;
  
//stageを更新
stage.update();
}

//lorderを実行
lorder();
              
            
!
999px

Console