2017-05-30 91 views
0
var adobe1bar1; 
function preload() { 
    adobe1bar1 = loadImage("1-1.png"); 
} 
function setup() { 
    createCanvas(500, 500, WEBGL); 
    center = createVector(width/2, height/2, height/2); 
    cameraZ = -500; 
} 
function draw() { 
    background(40); // backgraound white 
    var cameraX = map(mouseX, 0, width, -500, 500); // map 
    var cameraY = map(mouseY, 0, height, -500, 500); 
    console.log(cameraY, cameraX); 
    if (cameraZ < -500) { 
    cameraZ = -500; 
    } 
    if (cameraZ > 0) { 
    cameraZ = 0; 
    } 
    camera(center.x + cameraX, center.y + cameraY, center.z + cameraZ, center.x, center.y, center.z, 0, 1, 0); 
    translate(center.x, center.y, center.z); 
    translate(0, 0, 0); 
    image(adobe1bar1, -250, -250, 500, 500); 
} 

這是我的p5.js代碼。p5.js this._renderer.image不是功能問題

當我使用image() function 以下錯誤消息不斷出現。

Uncaught TypeError: this._renderer.image is not a function

有沒有解決方案?

當不使用「WEBGL」, 它上傳圖片沒有錯誤, 但camera()功能不起作用。

+0

你能編輯在控制檯中出現錯誤的堆棧跟蹤問題?它似乎錯誤不是來自您發佈的代碼 –

回答

0

圖像不是一個WEBGL功能。

嘗試將圖像紋理應用於平面。

texture(adobe1bar1); 
translate(-250, -250, 0); 
plane(500); 

https://github.com/processing/p5.js/wiki/Getting-started-with-WebGL-in-p5

編輯: 要使用透明的質感,你需要啓用混合模式,它可以通過使用來完成:

fill(0,0,0,0); 

在設置

+0

我如何在紋理()上使用png圖像(透明圖像)? – JuneNan

+0

@JuneNan這聽起來像是一個單獨的問題。請將它發佈在一個新的問題帖子中,同時更新[mcve]。 –