xcode - Help loading a texture in a variable in Objective-C -


i have "ball" sprite changes it's texture when scenario occurs. change it's texture this:

[ball settexture:[[cctexturecache sharedtexturecache] addimage:@"red.png"]]; 

this work; changes ball sprite use red.png image. how handle if have 20 balls need switch using sprite? run through each ball , "addimage"?

if could, load texture once, save in variable (called "redtexture"), , able assign of ball objects.

any advice on how approach huge help, thank you!

if put statement inside, say, loop, you'd adding red.png image shared texture cache on , on again, doubt want.

let's , re-write things bit, starting adding red.png image shared texture cache, on line itself:

[[cctexturecache sharedtexturecache] addimage:@"red.png"]; 

you'd subsequently same texture again calling [cctexturecache sharedtexturecache]. until add image shared texture cache, is.

cctexturecache singleton, , docs don't suggest there's way make copy of shared texture cache (which ideal preserving redtexture). being case, create variable , point @ [cctexturecache sharedtexturecache]; careful not add other images before you're done it:

cctexturecache *redtexture = [cctexturecache sharedtexturecache]; 

now let's assume have array (or mutable array) called ballarray, contains 20 ball objects. loop through them this:

for (yourballobject *ball in ballarray) {     [ball settexture:redtexture]; } 

or better, this:

[ballarray makeobjectsperformselector:@selector(settexture:) withobject:redtexture]; 

good luck in endeavors.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -