在Processingjs Canvas 元素中实现预加载器

发布于 2024-10-03 05:42:25 字数 127 浏览 8 评论 0原文

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

两种情况 - 资产已加载,但 js 仍在计算/渲染视图;资产尚未

加载有人创建了processingjs 标签!代表数为 1500 的用户还不能这样做:(

How do you implement a preloader for a processingjs canvas element?

Two cases - assets have loaded, but js still calculating/rendering the view; assets have not loaded

P.S. Someone create the processingjs tag! Users with rep lt 1500 can't do that yet :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深巷少女 2024-10-10 05:42:25

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

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");
})

May be this very old snippet helps you, after loading all images a callback is called. The folder param was used to load low or highres pics.

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");
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文