I have a problem with my arrays. I create them (which I’m not sure is correctly designed) but having difficulty understanding how to do checks on it.
My array is created like this:
id = i++;
uid = my_id;
imgwidth = img[0].width;
imgheight = img[0].height;
spritea[uid] = new Array();
spritea[uid][0] = abposx;
spritea[uid][1] = abposy;
spritea[uid][2] = imgwidth;
spritea[uid][3] = imgheight;
I’m only assuming this is the correct way to store information about an image’s position and give it a unique id.
I then want to do checks on the follow example criteria:
if (x > spritea[0] && x < spritea[0]+spritea[2]){
var uid = //get the UID of the array ;
}
But i think i have structured my array wrong? Any advice?
Use an object. It’s cleaner:
For searching, try this: