Tower defence help with mouse clicks.

0 favourites
  • 9 posts
From the Asset Store
🙌 Battle Defense Sound Pack comes with 525 high-quality sound effect
  • Hello everyone,can I please have some help on a issue I'm having,I created a tower defence game and im having an issue,if I click a turret to select it to be built,that turret then spawns and follows my mouse until I click and place the turret,how do I stop the mouse from clicking the same turret and spawning a second turret,that follows my mouse at the same time,I basically want my mouse to only be able to select one turret at any time,currently If i have enough cash i can select many towers and they all follow my mouse.

  • Use a global variable as some kind of mode switch, for example have a variable 'buildmode' set to 0 by default.

    When you select a turret it goes into build mode, so you set buildmode variable to 1. Then you adjust the initial selecting a turret logic to have a condition only if buildmode=0. This locks out any future clicking on turrets while you are holding one on the mouse.

    Then to place the turret in the level you add to your turret placing logic a condition buildmode=1. This means it will stamp a turret and remove the follow mouse logic only if buildmode=1, and then once stamped you set buildmode back to 0.

    In short, you will only be able to select a turret to follow the mouse if buildmode=0 and you will only be able to stamp a turret down if buildmode=1.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you, i will try do that.

  • I have the build mode working by setting a variable in every tower with a variable call build,with the number set to 0,then on the tower I have the boolean variable set to inverted,then on left click I have set boolean to true that is selecting the tower,and I have the tower to move to mouseX and mouseY,that's all working fine and I have the towers placing good to,its just the issue with multiple mouse clicks is what I'm having trouble with,I'm not a advance user and I'm confused on how to solve it.is it possible to solve that without messing with the tower logic.just have another logic for the mouse clicks,but how?

  • Not on the individual towers, a global variable I said, that solves all your problems. It means you can only select one tower until you place the tower.

  • Thanks for your reply,Can you please be more Pacific,I tried what your saying but cannot get it to work.

  • Finally I figured it out,thanks so much for your help,its hard being a novice:)

  • I guess maybe you will need a variable on the tower too, like a bool isSelected.

    1. On tower clicked, if globalvar=0, set globalvar=1 and set tower isSelected true.

    2. If tower isSelected : set tower position to mouse.x,mouse.y

    3. On mouse clicked, if globalvar=1, set tower isSelected false, set tower to position mouse.x,mouse.y, set globalvar = 0

  • Yes mine is very similar to that,i decided to make a tower defence game for my first game ever,and it's really challenging,but I'm watching every tutorial available and asking for help when I'm stuck,its starting to come together real nice,thanks again for your help,no doubt I'll need help on something else

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