2010-11-19 3 views
1

processingjs 캔버스 요소에 대한 프리 로더를 어떻게 구현합니까?Processingjs 캔버스 요소에 프리 로더 구현

두 가지 경우 - 애셋이로드되었지만 여전히 뷰를 계산/렌더링하는 경우. 애셋이로드되지 않았습니다.

P.S. 누군가 processingjs 태그를 만듭니다! 담당자 LT 1500 사용자는이 아주 오래된 조각이 콜백이라고 모든 이미지를로드 한 후. 폴더 PARAM이 낮거나 highres 있습니다 사진을로드하는 데 사용했다, 당신을 도와줍니다

답변

0

될 수 있습니다 아직 :(할 수 없습니다.

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