How to create an Inventory in a game dependent on what items the user obtains
I need to create a view with images that appear depending on what items the user obtains. Basically, the view is empty, then the user obtains an item and that item appears at say, (20, 44,) then they obtain a second item and that item appears at (120, 44) and it continues on in designated positions. And I also need to add a button over each item depending on what image is placed there. I thought maybe I could use an array with each individual item having it's own x,y value, and just push items in th开发者_StackOverflow中文版e array according to what they get. But I am not sure how to do that. Could someone please help me? It would be infinitely appreciated.
You can add items to an NSMutableArray with addObject:
(which puts the object at the end of the array) or insertObject:atIndex:
(which puts the object at the designated index). That seems to be the only part of your plan you were unclear on.
Also, if the item's position can be calculated from its index in the array, there's no need to store it. You can just make a function to calculate it and call that whenever you need to draw.
精彩评论