ios - Using imageWithContentsOfFile: to load textures in spritekit -
ios - Using imageWithContentsOfFile: to load textures in spritekit -
so, noticed recommendation in 1 of discussions here. says in order release memory 1 time done textures, possible solution next:
create uiimages +imagewithcontentsoffile: create sktextures resulting uiimage objects calling sktexture/+texturewithimage:(uiimage*).i have memory issues comes high res backgrounds , few embedded scroll views, tried above implementation - , works in terms of memory.
the problem looks when doing so, imagewithcontentsoffile: in retina devices, scales @2x image 2, need explicit scale 1 time again 0.5.
how can ensure right scaling when calling method?
here code:
nsstring *path = [[nsbundle mainbundle] pathforresource:@"sc_01_bg" oftype:@"png"]; uiimage *img = [uiimage imagewithcontentsoffile:path]; skspritenode *backgroundsprite = [skspritenode spritenodewithtexture:[sktexture texturewithimage: img]];
actually, there upvote on answer, , upvote mine. can't remember why have upvoted answer, because i've never experienced such problem.
if still want utilize approach stated in answer, should utilize [uiimage imagenamed:@"imagename"]
instead of [uiimage imagewithcontentsoffile:path]
. probably, uikit doesn't automatically handle retina/non-retina images imagewithcontentsoffile:
method.
but don't need that. check learncocos2d's reply question.
ps: free memory have been used skscene
call
[self.skview removefromsuperview]; self.skview = nil;
ios uiimage sprite-kit
Comments
Post a Comment