Dynamic Horizontal Indexing to cycle objects

Get help using Construct 2

Post » Sat Aug 31, 2013 7:00 pm

Hi. I have 3 troll sprite instances, on a horizontal platform.

This is The CAPX


When ctrl is held and an arrow key is pressed, I cycle between them by adding +1 to the instance number or subtracting 1 from the instance number
The problem is, if the trolls move from their original positions, they are not in the correct order any more. So by pressing ctrl+arrow, you don't necessarily select an adjacent troll any more :(


So I found a way to dynamically assign an Xindex number to each instance, by using a loop and comparing the X position to a minimum and maximum X.
So then, every time I press ctrl, the troll instances get numbered 0, 1, 2 (leftmost, middle, and rightmost troll respectively).


QUESTION

What do I do with the horizontal index though? How can I use it to always select the sprite to the right, when pressing ctrl+right, or the sprite to the left, when pressing ctrl+left ?


I may be overthinking it, so I'm stuck.

If anyone has any idea, I'd be grateful
B
28
S
12
G
4
Posts: 193
Reputation: 4,581

Post » Sat Aug 31, 2013 11:10 pm

interesting problem..
i had a go at making it in top down style for x and y, in a new .capx :

https://dl.dropboxusercontent.com/u/53374990/Forum/selectionthing.capx
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Sep 02, 2013 12:04 am

Oh god, so *that's* what for each (ordered) is! I should read the manual more.

What an elegant solution, thank you @keepee, I'm in your debt!christina2013-09-02 00:06:15
B
28
S
12
G
4
Posts: 193
Reputation: 4,581

Post » Mon Sep 02, 2013 5:38 am

Just as a note to that .cap i posted.. I'm doing things like setting all the bodies to stop their control every tick and then just overriding the selected one in the very next event.. that kind of stuff is kinda the lazy/'brute force' way to do it and is probably not wise in some cases.

anyway, no worries, nice d.a gallery by the way- skilled in different styles, varied, interesting.
Good luck with the game etc
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Sep 02, 2013 12:44 pm

Thanks for the heads up. I noticed, but I was way more interested in your awesome indexing skills. Don't worry, I won't learn "bad" techniques from you.

Thank you for the kind comment as well, if you ever need any graphics tips, you know where to find me
B
28
S
12
G
4
Posts: 193
Reputation: 4,581


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests