Efficiency for item inventory?

Discussion and feedback on Construct 2

Post » Sat Feb 16, 2013 7:52 pm

Wagwun fellow developers

So I'm currently making an inventory system, but I realised that my method may be very inefficient to the performance of the game.

The general premise of the inventory is that it will be a slot-based system that will be stored via an Array. There will be MANY different items throughout the game that the player can collect, each with their own icon, but the inventory will only display about 16 items at a time.
The amount of items is definitely going to be 100+. Each icon will have the dimensions 32x32.
Now how do I display this and make adding items an easy task...
Hmm..

I have 2 ideas on how to display/create the icons for the items in the Array when I load them

A) (I'm currently doing this) Have all (100+) item icons of the items in one universal sprite called "Items", and name the animation whatever the item is, and display the animation according to what the item should be.

B) Create a separate sprite for each and every icon and add it into a universal family and individually code a "create" function for every object (as you cannot "Create object by name", which is why idea A is excellent, due to being able to choose the animation by name).

Now, I'm thinking that A) would mean that all of the items that exist in the game would be loaded all the time, which wouldn't be too nice on the VRAM. Whereas, B) would only load what is needed (I'm not entirely sure how C2 handles loading stuff)

However, B) is very long-winded and could potentially be BAD perhaps because there would be 100+ individual sprite objects. But A) Would be all self contained.

Thoughts?
Thanks for reading!
B
45
S
19
G
10
Posts: 562
Reputation: 9,543

Post » Sat Feb 16, 2013 8:59 pm

B is definitely not an option. Your fears with A are valid, however, but since these are all just icons, you will be able to make the image sizes relatively small.

I'm fairly sure the whole animation is loaded into memory as C2 forms all animations into a sprite sheet, but another option might be separate animations for each icon. I'm not sure how C2 handles this - could we get a statement @Ashley?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sat Feb 16, 2013 9:30 pm

Thanks very much sqiddster, I feel more confident to work with the A) method now :)

In the universal "Items" sprite, there is lists of animations with just 1 frame for each animation (which is yeah, the icon), and the animation is named after the item (so then I'm able to call it in an event sheet to display the correct item according to what the Array says the item is) and it's doing fine for me, just yeah worried about later on if it might hit the performance. It would really suck if I loaded in 100 odd items then suddenly bam, lag. :P
I guess the straightforward question is literally "Is having loads of 32x32 icons in one sprite a bad idea?"
B
45
S
19
G
10
Posts: 562
Reputation: 9,543


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests