0 Favourites

A better way to fade in/out certain sprites?

  • 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!

    [attachment=0:2b10m66p][/attachment:2b10m66p]

    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?

  • What about this:

  • 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.

  • could use a family to cut down events

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

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • codah

    Perfect example.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Sprite Font Generator - v3
368 112,380
RetroDaddy's avatar
RetroDaddy
Unread hot topic
52 9,679
Rable's avatar
Rable
Unread hot topic
86 28,722
St4rDu57's avatar
St4rDu57