As the phone tilts more I want the music to get faster.

somersetjc

  • Posts: 40
I am making a mobile game and I want to make it so when the phone tilts more the music gets faster and faster. I tried doing this by having 3 different versions of the same song with different speeds and play them if the phone is tilted enough but it makes the song start all over. Is there any way to do this? I have attached what I tried.

« Last Edit: January 29, 2017, 12:10:59 pm by somersetjc »

ceosol

  • *
  • Posts: 2279
You say "stop all sounds on channel 2". That will stop the song. You either want to get a current location of the soundtrack and start the other songs at the same spot or you want all of it on one soundtrack and adjust the speed of playback.

somersetjc

  • Posts: 40
You say "stop all sounds on channel 2". That will stop the song. You either want to get a current location of the soundtrack and start the other songs at the same spot or you want all of it on one soundtrack and adjust the speed of playback.

I would like to have them all on one soundtrack and just adjust the speed if possible but is there a way to change the speed of the sound on a specific channel using blocks or code?

ceosol

  • *
  • Posts: 2279
If you want to do it that way, you'll have to code it: http://forums.flixel.org/index.php?topic=3260.5;wap2

morphman86

  • Posts: 141
edit: ceosol's answer might be more relevant for you, (s)he wrote that while I was typing this novel of a reply, but since my answer is going a different route, I've chosen to post it anyway.

As far as I know, there are no controls in place for playback speed, nor is there any controls that allows you to start a segment at a given time code.
It seems like they didn't foresee this particular use of it. They do allow for channels to be used, played, stopped and paused, so you can temporarily pause one soundtrack and play another on a different channel and then pick back up where you left off on the first one. But that won't be useful for you here. I was thinking first to have the two other tracks play simultaneously on different channels with volume set to 0, but with different lengths of the tracks, that won't work. It will start playing in a different part of the song anyway.

In Sound.hx (found in C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\models on Windows) I can see that the Play function can take a position, but Stencyl doesn't interface with this class directly. Instead, it interfaces with SoundChannel.hx (in the same folder) via Scripts.hx (in  C:\Program Files (x86)\Stencyl\plaf\haxe\lib\stencyl\1,00\com\stencyl\behavior) and it does not include the optional parameter "position".

If you can find a way to implement the position parameter from Sound.hx (possibly by writing your own SoundClip and Scripts files), you could get this behaviour to work.
What you would need to do is find the position relative to the length of the currently playing clip and simply start the new clip at that relative position.

For example, if channel 1 is playing the long clip, divide the length of that clip with the current position to get a "ratio". Then divide the length of the shorter clip with that "ratio" to get the position you need to start at in the shorter clip and play from there.
Programming equivalent of Jack-of-all-trades

somersetjc

  • Posts: 40
If you want to do it that way, you'll have to code it: http://forums.flixel.org/index.php?topic=3260.5;wap2

I was looking at it but I am kind of a noob when it comes to this stuff.  I've never coded in Stencyl before, I just use the blocks. What exact code would I use and where would I type it in?

ceosol

  • *
  • Posts: 2279
You are the one who wants it in your game. I've never looked at the sound code.

letmethink

  • *
  • Posts: 2545
~Letmethink