How do I switch selected sprite from RTS exampel

Get help using Construct 2

Post » Tue Jul 15, 2014 2:55 pm

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.
My game Petrolhead Tactics is now on Steam Greenlight. I could not have done this without C2 ? Please rate, if you like!

Steam client already open: petrolheadtactics.com/steam
Web: petrolheadtactics.com/greenlight
B
20
S
4
G
4
Posts: 132
Reputation: 4,130

Post » Tue Jul 15, 2014 3:24 pm

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).
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
15
S
3
G
1
Posts: 329
Reputation: 2,012

Post » Wed Jul 16, 2014 2:10 pm

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.
My game Petrolhead Tactics is now on Steam Greenlight. I could not have done this without C2 ? Please rate, if you like!

Steam client already open: petrolheadtactics.com/steam
Web: petrolheadtactics.com/greenlight
B
20
S
4
G
4
Posts: 132
Reputation: 4,130

Post » Wed Jul 16, 2014 2:30 pm

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

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
15
S
3
G
1
Posts: 329
Reputation: 2,012

Post » Wed Jul 16, 2014 3:57 pm

https://dl.dropboxusercontent.com/u/80975153/%5Esaveforever/RTS%20Example.capx

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
My game Petrolhead Tactics is now on Steam Greenlight. I could not have done this without C2 ? Please rate, if you like!

Steam client already open: petrolheadtactics.com/steam
Web: petrolheadtactics.com/greenlight
B
20
S
4
G
4
Posts: 132
Reputation: 4,130


Return to How do I....?

Who is online

Users browsing this forum: stevenode and 9 guests