I’m making an inventory system and want to know how I could put a sprite of a sprite object on another sprite object. How could I do this?
Hi, maybe some forum members know exactly what you want to do, but there might be others - including me - who have no idea. In Gdevelop a sprite is by itself an object and it does not belong to another object unless you set it up accordingly (e.g. ‘hitbox-sprite’ and 'animation-sprite etc.). So what do you mean by object?
Unless I’m misunderstanding you, there are no sprites without objects.
If you want to place a background or a character sprite, you have to place a sprite object (Or tiled sprite, or 9patch, etc) for it to be displayed. You can also create it via events, but there still must be an object with the sprite, even if it’s not added to the scene.
I think you should provide some more context. Are you trying to add images to an object at runtime or are you trying to pin a sprite object to an other sprite object. What are you trying to do?
To pin an object to an other is possible using:
- “Put an object around an other object” event
- Using image points and set the position of one object to be always at the position of the point.
- You can also free to implement your own Pin function using Math expressions.
To pin objects to an other, there is an example included with GDevelop here:
Next time you may want to post a new reply because people don’t get notified if you edit the original post.
One way to do it is to have both objects (Item and Slot) the same animation names and then you can set the animation of the Slot object to be the same as the Item using the expression
Set animation of Slot to Item.AnimationName()
If you prefer, you can also store the name of the item in an object variable say objectName and make the name correspond with the animation name of the slot animations and then you can set the animation of the slot using variable like so
Set the animation of Slot to Item.VariableString(objectName)
There is an inventory example included with GDevelop here:
In case it is too complicated, you can also find a more simplified version called simple-inventory-system at the bottom of this page: