Simulating touch to workaround iOS sound problem

0 favourites
  • 9 posts
From the Asset Store
Shark.io
$49 USD
Shark.io in the sea full of killer sharks, Sunday of life is the game. Who knows what is happening under the sea?
  • I'm making a point and click adventure, and the fact that audio doesn't play on ios until the first touch in every scene is a big problem.

    Ashley suggests in the iOS article "Audio won't play until the first touch. However, this is not usually very important and can be easily worked around with a "touch to begin" screen that plays a sound when you touch it."

    In a game with few scenes this wouldn't be a huge problem, but as my game involves players moving from scene to scene, having a sign saying 'touch to start' whenever a player walks from the bathroom to the hall for example would massively break immersion.

    I'm wondering: Is there any way touch can be simulated in c2, be it natively or through an addon, and why is a first touch required?

  • Simulating a physical touch through programming, sounds to me like a hackers dream, so I hope it's not possible..

    Why a first touch is needed?

    From the manual on audio:

    Mobile limitations

    Safari on iOS and Chrome for Android share a limitation in playing music. While sound effects can be played at any time, music is only allowed to start playing when the user touches the screen. This is a limitation in the browsers themselves. As a result, if you play music on the start of layout, you may find in these browsers it does not actually start until the next touch.

    Safari on iOS has a further limitation that no audio can play at all until the first touch. In other words, audio starts off muted and the first touch unmutes audio playback.

    Usually you do not need to handle this in your events. If you try to play sound or music on 'start of layout', the audio object will automatically queue it up for playback the next time the user touches the screen. However you should be aware of this when designing your game. If the first touch changes layout or stops the music, then the music may never be heard. You may want to start playback then encourage the user to touch the screen with a 'Play' icon or something similar.

    So it's the browser that has the limitation..

  • Thanks for the info, that's a pain but it sounds like there is very little I can do, aside from hoping someone comes along with a simulate touch plugin, which as you said may be impossible due to security implications :/

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not sure about this, but would starting the music for the next layout on the previous one work?

  • I'm not entirely sure, I'll give a try and report back.

  • If it were possible to work around the limitation by simulating touches, we would have done that already. Unfortunately it's not possible.

    You should be able to play sounds at any time after the first touch. Only music can't play until the next touch after it's started. There's really nothing that can be done about it, it's a stupid limitation in both Safari and Chrome for Android. If you categorise the audio as a sound instead, it can play any time after the first touch, but then that fully decompresses the entire track in to memory which is pretty wasteful, whereas music can stream. So the restriction is completely pointless and encourages wasteful workarounds, but browser makers won't seem to budge on this.

    TBH I would just ignore the limitation and let the engine do its workaround where music starts on the next touch after playing. You don't really need any "touch to continue" screens, it just won't start music playback until the user touches the screen, and if they're doing that a lot in your game hopefully they won't notice.

  • If it were possible to work around the limitation by simulating touches, we would have done that already. Unfortunately it's not possible.

    You should be able to play sounds at any time after the first touch. Only music can't play until the next touch after it's started. There's really nothing that can be done about it, it's a stupid limitation in both Safari and Chrome for Android. If you categorise the audio as a sound instead, it can play any time after the first touch, but then that fully decompresses the entire track in to memory which is pretty wasteful, whereas music can stream. So the restriction is completely pointless and encourages wasteful workarounds, but browser makers won't seem to budge on this.

    TBH I would just ignore the limitation and let the engine do its workaround where music starts on the next touch after playing. You don't really need any "touch to continue" screens, it just won't start music playback until the user touches the screen, and if they're doing that a lot in your game hopefully they won't notice.

    But why does iOS have this limitation? What's the reason? Are they planning to remove it?

  • If it were possible to work around the limitation by simulating touches, we would have done that already. Unfortunately it's not possible.

    You should be able to play sounds at any time after the first touch. Only music can't play until the next touch after it's started. There's really nothing that can be done about it, it's a stupid limitation in both Safari and Chrome for Android. If you categorise the audio as a sound instead, it can play any time after the first touch, but then that fully decompresses the entire track in to memory which is pretty wasteful, whereas music can stream. So the restriction is completely pointless and encourages wasteful workarounds, but browser makers won't seem to budge on this.

    TBH I would just ignore the limitation and let the engine do its workaround where music starts on the next touch after playing. You don't really need any "touch to continue" screens, it just won't start music playback until the user touches the screen, and if they're doing that a lot in your game hopefully they won't notice.

    Damn, that's an annoying limitation. Sadly I think it will be quite noticeable as in a point and click music really needs to start as soon as you enter the scene to set the atmosphere, and a lot of the scenes start with cutscenes, so they player will have no need to tap the screen for a while

    Guess I'll have to think of something, thanks for clearing it up.

  • Interesting stuff. I have the same problem on iOS (cocoon.io) but not with sound. I have the same with localstorage. sometimes it loads my saved variables instantly and sometimes I need to touch the screen and then it loads up.

    Anyone else hat this? On Browser preview all works fine.

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