美文网首页
Pixi.js 基础知识(二)

Pixi.js 基础知识(二)

作者: 已注销null | 来源:发表于2016-11-09 20:49 被阅读0次

    参考:
    https://github.com/kittykatattack/learningPixi

    使用 aliases 来简化代码

    //Aliases
    var Container = PIXI.Container, 
        autoDetectRenderer = PIXI.autoDetectRenderer, 
        loader = PIXI.loader, 
        resources = PIXI.loader.resources, 
        Sprite = PIXI.Sprite;
    
    var stage = new Container(), 
        renderer = autoDetectRenderer(256, 256);
    document.body.appendChild(renderer.view);
    
    loader 
      .add("images/cat.png") 
      .load(setup);
    
    function setup() { 
    var cat = new Sprite(
      resources["images/cat.png"].texture
    ); 
    
    stage.addChild(cat); 
    renderer.render(stage);}
    

    加载进程

    PIXI.loader 
      .add(
        [ "images/one.png",
          "images/two.png", 
          "images/three.png" ]
    ) 
      .on("progress", loadProgressHandler) 
      .load(setup);
    
    function loadProgressHandler(loader, resource) { 
      console.log("loading: " + resource.url); 
    
      console.log("progress: " + loader.progress + "%"); 
    
      console.log("loading: " + resource.name);
    }
    
    function setup() { 
      console.log("All files loaded");
    }
    
    /*
      loading: images/one.png
      progress: 33.333333333333336%
      loading: images/two.png
      progress: 66.66666666666667%
      loading: images/three.png
      progress: 100%
      All files loaded
    */
    

    相关文章

      网友评论

          本文标题:Pixi.js 基础知识(二)

          本文链接:https://www.haomeiwen.com/subject/pmstpttx.html