It is on the road map on trello I believe but not sure if anyone working on to implement it.
What I would try is use an object variable to flag an object as dropped :
If object being dragged THEN DO = 1 to variable dropped of object myObject
If left mouse button is released AND mouse is over myObject AND variable dropped of myObject = 1 THEN the object was dropped, do what you want to do and set the variable dropped back to 0 so it is no longer going to be considered dropped.
Yes thats what i was thinking too how to do it. Just think that this is not really an elegant way. Anyway, hope this will get implemented soon, as it is an essential feature of dragging imo.
By the way, dont want to open another thread:
I have placeholder-sprites for positions. At the beginning of the game, game-sprites getting positioned on them. Then the player is able to drag the game-sprites around, however, if a game-sprite gets dropped at an invalid location, the game-spite should be set back to the placeholder-sprite location from where it has been dragged from. For that, i need to save the reference of the placeholder-sprite from where the game-sprite has been dragged from. Having the placeholder-sprite, i can access its x and y variables and set the game-sprites x and y variables according to them.
Is that possible in GDevelop? Or is there a better “GD-Way” of doing this?
Im totally new to GDevelop and usually used to do everything in code. So i have to get used to “thinking the GD-way”.
You can reference the position of objects using the expression object_name.X() and object_name.Y().
Not sure if this is what you looking for but in case the name of the placeholder objects is different, you can pick their position using this expression and store inside an object variable of the game-sprite to reference their initial position any time during the game.
If you want to pick object variable, the expression is object_name.Variable(variable_name).
In case the placeholder sprites are moving and they are instances of the same object, you could check collision with them at the beginning of the scene and Link the placeholder sprites to the game-sprites they are colliding with and then anytime during the game you can pick the placeholder that have a link to the game-sprite then pick their position or variable using the expression and work with that.
If placeholder is in collision with game-sprite At the beginning THEN Link placeholder and game-sprite
If game-sprite dropped at invalid location THEN
–pick placeholder Linked to game-sprite AND Do= placeholder.X() to the X position of object game-sprite AND Do= placeholder.Y() to the Y position of object game-sprite
Or if you want to reference variable use placeholder.Variable(X) and placeholder.Variable(Y) instead of .X() and .Y()
It is the most advanced scenario but in case the placeholder is static or different objects with different names, it is not necessary and I think it is more simple to just pick their position or variable at the beginning using the expression.
The name of the placeholders are the same. Its just one object instantiated several times.
But thats exactly what i want to do, but how can i store a variable of type “Object” in my sprite object? Only variable types supported are Number and Text?
So when the game sprite gets droppen on an invalid position, i can simply do; If game-sprite dropped at invalid location THEN Do= placeholder.X() to the X position of object game-sprite AND Do= placeholder.Y() to the Y position of object game-sprite. Where “placeholder” is a variable of type “Object” inside my game-sprite object.
In GDevelop you can not store objects in variables but you can add variables to objects to store either number or string / object.
“placeholder” is the name of the object. object_name.X() and object_name.Y() return the position of the object directly.
So in case you have the placeholder objects in the scene at all times, you can pick their position directly at any time. But if you delete them after start the game, you can save their position in to object variables using the above expression before deleting them.
A few advice:
I don’t think the condition to check if deck is NOT being dragged necessary since you also check if the mouse is released. It the mouse is released, nothing can be dragged. So you may waste some resources there on the condition to check if deck is not being dragged.
Also I would put the condition and everything after below the condition to check if the mouse is released as a sub-event, because as long the mouse is not released, there is no point to check if the cursor is on deck and if the variable of deck is = “true” so you are wasting some resources there too.
So I recommend to do this in order to be more optimal on resources:
Left mouse button was released
–The cursor/touch is on deck
----The text of variable was_dragged of deck is = “true”
------Repeat for each Card_Slot object
Each line begins with – is a sub-event of the previous so they won’t be executed and checked unless necessary which is in case the mouse was released and something may potentially was dropped.
I tried dragging.Now don’t have the code in hand but i think i did (translate to events )
if mouse left button down and touch in a draggable object set variable dragging to 1 or true you choose.
then check the event
left mouse butron released and check if drsgging is 1 if it is do whatever you want and set to 0