Answer the question
In order to leave comments, you need to log in
Get area in texture atlas solely by its id?
Good day.
There is an atlas of textures of a certain size (128x128 for example), on which sprites of the same size (32x32) are located, for a total of 16 sprites.
Is there any way to get the correct X and Y offset using only the X offset?
I tried to do like this:
if (indexTile * 32)>= y * 128)
{
y+=1;
}
Рисовать(indexTile * 32, y * 32);
Answer the question
In order to leave comments, you need to log in
function getCoordByNumber(n, width, heigth, totalWidth, totalHeigth){
if(n == 0) return {x:0,y:0};
var nx = ~~(totalWidth/width);
var ny = ~~(totalHeigth/heigth);
return {
x:(n%nx)*width,
y:(~~(n/ny))*heigth
};
}
console.log(getCoordByNumber(/*номер текстурки*/9, 32, 32, 128, 128));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question