Dynamic Horizontal Indexing to cycle objects

0 favourites
  • 5 posts
From the Asset Store
a full game example, menu system, with the first level and a boss, to create a horizontal shooter
  • 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).


    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

  • interesting problem..

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


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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!

  • 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

  • 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

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