Let’s say I have sprite sheet, and I know there are 4 columns of sprites, and n number of rows. So how will I find the row/column of a particular frame?
I tried:
function drawSprite(num){
var row = Math.floor(num/col_count)+1;
var col = parseInt(num%col_count); // forget about parseInt for now
console.log("Row:"+row+" Col:"+col);
}
for frame 7 it works perfectly, giving Row:2 Col:3, but for frame 8, it gives Col:0, is there a way to get it to give 4, without a ternary condition checking in there?
Rows and columns should be zero-based, with
(0,0)being the top-left corner. Remove the+1on therowline, then you’ll be able to multiply the coordinates by the frame size.