cocos2d iphone - Updating a CCTexture2D from a BatchNode -
after completed testing, have moved images on spritesheet.
i loaded batchnode appropriate files , images load fine.
but running issue of swapping textures out. when images individual files, there no problem. seems cctexture2d doesn’t sprite sheet.
i have objects stored in multidimensional array, can run through them , update image.
here did when worked:
cctexture2d* tex = [[cctexturecache sharedtexturecache] addimage:@"alt-image.png"]; [((myfunobject*)[[myfunobject2darr objectatindex:j]objectatindex:i])->img settexture: tex];
here doing now:
cctexture2d* tex = [[cctexturecache sharedtexturecache] addimage:[ccsprite spritewithspriteframename:@"alt-image.png"]]; [((myfunobject*)[[myfunobject2darr objectatindex:j]objectatindex:i])->img settexture: tex];
myfunobject subclass of ccsprite
, has ccsprite
img property set. run through array , find objects , replace image new image “alt-image.png”.
seems simple, outside of sprite sheet worked flawlessly.
can tell me doing wrong?
update: here solution in future has issue
you can't change sprites 'texture' when texture in question spritesheet. (slapped head on one) can change rectangle viewed.
here how it:
[((myfunobject*)[[myfunobject2darr objectatindex:j]objectatindex:i])->img settexturerect:[[ccspriteframecache sharedspriteframecache] spriteframebyname: @"alt-image.png" ].rect];
notice changed settexture
settexturerect
, called spriteframe's rectangle argument.
enjoy.
Comments
Post a Comment