enum of pointers

Started by nightmarer, Tue 23/02/2021 22:27:02

Previous topic - Next topic

Laura Hunt

(eri0o: putting this under spoiler tags because I don't want to interfere with the thread any further)

Spoiler

Quote from: eri0o on Wed 24/02/2021 15:12:11
@Laura Hunt

Ah, it's possible then! In the end I didn't use that option (I could not understand it) and made my own crossfade and stuff module that I have been using since - which requires indeed two audio channels! My use case is having different versions of the same music with exact same length and the need to do the crossfade.

Unfortunately the code is kinda kinda tricky (depends on a bunch of modules) so I never bothered packaging for others.

Hey, I just did another test right now and it turns out I was wrong! Apparently AGS does somehow create a "ghost" channel or manages to mix both clips in the same music channel somehow in order for the crossfade to take place, but even with the help of my GUI I wasn't able to see this because even the "slow" fade is really fast, and if the volume of your tracks is lower than 100 the whole thing happens too quickly to even notice the fade and it feels and looks like one clip is playing right after the other. Apologies for the confusion! * embarrased face *

[close]

Crimson Wizard

#21
Well, speaking formally, if you'd like to tell a function to assign certain pointer from your collection, the most common way is make an array of these pointers and pass an index of the element.

So, instead of
Code: ags

AudioChannel *bgm;
AudioChannel *bgm2;


you would have
Code: ags

AudioChannel *bgm[2];


Then in the function:
Code: ags

void SetBGM.Play(AudioClip *music, int index) {
  if (bgm[index] == null || bgm[index].PlayingClip != music) {
   bgm[index] = music.Play();
  }
  else if(music == null) {
    music.Stop();
  }
}


If you don't like passing mere number, then of course you may create a enum, and fill it with values that correspond to array indexes, for example:
Code: ags

enum ChannelIndex {
  bgmA = 0,
  bgmB = 1
};



PS I think this is similar to what Khris proposed some time ago.

nightmarer

That totally works!
Thank you very much all for your help!
:) :) :) :) :) :) :)

SMF spam blocked by CleanTalk