HowTo: load Images from a Spritesheet and put the images inside an array

cocos2dx v2.2.5

I have a spritesheet “letters.png” with it’s “letters.plist”.
it contains sprites named “sprite1.png”, “sprite2.png”, “sprite3.png”. you get the idea, the number is the only distinguishing factor (so i can use it in a loop later)

Now what I want to do is load all this sprites inside an array, then display them, so I can just do something like these:

i’ll just use Lua format so you have an idea;
this is the pseudo code…

local myTable = {}
for i=1; i <= 3; i++

  myTable[i] =  sprite%i.png, i                  ('load the images from spritesheet inside this array as objects and display them on the screen')
 myTable[i].x, myTable[i].y = i * 50, 10
 myTable[i]:addTouch Events()        ('add a touch event to each object' (i dont know how))

end

hope you understand what i’m trying to do :smiley:

once you have loaded the images to the sprite cache with

SpriteFrameCache::getInstance()->addSpriteFramesWithFile("spriteSheetName.plist");

you can access them by just using

SpriteFrameCache::getInstance()->getSpriteFrameByName("spritename.png");

P.S.: if you really want to use the array, I would recommend to use an array of char *, (or string - what suits you better) just with the sprite names and retrieve them from the cache with the code line above. but you dont really need to create an array of images once they are in cache.

Hope it helps :wink:

im trying to recreate this one. . I have already made a clone of this using Corona SDK, but Im having a hard time to do it using Cocos2d-x (im a newbie and dnt have complete grasp of OOP)

every level the letter buttons changes, in Corona SDK, i use an array to handle that. . Does anyone have a tutorial code on this one (4pics 1 Word Game)???

did you figured out how to handle the images from the cache?

i dont think you’ll find a tutorial of this specific game, but if you point out the issues you’re having, I may be able to help you :blush:

You have posted this in I think 3-4 different topics. Can we consolidate to a single topic, please? I wrote you a reply in your other topic as well.

i have just learned how to access files from a plist and we’ll be working on this one now. . anyone who wants to collaborate? :smile: I could surely share the spotlight with someone (: