Jump to content

Play a Sound when a KEYDown is released


Russell
 Share

Recommended Posts

Hi there team!!

I'm working in ZOOM system for my game. When i press down the Right button of the mouse, we make ZOOM and the game plays a sound with this code:

Load sounds:

--Aquí cargamos los sonidos que necesitaremos:
self.sound.zoomin=Sound:Load("Sound/MisSonidos/ZOOMCamara/ZoomIN.wav")
self.sound.zoomout=Sound:Load("Sound/MisSonidos/ZOOMCamara/ZoomOUT.wav")

 

Use loaded sounds:

--Hacemos ZOOM al pulsar el boton derecho
if window:MouseHit(Key.RButton) then
	if self.sound.zoomin~=nil then self.sound.zoomin:Play() end
end
if window:MouseDown(Key.RButton) then
	self.camera:SetFOV(20)
	self.camera:SetRange(0.05,1000)
else
	self.camera:SetFOV(70)
	self.camera:SetRange(0.05,1000)
end

This works ok, but I don't know how play a sound ONCE when we release the Right button of the mouse.

Any tip that can help me?

Thank you very much!!

Link to comment
Share on other sites

Finally!!! Nevermind team... Finally I got it!!

I have used a simple variable to achieve this. This is my code that finally works with SOUND playing ONCE on ZOOM IN and SOUND playing ONCE on ZOOM OUT:

local ZoomActivo=false

if window:MouseDown(Key.RButton) then
	self.camera:SetFOV(20)
	self.camera:SetRange(0.05,1000)
else
	if self.sound.zoomout~=nil and ZoomActivo==true then
		self.sound.zoomout:Play()
		ZoomActivo=false
	end
	self.camera:SetFOV(70)
	self.camera:SetRange(0.05,1000)
end

if window:MouseHit(Key.RButton) then
	if self.sound.zoomin~=nil then
		self.sound.zoomin:Play()
	end
	ZoomActivo=true
end

????

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...