0 Favourites

Inventory weapons (Drag and drop)

  • What I have:

    I have 2 boxes at the bottom of the screen and an inventory with weapons.

    What I want to do:

    • When I drag a gun from my inventory to slot 1, I want it linked to key 1
    • When I drag a gun from my inventory to slot 2, I want it linked to key 2
    • When I press key 1 or 2, it should pull out the correct weapon I dragged there

    Question:

    What is the best way to do this? Should I use arrays? If so, how?

  • i would do it with families and instance variables.

    put all weapons into one family called all_weapons i.e and give them a family instance variable called "ID" or something like this. Make a family for the slots too. -> all_slots. with instance variables "number" 1 and 2.

    give the player instance variables like "weaponsEquipted1" & 2.

    give the family all_weapons drag&drop behaviour.

    then do somethin like this:

    "all_weapons" On overlapping "all_slots"

    -> Set value "weaponsEquipted"&"all_slots.number" to all_weapons.ID

    and then if 1 or 2 are pressed:

    on 1 key pressed

    ---compare instance variable all_weapons.ID = weaponsEquipted1 (this is a subevent)

    -> set all_weapons position to player at image point whatever ...

    -> set drag'n'drop of all_weapons to disabled

    -> set position of all_weapons to itemslot1.X,itemslot1.Y

    so the player won't be able to remove them by accident if they are selected.

    i can send you a capx this evening if you don't get it. or send me your's and i'll show you what i mean.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • of course you can use an array instead of all these instance variables.

    depending on what you plan to do with your weapons further in the game this would even be better. for example if you have different stats for reloading time, recoil, firerate and so on ..

    i can show you how to do it with arrays aswell.

  • Thanks. Would you happen to have a good capx example? If not, explanation of the array option would be nice! Thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)