|Topic was automatically imported from the old Question2Answer platform.
I am very new to coding. I am learning Godot on the fly to build my football manager type sim. The first insurmountable problem I have come up against is how to set up the Squad Page so that I have a list of players with various stats that I can drag and drop and swap with each other. Any help or advice would be really appreciated!
I have watched various videos on inventories and GUIs but nothing has the functionality I’m looking for. Specifically to be able to pick up a player and drag him so that he can be swapped with another player in the team with all of the underlying data swapping with him.
If anyone has any tips or could perhaps point me in the direction of some videos or tutorials on this I’d be very grateful.
Thanks very much.
i think the bare minimum is to create a Control object (panel+label+other things) object for each player, and place them into a list (a parent
VBoxContainerYou need to have one list for each team).
The player-object also needs an area (i suggest to use a
TextureButton, the area could even be as big as the entire object) : with a click on that area the object is removed from the VBoxContainer and placed into a momentary parent node, then you link your mouse movement to the player
The VBoxContainer (the list) also need a similar 2d area to check if the mouse entered or not, so that when mouse is released the player-object is moved into a secondary VBoxContainer (the other team)
Andrea | 2020-05-26 11:19
Hi Andrea. Thanks for your message. I think I understand the general idea of clicking and dragging but my problem is I would like to be able to swap the player I am dragging with another that is in place in the team.
So, for instance I might want to swap a substitute with a 1st team player. I would click on the sub, drag him over the first team player and release which would snap the sub into the first team player’s spot and the first team player would snap into the newly vacant sub’s slot. If you get me?
Blooobird | 2020-05-26 12:30
In that case the “squad” object need to be a little bit more complex than a simple list, but the concept is not different: point is you create a game-tree structure similar to PC folders (goalkeeper folder, attacker folder, sub folder), you place players inside and move them by simply changing folder (check
For example when you release one player on top of the current goalkeeper a sequence similar to this one happens:
After your structure is done, there are hundreds of way to show it visually, either with Control nodes that arrange the rect position automatically on the screen (like, setting the goal-keeper position to be on top, ecc) or even using Node2D and your personal code.
I know it’s not a very specific solution, the specific one depends on what you are trying to achieve!
Andrea | 2020-05-26 13:08
Thanks for your help Andrea. Can I ask some more questions?
Lets say I set up two squads : sqaudA and squadB
Squad A is the first team and the stats of the players combine to make the team stats (shooting, passing, stopping).
SquadB is the reserves and the stats do not affect the team’s stats.
I then create individual nodes for each player and put them in the two squads. when I swap one player from squadB with a player in squadA how do I get the new player’s stats to update the team’s stats?
I’m guessing the squads need to be stored in an array? Is that right?
Thanks again, I am really pulling my hair out over this!
Blooobird | 2020-05-27 22:35