单实例管理图片加载防止重复加载使用导致内存问题
imgDef = {} function getImageByName(name) if (imgDef[name] == nil) then imgDef[name] = UIImage:imageNamed(name) end return imgDef[name]; end
如果涉及图片是retina的 需要吧retina图片分割成不同部分
function splitePNG(img, rect) local scale = img:scale() rect.x = rect.x*scale rect.y = rect.y*scale rect.width = rect.width*scale rect.height = rect.height*scale local cgimage = Game.CGImageCreateWithImageInRect(img, rect) local image = UIImage:imageWithCGImage_scale_orientation(cgimage, scale, 0) puts(img:scale()) return image end