
function setSpriteFromDef(ent, row, col, registerBottom)

   local texName = ent:getTexture();
   local defs = spriteDefs[texName];

   if defs then

      local rs = defs[row][col];

      local scale = ent:getSpriteScale();

      ent:setSpriteFrame(rs[1], rs[2], rs[3], rs[4]);
      ent:setSize(scale * (rs[3] - rs[1]), scale * (rs[4] - rs[2]));
      if not (rs[5] == -1) and not (rs[6] == -1) then
         
         if registerBottom then
            ent:setSpriteBottomCenter(rs[5], rs[6]);
         else
            
            local ax, ay;
            
            -- Get the current center.
            ax = rs[1] + (rs[3] - rs[1]) / 2;
            ay = rs[2] + (rs[4] - rs[2]) / 2;
            
            -- Get the offset from that center.
            local dx = ax - rs[5];
            local dy = ay - rs[6];

            ent:setSpriteOffset(-dx, dy);
            
         end

      end
   
   else
   
      writeConsole("Error: No defs for texture: "..texName.."\n");
   
   end

end
