Sound not playing everytime i want it to

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Sound not playing everytime i want it to

Post by ishkabible »

fisrt off im new to LOVE but so far im loven' it (how many times do people say that?). in my update function i have it so that if the mouse is down on a any frame it will play a shooting sound. problem is Love will not let me play it for some time after the sound is done playing. the file was like 2 seconds long but i took off all but half a second. still it wont play for a little while. i checked the frame rate to see if that was the issue but it runs at 60 fps so that's not the case. im guessing this is something built into LOVE to keep sounds from being played a t housed times when code like mine is run. if this is the case i would like to override this feature and mange it myself instead, is this possible?

here is the code i have so far:

Code: Select all

--classes
Player = {}
Zombie = {}
MiniBoss = {}
zmt = {}
mbmt = {}
pmt = {}

--Objects/Buffers
local ThePlayer
local Bullets = {}
local Enemys = {}
local EBullets = {}

--Assets
Music1 = nil
Music2 = nil
ShootSound1 = nil
ShootSound2 = nil
ZombieTex = nil
PlayerTex = nil
MiniBossTex = nil
GameFont = nil
ReloadSound = nil

function Init()
	ThePlayer = Player:new(300,400)
	love.audio.play(Music2)
end

function Zombie:new(sx,sy)
	return setmetatable({x=sx,y=sy,tex=ZombieTex,theta=0,health=20},zmt)
end

function MiniBoss:new(x,y)
	return setmetatable({x=0,y=0,tex=MiniBossTex,theta=0,health=50},mbmt)
end

function Player:new(x,y)
	return setmetatable({x=0,y=0,tex=PlayerTex,theta=0,health=35},pmt)
end

function FireBullet()
	love.audio.play(ShootSound1)
end

function love.draw()
	local fps = love.timer.getFPS( )
	love.graphics.print(fps,20,20)
	--love.graphics.setColor(33,33,40);
	--love.graphics.quad("fill", 0, 300, 0, 600, 800, 600, 800, 300)
	love.graphics.draw(ThePlayer.tex,ThePlayer.x,ThePlayer.y,0,1,1,0,0)
    --draw all zombies
	--draw all minibosses
	--draw all bullets
	--draw Player
	--draw interface
end

function love.load()
	love.graphics.setCaption( "Zombie Game" )
	PlayerTex = love.graphics.newImage("Player.png")
	--ZombieTex = love.graphics.newImage("Zombie.png")
	--load MiniBoss Assets
	--load Aimer
	--load interface
	ShootSound1 = love.audio.newSource("Shoot1.wav", "static")
	--ReloadSound = love.audio.newSource("Reload.wav", "static")
	--load shoot sound2
	--Music1 = love.audio.newSource("labyrinth.mod", "static")
	Music2 = love.audio.newSource("prondisk.xm")
	--GameFont = love.graphics.newFont("Arcade.ttf", 15)
	--Init()
	Init()
end

function love.update(dt)
	if love.mouse.isDown( "l" ) then
		FireBullet()
	end
	if love.keyboard.isDown("w") then
		ThePlayer.y = ThePlayer.y + 1;
	end
	if love.keyboard.isDown("a") then
		ThePlayer.x = ThePlayer.x - 1;
	end
	if love.keyboard.isDown("s") then
		ThePlayer.y = ThePlayer.y - 1;
	end
	if love.keyboard.isDown("d") then
		ThePlayer.x = ThePlayer.x + 1;
	end
	--update player
	--update enemys
	--make new enemys if needed
	--check for collisions and act as needed
end

function love.mousepressed(x,y,button)
	--FireBullet()
	--move curosr
	--fire if button is down
	--start fireing machine gun if needed
end

function love.mousereleased(x, y, button)
	--relase fireing machine gun
end
also on a side note it dose not seem to be alpha blending as it should, i saw that there is a set blend mode function but i saw no documentation one what the different modes are, could someone give some insight on how i would get alpha blending to work.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Sound not playing everytime i want it to

Post by bartbes »

Try converting the sound to another format, this is a known bug with wavs.
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Sound not playing everytime i want it to

Post by ishkabible »

ok i tired converting it to .ogg file but nothing happens when i click. i checked the volume and it was 1, whats the issue?

here is revised code, made some changes to clean everything up:

Code: Select all

--classes
Player = {}
Zombie = {}
MiniBoss = {}
zmt = {}
mbmt = {}
pmt = {}

function Player:new(x,y)
	return setmetatable({x=0,y=0,tex=PlayerTex,theta=0,health=35},pmt)
end

function Player:draw()
	love.graphics.draw(self.tex,self.x,self.y,self.theta,1,1,0,0)
end

pmt.__index = Player

--Objects/Buffers
ThePlayer = nil
Bullets = {}
Enemys = {}
EBullets = {}

--Assets
Music1 = nil
Music2 = nil
ShootSound1 = nil
ShootSound2 = nil
ZombieTex = nil
PlayerTex = nil
MiniBossTex = nil
GameFont = nil
ReloadSound = nil

function Init()
	ThePlayer = Player:new(300,400)
	love.audio.play(Music2)
end

function Zombie:new(sx,sy)
	return setmetatable({x=sx,y=sy,tex=ZombieTex,theta=0,health=20},zmt)
end

function MiniBoss:new(x,y)
	return setmetatable({x=0,y=0,tex=MiniBossTex,theta=0,health=50},mbmt)
end

function FireBullet()
	love.audio.play(ShootSound1)
end

function love.draw()
	local fps = love.timer.getFPS( )
	local vol = ShootSound1:getVolume()
	love.graphics.print(fps,20,20)
	love.graphics.print(vol,100,20)
	ThePlayer:draw()
end

function love.load()
	love.graphics.setCaption( "Zombie Game" )
	love.graphics.setBlendMode("alpha")
	PlayerTex = love.graphics.newImage("Player.png")
	ZombieTex = love.graphics.newImage("Zombie.png")
	ShootSound1 = love.audio.newSource("Shoot1.ogg", "static")
	ReloadSound = love.audio.newSource("Reload.wav", "static")
	Music1 = love.audio.newSource("labyrinth.mod")
	Music2 = love.audio.newSource("prondisk.xm")
	GameFont = love.graphics.newFont("Arcade.ttf", 15)
	Init()
end

function love.update(dt)
	ThePlayer.theta = ThePlayer.theta + math.pi/180
	if love.mouse.isDown( "l" ) then
		FireBullet()
	end
	if love.keyboard.isDown("w") then
		ThePlayer.y = ThePlayer.y - 2;
	end
	if love.keyboard.isDown("a") then
		ThePlayer.x = ThePlayer.x - 2;
	end
	if love.keyboard.isDown("s") then
		ThePlayer.y = ThePlayer.y + 2;
	end
	if love.keyboard.isDown("d") then
		ThePlayer.x = ThePlayer.x + 2;
	end
end
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Sound not playing everytime i want it to

Post by ishkabible »

ok i switched it to .mp3 becuase i figured of all the files it must have best support for that, now it works grate. why was the .ogg file not working?
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: Sound not playing everytime i want it to

Post by Tesselode »

The .ogg file should have worked. You're using 0.6.2, right? 0.6.2 has a pretty horrible glitch with sounds, but it's fixed in 0.7.
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Sound not playing everytime i want it to

Post by ishkabible »

ya i'm using 0.6.2, how did you know? any way i will update it, thanks!!
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: Sound not playing everytime i want it to

Post by Tesselode »

Well, you might not want to update to 0.7, since it's still in beta. Also, I knew you were using 0.6.2 because that's the version on the front page. :)
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: Sound not playing everytime i want it to

Post by ishkabible »

ok so where do i get 0.7? i looked for it but have not found it. i have halted audio stuff becuase it was all working with new file types. i have made a lot of progress in my game, i LOVE LÖVE. this is by far the best 2D game engine anywhere. productivity of Lua and a good engine with a vast array of file types to load, 3D acceleration from OpenGL, audio position changing thanks to OpenAL, this engine amazing
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Sound not playing everytime i want it to

Post by TechnoCat »

ishkabible wrote:ok so where do i get 0.7? i looked for it but have not found it.
Continue your search on this thread: http://love2d.org/forums/viewtopic.php? ... 882#p19271
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests