Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Looping sound. — Gideros Forum

Looping sound.

Hi chaps,

How would I go about looping sound? I'm trying to handle a looping sound onEnterFrame when the move button is being held but I keep just getting the sound playing hundreds of times at the same time. Nearly blew out a speaker hah!

Anyway, I tried using bools to determine whether the sound is currently playing or not but I'm not having much luck. I'm thinking this use case must definitely have come up before...
Tagged:

Comments

  • Apollo14Apollo14 Member
    edited May 2018
    I'm not sure what you're trying to do and why do you use enterframe.
    If you just want to simply play/stop on button touched/released you can do this:
    local ourSound=Sound.new("jump.mp3")
    local ourButton = Pixel.new(0x8e44ad,1,200,50)
    stage:addChild(ourButton)
     
    stage:addEventListener(Event.TOUCHES_BEGIN, function(event)
    	if ourButton:hitTestPoint(event.touch.x,event.touch.y) then
    	ourSoundChannel=ourSound:play(0,true)
    	end
    end)
     
    stage:addEventListener(Event.TOUCHES_END, function(event)
    	if ourSoundChannel~=nil and ourSoundChannel:isPlaying() then ourSoundChannel:stop() end
    end)

    Likes: Astirian

    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
    +1 -1 (+1 / -0 )Share on Facebook
  • Apollo14Apollo14 Member
    edited May 2018 Accepted Answer
    If your sound is playing over and over every frame, most likely you forgot to switch playback trigger when playback starts (or to check it before starting playback)
    local ourSound=Sound.new("jump.mp3")
    local ourButton = Pixel.new(0xf1c40f,1,140,40)
    stage:addChild(ourButton)
    ourTrigger=false
     
    stage:addEventListener(Event.TOUCHES_BEGIN, function(event)
    	if ourButton:hitTestPoint(event.touch.x,event.touch.y) then
    		if ourTrigger==false then
    		ourSoundChannel=ourSound:play(0,true)
    		ourTrigger=true
    		end
    	end
    end)
     
    stage:addEventListener(Event.TOUCHES_END, function(event)
    	if ourTrigger==true then ourSoundChannel:stop() ourTrigger=false end
    end)

    Likes: antix, Astirian

    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
    +1 -1 (+2 / -0 )Share on Facebook
  • Thanks Yuri! ;)

    Yeah, logic problem on my part I think.

    Likes: Apollo14, antix

    +1 -1 (+2 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    @SkyBlue - are you a bot?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.