Refractor spritesheet code