How do I make a bunch of sprites change color based on the distance from each other?

0 favourites
  • 15 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • Hi everyone, I have some problems in obtaining the expected result.

    In my project i have a family that contains an object, the family has a boolean variable called "active", how do I select all instances close to an object instance with the boolean active? I cannot simply reverse the control of the variable because I have multiple groups of instances close to each other and I have to select only those close to, for example 100px to the active object.

    Below I attach the images of the project.

    What I was hoping to achieve was that by approaching an active sprite to a sprite or a group of inactive sprites, the latter would set their variable ID_Aquired the UID with the UID value of the active sprite so that you could change the color only of the groups of sprites close to the active sprite. Currently the behavior occurs on the active sprite, but this is incorrect.

    Thanks to whoever will be able to help me and sorry for the English, I'm using google translate.

    Below is the link to the project.

    https://mega.nz/file/7KQCmbKS#i4c0MfY07Tiy-UUK_CgnY-fuvXDUj-Ofg5x8Sxmc1ew

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the answer and for the example, but it only works partially. My question was perhaps not well expressed.

    Your example works perfectly until I add a second pick condition, then, the active sprite changes its frame by updating it to the last available frame while it should keep the frame set as active (in this case frame 1).

    Another problem that remains is that in the case of two sprites active at the same time, the reaction of the other sprites becomes unpredictable, they do not always assume the frame indicated by the distance in pixels indicated by me in the pick condition and sometimes they do not react to the proximity to the active sprite.

    I hope I have better explained the problem now, otherwise I will try to make a video to show what I expect, in the meantime I am attaching an image of the modification I made and the problem that arises. Thanks again for the help.

  • Anyone know how to fix this problem? Or do you know how I should redesign everything to make it work?

  • You need to add 'for each' for Sprite so each instances will act the same.

  • thanks for your help Alextro, I had tried this solution too, unfortunately it only works if I have only one active object.

    As you can see in the image I attached ...

    both are active ...

    but only one of the two works, among other things why does the one on the right and not the one on the left work? Certainly I am missing some fundamental concepts.

    the for each I used it like this...

    in the meantime, thanks again for your help

  • Ah you really need to pick up object by evaluating the distance:

    dropbox.com/s/57dr0m5uow6w0rg/change_color_around.capx

    And make sure that "active" variable created in Family instance variable and don't forget to set the variable too.

  • Thanks for the example but I think I have not yet explained myself well, I do not speak English and it is becoming an obstacle. I tried to redo the project by commenting on it in the hope that we can better understand what I need.

    https://mega.nz/file/2aoySLaC#neG8FESN6FnDWuAI3ooV6lRLY125dZVHU1Y5VZGwMPk

    Basically I need that any sprite that is activated has the ability to make the adjacent (inactive) sprites change color, this is because in a real situation it will be very easy to find multiple instances of the same object close together and I need to prevent the behavior from malfunctioning in case of several groups of nearby and / or active objects at the same time.

    This time I hope I was clearer, unfortunately my english comes completely from google translator so I know I might be misunderstood again. Anyway, thanks again for the help!

  • I forgot ...

    the sprites circled in red are the ones I activated with the right mouse button. I first activated the one on the left, moving it among the other sprites everything worked correctly, then I activated the one on the right and now only this one works correctly, the other one has stopped making the adjacent sprites change color. How do I fix or get around this problem?

    Thanks again!

  • It's not so correct logic you put there. As I mentioned before set the boolean active to truly toogle the instance state and not rely on animation. And it is not make sense if you set boolean true while the condition already true.

    So in the following example I made it simple to gives basic understanding:

    dropbox.com/s/nljgzcqxn0byyyz/ChangeColorDistance.c3p

    Deactivate only works by right clicking further from minimum activated distance.

  • I feel a bit stupid because either I still don't understand or I still don't explain myself well.

    When I run your example on my pc, nothing works as I expect. I try to make a video to show what I want to happen.

    https://mega.nz/file/rKJgnZKZ#MitDbHMVj1xT_RIIoE2uNtJfhAbP19_EQRdrd_ULzeY

    I apologize if I am not understanding something obvious, but unfortunately what you have suggested to me is not the behavior I expected ... or maybe what I want to achieve is not possible in construct 3?

    thanks for your help and your patience

  • For that case I suggest using another sprite as overlapping range pinned to active Sprite which is more more simple approach.

  • So all you have to do is use the nearest/farthest condition and if it is far enough away change RGB to x,x,x

  • I realize that it is all about tagging object around the activated one or two or more. Yes we need to tag which object were affected by the Sprite especially when they are further away. But this way you can't affect object that already tagged before it moves away.

    Have a look: dropbox.com/s/1ohpyo6xara7f3h/color_based_range.c3p

  • Great Alextro, this is what I needed !!! The tag system is brilliant and I just wouldn't have known how to implement it ... Thanks again for your invaluable help!

    Thank you all!!!

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