[Solved] Load Object as needed

Hi :wink:

Is there a way to load an object into a scene as needed?

For example, my player sprites consists of about forty images right now, and I’d like to allow the player to choose between characters at the beginning of the game. Right now I’d put sprite objects for all characters onto the scene, and show only the one selected, but this means I waste resources.

Thinking about having f.e. different visible upgrades like armour, which would need to be drawn for every frame too would lead to quickly escalating resources, for example:

Every character has 40 frames, Armours and Weapons too to fit accordingly:
[3 Characters] * ( [3 Armours] + [4 Weapons] ) * [40 Images] = 840 Images

This would load 21 Sprite Objects, of which only three are shown, in effect loading 18 objects with about 720 images only to have them turned hidden by default… so, is there some way to load only those three I need?

Thanks in advance and all the best,

Hey i hope this help :

  1. Create a scene that display the sprites(character) which the player can pick with
  2. each sprite has its own name that is connected to global variable (selectedCharacter)
  3. On the game scene events, “at the start of the game”- “create object based on the global variable name that the player select”.

Forgive me if it’s seems rather confusing.
For the modular part, i guess you can try to learn about “parent-child pin”.

I suggest you create presets of characters that the player can select first. and once you feels happy with the result continue with the modular part.

I hope i’m not pointing on the wrong direction. :slight_smile: CMIIW

Thank you Esdeepee :smiley:

Today I’m not at home, but I will try it tomorrow. If it works I’ll confirm :slight_smile:

Update: Worked like a charme, only the object needs tot be a global one.