0 Favourites

Change animation frame on an instance of an object.

  • Hello everyone, I am stumped on this little problem of mine.

    I am attempting to create radial buttons for the difficulty level of my game but can't seem to get it working properly. The first time I created it I made 5 sprites of the same image and the coding was dead easy for that but I decided to challenge myself and use only 1 sprite and make instances of it. Now I have 5 instances of my radial button with instance variable "Parent" (to identify which object is which) and "Value" (to determine if it's 0 "off" or 1 "on"). As you can see from my attached .capx when the layout starts radial 1 should be active as the difficulty can't be 0. When I click on any of the radial buttons they work just fine.

    Problem:

    How do I make it so that if I click on a radial button, all the previous ones will also activate but it will deactivate any radial that comes after the one clicked?

  • Take a look at this: I've trimmed it down for you a bit.

    Generally, if you ever find yourself setting up a bunch of events where "if value is 4" | "set this other value to 4" "if value is 5" | "set this other value to 5" you probably want just one where you set "this other value to value"

    The specific answer to your question, [quote:2tjqianh]How do I make it so that if I click on a radial button, all the previous ones will also activate but it will deactivate any radial that comes after the one clicked?

    is, "Using a ForEach loop, with a system condition that selects each instance

    This .capx also includes the feature where, if you re-tap a button and the difficulty level is already there, it ratchets the difficulty down a notch.

  • "Using a ForEach loop, with a system condition that selects each instance.

    This .capx also includes the feature where, if you re-tap a button and the difficulty level is already there, it ratchets the difficulty down a notch.

    This is perfect, exactly what I was thinking. Thank you so much. You also cut down my events like crazy and I only had half of them in there (the other half is what I couldn't get to work). Let me try to understand what is happening in your events just so that it's clear to me and I can store it safely in my memory bank and also if anyone else stumbles on this they too can get a clear grasp of what is happening.

    So, on tapping on difficultyDot the difficulty is set to it's parent variable. Easy.

    Then a sub event picks all the instances of that object and for each instance it will check whether the difficulty is greater than or equal to the parent variable, if so we see the empty radial, otherwise the radial is active.

    Thank you for your help, it is greatly appreciated.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You've definitely got a good understanding!

    The one thing you might have missed is this: The reason the subevent picks all instances of the object is that the parent event had already selected just one instance. If the code ran on every tick, it could just use ForEach, but it's better (lower processing, better organized code) to only run that loop when needed.

  • Thanks again Unnatural20.

    Lately I've been on an optimization learning spree hahaha. This definitely fits the bill.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
1,941 263,316
FlyingRam's avatar
FlyingRam
Unread hot topic Locked topic
195 16,198
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
167 14,512
DMT2005's avatar
DMT2005