[Solved]Setting effect parameter affects all instances

0 favourites
  • 9 posts
From the Asset Store
Shatter
$2.49 USD
Shatter effect, with parameters for crack size with an option for crack region and crack animation.
  • Hi, I create a square (with bullet behavior) every 1 second with some random values for it's size, speed, spawn coordinates.

    For these values, it's working correctly, each instance has different values and they do not change during their lives.

    But I also have a ReplaceColor effect that is changed randomly between 3 colors on creation of the square.

    This one affects all square instances, not only the newly created one.

    (Click on image to go to it's full size)

    I have a Construct license for some times now but I never used it so I'm a newbie and don't see where I did something wrong.

    Can you explain how can I change the color of the newly created square without affecting already created squares?

    Thank you.

  • When you recreate a new instance of an object, construct 2 uses its default values to Initialize the instance. You can have the function called after the new object is created to change its stats, or keep the first instance of the object somewhere in the layout, and change it values on layout load.

  • Thank you for your answer, sorry but I do not understand what I have to do, I'm not sure it answers my problem.

    This is what my function does:

    Everything works great, each instance has it's own size, speed, and spawn coords.

    But the ReplaceColor affects all instance, I do not want that.

    I'd like that each instance keeps the color that was defined at creation. The same way it keeps its size and speed.

    So why does it work for size and speed but not for color?

  • Okay I see what are you trying to do, when you change the color it changes for every single instance, but you want it change for 1 only. This can be little tricky to implement. Add a global variable called color_picker, add the same variable as a instance variable to the square object. When you create your object increment both the local and the global variable by 1. Add the change color function, and call it with a parameter which is equal to the instance variable. This means that the function will trigger only once on the object with the current id, the next will spawn with different id because we are increment it by 1 each time you create the object and it wont be effect by the function.

  • I tried but I must be dumb, it's still behaving the same.

    If you ever have time to test it and make a working example that would be awesome but even if you can't I thank you for your time and answers.

  • Here is an simple example I made, the event is bit different then my explanation above, but it does the trick every instance is created with a different random color.

    https://www.dropbox.com/s/etc3o79zi004t ... .capx?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok, I'm sorry it's my fault.

    It was working from the beginning... on Construct 2.

    I didn't realize I'm on the C2 side of the forum but I'm actually working on C3.

    It works on C2 but not on C3, even your example code. So I guess I found a bug.

    I will go signal it on the C3 side of the forum if it was not already.

    Thank you.

  • I am also working in C3 and had issues with setColor. For example the capx above wont work in C3 unless you just use one setColor action.

    Set effect "SetColor" parameter 0 to rgb(255, 0, 0)

    In this case, that is bright red.

  • In C3 it's normal to use only one parameter like this : rgb(red, green, blue)

    instead of 3, one for each color, as it was on C2.

    So what you are describing seems normal.

    As for my specific issue, I reported it on Github there : https://github.com/Scirra/Construct-3-bugs/issues/311

    And it was fixed in r32 update.

    Edit: Just to be sure, parameter 0 is source color, parameter 1 is the color you want; so if you want red it should be:

    Set effect "SetColor" parameter 1 to rgb(255, 0, 0)

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