How do I switch selected sprite from RTS exampel

0 favourites
  • 5 posts
From the Asset Store
10 isometric and animated Strategy Game Buildings in two Colors.
  • Hi all you C2 aces! I'm tinkering with the RTS example and was wondering how to select units, one by one, by pressing tab on the keyboard. I'm trying to make the system deselect a unit go to the next and select it. The example has a very robust structure and it is in this i would like to implement a solution.

    I've spammed the search engine with all kind of relevant phrases. Thrown more or less sophisticated attempts of code at it but I can't get my head around this one.

    Any Suggestions, thoughts or existing examples that could help, you are welcome to share.

    Thanks for your time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 1. Create an array to list the UIDs of all active units (activeUnits).

    2. Create a Global Variable to store the array position of the current selected unit (selectedUnit).

    3. Create a keyboard event that checks for tab and increase the global variable. If the variable equals the size of the array set it to zero, so it will go back to the beginning of the array.

    When you need to refer to the selected unit just use activeUnits.At(selectedUnit).

  • Thanks for your reply brunopalermo . Sorry to say I still can't figure it out. Let's forget about the selection and active for a minute and focus on the array. I've probably not read the manual inside out, because i get stuck when I ask the Array to list UID.

    It looks something like this:

    On sprite created - set array width to sprite.count

    -> For each X set to sprite.UID

    I tough I could call this when a sprite are destroyed to remake the Array. But the UID won't show up in debug mode.

  • Could you share the capx, so I can take a look?


    I've put together a quick example. I have not started on the keyboard actions, since I got stuck on your second step. So it ain't much. Here you are! Dear sir brunopalermo

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