How do I change opacity between instances of the same sprite?

0 favourites
  • 11 posts
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • Good day everyone,

    My frustration is starting to exceed my embarrassment. So here I am, asking for help.

    I've got instances of an SVG file. What I want to happen is this: click on one of the instances (instance A), and change its opacity to 70% let's say. Then if you click on another instance (instance B), instance A goes back to 100 opacity and instance B goes to 70%

  • You have to do something a little extra for this, you would store the instance selected, for example the UID, in a local variable with your 'on selected' event. Then as a sub event you 'pick all' instances and set opacity 100, then again as a sub event you pick the instance by UID, the variable value you stored, and set it to 70.

    This is because when you use on selected event it narrows the selected instances to just 1, you have to open them up again with pick all to set everything back to default, then return to the original one instance to pick that and set it to 70. Hopefully that makes sense.

  • Bruh, I was looking for something like "pick all". I expected it to be in the sprite object itself not system. I understood how events work, it was just that I couldn't figure out how to reset the filter. I actually tried picking every instance by its id and resetting their opacity individually but that didn't work for some reason.

    Anyways, many thanks.

  • Hi again,

    So I got another problem. My object has tile movement behavior and I want to detect when non of the instances can move to an adjacent grid respective to each one of them. I used the instance change in opacity as a selector. To know which instance you're moving. I want to end the game when non of your pieces (instances of the same object) can move anywhere. I tried using the "can move to" inverted condition but putting the name of the object just checks the condition against one instance, not all.

  • If you add 'system for each instance' to your can move checks then this could work but you might not have too much control over it. During such checks change a variable on that instance, so let's say variable1=yes if it can move and variable1=no if it cannot move. This would be updated throughout the game I imagine and allow you to see what can and cannot move.

    For the game end functionality, try system for each instance where variable1=yes. Then on the actions set a global variable to object.pickedcount. That variable value will be the number of instances that can still move, if it's 0 then that means none of them can move.

    Of course you can do this the opposite way if the total number of instances is known you can check where variable1=no and check that object.pickedcount is equal to the total number of instances.

  • Ok kind stranger, thank you for helping me but I'm kinda stuck a bit with your solution. My game is turn-based. So as you can see, every turn I reset instance variable "trapped" to no.

    I then did as you suggested with the first for each and that worked out fine. I could see in debug mode the instance variable changing. It's the end game functionality that doesn't want to work. The global variable "notTrapped" updates fine when instances are free to move. As I trap them one by one, the variable decreases alright but it gets stuck at 1. Even when working with just one instance, the instance variable shows when it's trapped or not but the global variable remains stuck at 1.

    Is it an event order problem (I tried rearranging them.)? I honestly can't figure out what's wrong.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've seen problems reported before on returning pickedcount=0 actually, try it the opposite way I mentioned with a total set to yes for total number of pieces and see if that works better.

  • Hmmm, yeah. The reason I didn't consider it was because you have to know the number of instance. While I do know the starting number some instance can get destroyed.

    Actually, there is an expression that tells you number of instances in layout that I can use as total right?

    I'll try it.

    .... As soon as the electricity gets back.

  • Yes it's object.count use this

  • Hey lionz, I've finally finished my first game. Check it out

    construct.net/en/free-online-games/dodgem-xo-43762/play

  • Hey lionz, I've finally finished my first game. Check it out

    https://www.construct.net/en/free-online-games/dodgem-xo-43762/play?via=c7

    Nice job! :)

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