i need to store a sprite in an array but i am not sure how to do it. does anyone have an example or know where to find one?
thanks
A fast, easy to use, free, and community supported 2D game engine
i need to store a sprite in an array but i am not sure how to do it. does anyone have an example or know where to find one?
thanks
Why not use an NSArray or NSMutableArray?
self.mySpriteArray = [NSMutableArray arrayWithCapacity:2];
[mySpriteArray addObject:mySprite];
[mySpriteArray addObject:myOtherSprite];
nice that worked thank you. but what is the difference between NSArray and NSMutableArray? just for future reference
A mutable array will let you store different object types in the same array. NSArray can only store one type of object. Someone correct me if I am wrong!
Sorry but that is not correct, the difference between them is that NSArray can hold a certain amount of elements (once created you can not add or remove elements), where NSMutableArray can hold any amount of elements and have them removed or added, you could have it hold 5 elements then make it hold 500.
But you can have them both hold any kind of objects.
could you also store it as like below?
AtlasSprite *sprtArray[10];
Ahh...my bad. I was confusing regular C arrays with Objective-c arrays. Thanks for the clarification pablo!
Thom, I think you would be creating a C array there, not an objective-c NSArray. But it still may work for what you are trying to do.
-Sunsu
thanks sunsu. Im a oldtimer from C days, still trying to get upto speed with obc-c.
Oh I completely understand. I have much more experience with C. I'm beginning to get the hang of objective-c, but I have a lllootttt more to learn (as you can see from all the stupid questions I ask on this forum!).
Yes, you can also use regular c arrays, *but* then you have to do more memory management yourself. When you add an object to an NSArray or NSMutableArray, the object getting added will be retain'ed and when you remove an object from an NSMutableArray it gets release'd. If you use a c or c++ array you will need to do the retain and release yourself.
"Mutable" just means changeable. So an NSArray has a fixed number of objects at creation which cant be changed. And an NSMutableArray can have objects added and removed.
You must log in to post.