Play Sounds on Specific Animation Frames?

  • Hi All,

    I have a sprite with long animation (many frames) when it plays SPECIFIC FRAMES I want it to play chosen files (from many files I already imported).

    For example:

    Sprite | Animation Frame = 1 | >>> | Audio | Play (choose("sfx_01","sfx_02","sfx_03" many sounds here.. )

    Sprite | Animation Frame = 18 | >>> | Audio | Play (same as above)

    Sprite | Animation Frame = 35 | >>> | Audio | Play (same as above)

    and so on...

    I tried this:

    Animation Frame = 1 & 18 & 35 but it didn't play any of the sounds...

    .

    Is there a way to do this in one line like using the "&" or even more efficient way using other expressions or something?

    Thanks ahead! :)

    Tagged:

  • Sprite on animation frame change
    	Sprite | Animation Frame = 1
    	OR Sprite | Animation Frame = 18
    	OR Sprite | Animation Frame = 35
    		audio play ....
    

    Another way:

    Sprite on animation frame change
    System compare two values (Sprite.AnimationFrame=1 | Sprite.AnimationFrame=18 | Sprite.AnimationFrame=35) EQUALS 1
    	audio play ....
    
  • 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 quick reply sensei!

    The first solution is not what I'm looking for because I need any of the chosen sounds to play when the specific frame play 1 then 18 then 35... and so on

    The second, I'm not sure but I think it's almost the same amount of lines as I tried and mentioned above, I didn't try it yet so I may be wrong.

    So basically there is no short cut like using the AND "&" so I get the same amount of so many lines in one event, like your second example which I need to try.

    I mean if there is an expression I should inside the Animation Frame [NUMBER] but I guess not.

  • You mean you need to play on every 18th frame? You can compare (sprite.AnimationFrame%18=0) then.

    It will be true on frames 0, 18, 36 etc.

    Another simple method is to put the list of all frames into a string:

    find(";1;18;35;99;205;991;", ";"&sprite.AnimationFrame&";")>=0

  • I guess I didn't explain myself very well, sorry about that.

    Not on every 18th frame, but on the specific frames that I will put on the chose, it could be any number frame I want to put there for example: 2, 29, 72, 115, 188, 201, etc..

    For now I just made every specific frame to it's own event, it's just doesn't look as efficient as it could be in one event and a nice expression that I probably not familiar with like they way I used "CHOOSE" to put all the audio I wanted in one expression (I'm aware it's choosing random from the list I put) but it's a good example of one simple expression and I wonder if there is something like that for listing my animation frames, so I can also edit it if I like.

    I think your example with the string is something similar to what I look for if there is no built-in expression for that, I'm not sure but I should try it, thanks! :)

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