【问题标题】:Implementing a Preloader in Processingjs Canvas element在 Processingjs Canvas 元素中实现预加载器
【发布时间】:2011-05-12 18:21:45
【问题描述】:

如何为 processingjs 画布元素实现预加载器?

两种情况——资产已经加载,但是js还在计算/渲染视图;资产尚未加载

附:有人创建了 processingjs 标签! rep lt 1500 的用户还不能这样做:(

【问题讨论】:

    标签: javascript html canvas processing processing.js


    【解决方案1】:

    可能是这个非常古老的 sn-p 可以帮助您,在加载所有图像后调用回调。文件夹参数用于加载低或高分辨率图片。

    pics = {
      'Trans100'    : "trans100.png",
      'Trans101'    : "trans101.png",
      'TransPanel'  : "transPanel.png"
    }
    
    function oAttrs(o) { var a, out = ""; for (a in o){ out += a + " ";} return trim(out);}
    
    function imageLoader(pics, folder, onready){
      this.nextPic  = 0;
      this.pics     = pics;
      this.folder   = folder;
      this.names    = oAttrs(pics).split(" ");
      this.onReady  = onready;
      this.loadNext();
    }
    
      imageLoader.prototype.loadNext = function (){
        if (this.nextPic === this.names.length) {
          this.onReady();
        } else {
          this.loadImage(this.pics[this.names[this.nextPic]]);
        }
      };
    
      imageLoader.prototype.loadImage = function (file){
        this.nextPic += 1;
        var pic       = new Image();
        pic.onload    = this.loadNext.bind(this);
        pic.onerror   = function(){console.error("ERROR: " + file);};
        pic.src       = this.folder + file;
      };
    
    
    // example: 
    
    new imageLoader(pics, "images", function(){
      console.log("Images loaded");
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多