Change animation frame on an instance of an object.

Get help using Construct 2

Post » Mon Jan 12, 2015 11:38 pm

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?
You do not have the required permissions to view the files attached to this post.
B
27
S
3
Posts: 11
Reputation: 1,449

Post » Tue Jan 13, 2015 2:45 pm

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,
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.
You do not have the required permissions to view the files attached to this post.
B
11
S
4
Posts: 152
Reputation: 1,236

Post » Tue Jan 13, 2015 4:00 pm

Unnatural20 wrote:"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.
B
27
S
3
Posts: 11
Reputation: 1,449

Post » Tue Jan 13, 2015 11:14 pm

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.
B
11
S
4
Posts: 152
Reputation: 1,236

Post » Tue Jan 13, 2015 11:56 pm

Thanks again @Unnatural20.

Lately I've been on an optimization learning spree hahaha. This definitely fits the bill.
B
27
S
3
Posts: 11
Reputation: 1,449


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests