使用帧编号在spritesheet中查找行/列

时间:2013-01-26 16:25:25

标签: javascript

假设我有精灵表,我知道有4列精灵和n行。那么我如何找到特定帧的行/列呢?

我试过了:

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);
    }

对于frame 7它完美无缺,提供Row:2 Col:3,但对于frame 8,它给出了Col:0,有没有办法让它给4,没有三元组条件检查在那里?

1 个答案:

答案 0 :(得分:0)

行和列应从零开始,(0,0)为左上角。移除+1行上的row,然后您就可以将坐标乘以帧大小。