A better way to fade in/out certain sprites?

Just started using Construct 2? Post your questions here

Post » Tue Nov 04, 2014 11:22 pm

I've gotten my goal to work so far, but I was wondering if there was a better/cleaner way to do the following.

I have 3 character portraits. I put them each on a separate layer, like so:

Layer sally: spriteSally
Layer jake: spriteJake
Layer kelly: spriteKelly

All layers are set to 0 opacity at the start. I have a variable that gets a value from an XML file in order to determine which portrait to show at a time. For example, if my XML value says "sally", I set up events to make that layer go to 100% opacity, and all others to 0%. When "jake" pops up in the XML, that layer is set to 100%, and the others to 0%. So basically, when I want a certain character to show up on the screen, they will, while any others disappear. Thanks!

fade.jpg


However, if I have say 10 portraits, I would need 10 layers (one for each). I can make it work, but the code just gets really long and repetitive (since I have to set each individual layer to 0 or 100% each time). Is there a better way to do this? Ideally I'd like to have all the sprites on 1 layer, and show/hide each dynamically instead of typing each one out in an event every time.

EDIT: Forgot to mention that each sprite has animations with it (like smile, laugh, etc.). I thought I could make one sprite that holds *all* portraits/animations for every character, but is that ok design?
You do not have the required permissions to view the files attached to this post.
B
13
S
2
Posts: 20
Reputation: 756

Post » Wed Nov 05, 2014 12:37 am

What about this:
You do not have the required permissions to view the files attached to this post.
B
60
S
10
G
10
Posts: 1,013
Reputation: 9,155

Post » Wed Nov 05, 2014 1:09 am

That's cool! Thanks! Ok, so instead of me using layers, I can set the events to the individual sprites. And if I'm reading it correctly, it's basically setting opacity to either +1 or -1 every tick right?

Ok, so either way, sprites or layers, I'll have to end up setting an action for each sprite right? I was wondering if there was a shorter way to do it that I was missing out on or just missed in the manual.
B
13
S
2
Posts: 20
Reputation: 756

Post » Wed Nov 05, 2014 2:19 am

could use a family to cut down events
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Nov 05, 2014 3:06 am

Whoa, that's sweet! That's exactly what I was looking for. TYVM! The instance variables for families are awesome.
B
13
S
2
Posts: 20
Reputation: 756

Post » Wed Nov 05, 2014 6:34 am

mhazaru wrote:Whoa, that's sweet! That's exactly what I was looking for. TYVM! The instance variables for families are awesome.


yea it will scale up to any number of sprites with no more code. just change the 'fade' =1, 2, 3 to 'name'="sally", etc.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Nov 06, 2014 12:05 am

@codah
Perfect example.
B
60
S
10
G
10
Posts: 1,013
Reputation: 9,155


Return to Beginner's Questions

Who is online

Users browsing this forum: kainrazial and 1 guest