Hey guys, sorry for this topic, but I’m trying to create a system to randomly select an image to generate a sprite, but I can’t figure out how to do that here is my code:
If all your Color objects will have the same list of strings, you probably want to use a static const String* variable. The way I would do it is declare in the Color header file,
class Color {
private:
...
static const String* spriteC[2];
...
};
Hopefully that works. I’m a little rusty on arrays in C++ and I’m testing this code in cocos v2. C++ is a little daunting at the start, especially if you don’t learn the basics first, but I like it
Yeah, std string is what I use. Suppose I should have said that, but he mentioned cocos2d::String so I went with it.
I think a vector would be overkill, because I imagine he won’t be modifying it at runtime. Perhaps a std list would be better for his purposes; definitely a vector if he wants to dynamically change the list.
Thanks for the suggestions guys, well first of all grimfate, you where almost right about what I was trying to do, but the declaration String* was deprecated, I had to use __String *ArrayName, it worked, but now, I’m still stuck cause I’m trying to call one of those array elements but I’m always getting an error, here is the code now:
I just assumed an immutable list would be more efficient than a mutable vector, as the latter would have functions unnecessary for a static list, but I did look online and found that you can’t reference by index with a list, which makes it more annoying.
Surely there is a type of object that simply contains a immutable list of objects, a function for getting the size of the list and a function to access the objects by index.
And yeah, I am probably being a little too picky about efficiency when the array will be rather small in size haha