The inventory is the UI that shows your current inventory items, and allows you to use them. It is located in the scene file ui/inventory.scn. The inventory will show items from a scene that contains all the items in your game. Items can be shown in multiple pages.
The requirements of the inventory scene are as follows:
Here's ui/inventory.scn with a custom basket background:
The items element, set invisible by default, links back to the default inventory scene game/inventory_item.scn where we previously added all the pickable inventory items:
game/inventory_items.scn needs to be customized to add all the items of your game as children of a root Node2D node. The items must be fully functional Items, configured with their properties, sprite, script file, etc. For this type of item, usually a TextureButton is used with the globals/item.gd script attached to it, although any other type of item can be used. You can read The Items chapter for details.
For inventory items specifically, remember to tick the Use Combine property.
The inventory scene is a child of hud.scn which is a child of game.scn. So it should be made available automatically in your game once game.scn in imported to your main scene. Refer to our Create your scene chapter to see how to do it.
Now that the inventory is ready as a UI element visible to the user, it will be necessary to define how to use it. This will be done with an Esc script description. Generally, adding an element to the inventory will be made from a pick_up action. During this action we generally have to :
The script could look like the example we use in our intro game:
:pick_up > [!picked_item] set_global i/inv_good_bamboo true set_active good_bamboo false
Note that, since we add items to the inventory, we can use the global flag corresponding to the item to check if the user has it:
> [i/inv_good_bamboo] # user has the good bamboo
Generally, using an inventory item will be processed by a :use action:
:use inv_good_bamboo
and you will probably need to unset all the necessary globals, conversely to the pick up action.
Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.
Vous devriez rafraîchir la page.