Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
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 11
    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

    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    +1 -1 (+1 / -0 ) Share on Facebook
  • Apollo14Apollo14 Member
    edited May 11 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

    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    +1 -1 (+2 / -0 ) Share on Facebook
  • AstirianAstirian Member
    Thanks Yuri! ;)

    Yeah, logic problem on my part I think.

    Likes: Apollo14, antix

    +1 -1 (+2 / -0 ) Share on Facebook
Sign In or Register to comment.