Jump to content

[ AJUDA ] Funções no mesmo botão


Recommended Posts

Gostaria de colocar um botão (imagem) no login , onde ele pausaria ou iniciaria a musica . Consegui fazer isso , mas em botões separados , gostaria de uma ajuda para fazer essas duas funções em um mesmo botão (imagem) , assim trocando a imagem para som desativado .

Link to comment
elseif isCursorOnElement(x*930, y*20, x*55, y*50) then
				if button == "img/pause.png" then
					button = "img/play.png"
					setSoundPaused(playingSound, true)
					
				elseif button == "img/play.png" then
					button = "img/pause.png"
					setSoundPaused(playingSound, false)
				end


só cirar um if,  e setar o seu playsound para falso 

 

Link to comment

Vlw pela ajuda , mas não entendi muito bem a lógica da troca de imagem , estou usando dxDraw separado do meu "botão".

dxDrawImage(x*1803, y*52, x*50, y*50, "img/play.png", 0, 0, 0, tocolor(255, 255, 255, 255))
dxDrawImage(x*1803, y*52, x*50, y*50, "img/pause.png", 0, 0, 0, tocolor(255, 255, 255, 255))

addEventHandler('onClientClick', root, function (button, state, _, _, _, _, _, element)
	if button == 'left' and state == 'down' and sound then 

			if isMouseInPosition (x*1803, y*52, x*50, y*50) then
			setSoundPaused(sound, true)
		elseif isMouseInPosition (x*1803, y*52, x*50, y*50) then
			setSoundPaused(sound, false)
			end
	end
end)

sound = playSound("msc/music.mp3") 

 

Link to comment
1 minute ago, Arantes said:

Vlw pela ajuda , mas não entendi muito bem a lógica da troca de imagem , estou usando dxDraw separado do meu "botão".


dxDrawImage(x*1803, y*52, x*50, y*50, "img/play.png", 0, 0, 0, tocolor(255, 255, 255, 255))
dxDrawImage(x*1803, y*52, x*50, y*50, "img/pause.png", 0, 0, 0, tocolor(255, 255, 255, 255))

addEventHandler('onClientClick', root, function (button, state, _, _, _, _, _, element)
	if button == 'left' and state == 'down' and sound then 

			if isMouseInPosition (x*1803, y*52, x*50, y*50) then
			setSoundPaused(sound, true)
		elseif isMouseInPosition (x*1803, y*52, x*50, y*50) then
			setSoundPaused(sound, false)
			end
	end
end)

sound = playSound("msc/music.mp3") 

 

 

35 minutes ago, MRXBBC said:

elseif isCursorOnElement(x*930, y*20, x*55, y*50) then
				if button == "img/pause.png" then
					button = "img/play.png"
					setSoundPaused(playingSound, true)
					
				elseif button == "img/play.png" then
					button = "img/pause.png"
					setSoundPaused(playingSound, false)
				end


só cirar um if,  e setar o seu playsound para falso 

 

só vc fazer uma variavel no lugar do local da sua imagem no caso eu coloquei como button

dxDrawImage(x*930, y*20, x*55, y*50, button, 0, 0, 0, tocolor(255,255,255, between[5]), false)

ai eu fiz uma condição que se tiver play e ele clicar na posição e o button tiver em play ele seta pra pause e seta o som como pause e vice e versa

  • Thanks 1
Link to comment

Entendi perfeitamente  ,  mas não deu muito certo , esta dando este erro 'dxDrawImage' [Expected material at argument 5, got nill] .

dxDrawImage(x*1803, y*52, x*50, y*50, button, 0, 0, 0, tocolor(255, 255, 255, 255))

addEventHandler('onClientClick', root, function (button, state, _, _, _, _, _, element)
    
     if isMouseInPosition(x*1803, y*52, x*50, y*50) then
        if button == "img/pause.png" then
            button = "img/play.png"
            setSoundPaused(sound, true)
        
        elseif button == "img/play.png" then
            button = "img/pause.png"
            setSoundPaused(sound, false)
        end 
    end
end)

 

Link to comment
11 hours ago, Arantes said:

Entendi perfeitamente  ,  mas não deu muito certo , esta dando este erro 'dxDrawImage' [Expected material at argument 5, got nill] .


dxDrawImage(x*1803, y*52, x*50, y*50, button, 0, 0, 0, tocolor(255, 255, 255, 255))

addEventHandler('onClientClick', root, function (button, state, _, _, _, _, _, element)
    
     if isMouseInPosition(x*1803, y*52, x*50, y*50) then
        if button == "img/pause.png" then
            button = "img/play.png"
            setSoundPaused(sound, true)
        
        elseif button == "img/play.png" then
            button = "img/pause.png"
            setSoundPaused(sound, false)
        end 
    end
end)

 

Você está usando um variável pra definir a imagem do botão antes de dar um valor pra ela, imagino que a imagem deva começar como pause, então na lógica deverá ser assim.


button = "img/pause.png" --estou definindo inicialmente como pause, caso seja o contrário, é só mudar o nome da imagem, 

dxDrawImage(x*1803, y*52, x*50, y*50, button, 0, 0, 0, tocolor(255, 255, 255, 255))

addEventHandler('onClientClick', root, function (button, state, _, _, _, _, _, element)
    
     if isMouseInPosition(x*1803, y*52, x*50, y*50) then
        if button == "img/pause.png" then
            button = "img/play.png"
            setSoundPaused(sound, true)
        
        elseif button == "img/play.png" then
            button = "img/pause.png"
            setSoundPaused(sound, false)
        end 
    end
end)

importante que já que é um variável só dar um valor inicial, deva ficar no topo fora de de uma function

Edited by PeeQ.
  • Thanks 2
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...