Hi! I’ve been playing with WebGL for some time and I get stuck in a weird issue. I got a JSON file defining the position and src-image-for-texture for multiple elements. I load the positions in a ‘elementPositions’ array and the src-images in a ‘elementImageSrcs’ array. Then I have a ‘elementTextures’ array where I create all textures.
The problem comes when I try to initTextures() using the following line:
for (var i=0; i < numElements; i++) { elementTextures[i] = loadTexture(elementImageSrcs[i]); }
It just doesn’t work; it seems loadTexture() doesn’t like elementImageSrcs[i].
I’ve spend nearly two days trying to realize what could be the problem but I didn’t find the answer (maybe the JSON loading? maybe my limited knowledge of JavaScript?). Anyone knows what I’m doing wrong?
function initElements() {
var request = new XMLHttpRequest();
request.open("GET", "elements.json", false); // false means not asynchronously
request.send(null);
if (req.status == 200) {
var jsonData = JSON.parse(request.responseText);
for (var i=0; i < numElements; i++) {
elementPositions[i] = jsonData.elements[i].position;
elementImageSrcs[i] = jsonData.elements[i].imagesrc;
}
}
}