-- Sound Test 01 function love.load() -- init -- set filter love.graphics.setDefaultFilter("nearest", "nearest") -- set canvas size scr_w = 640 scr_h = 480 canvas = love.graphics.newCanvas(scr_w, scr_h) -- get window width and height wdw_w, wdw_h = love.graphics.getDimensions() scr_scale = math.min((wdw_w / scr_w), (wdw_h / scr_h)) scr_ofsx = (wdw_w - (scr_w * scr_scale)) / 2 scr_ofsy = (wdw_h - (scr_h * scr_scale)) / 2 -- load sound local srctype = ".wav" local bgm_fn = "bgm_loop"..srctype local se_fn = "se_beam"..srctype local se_explosion_fn = "se_explosion"..srctype bgm = love.audio.newSource(bgm_fn) bgm:setLooping(true) bgm:setVolume(1.0) se = love.audio.newSource(se_fn, "static") se:setLooping(false) se:setVolume(0.7) se_explosion = love.audio.newSource(se_explosion_fn, "static") se_explosion:setLooping(false) se_explosion:setVolume(0.9) -- framerate steady min_dt = 1 / 60 next_time = love.timer.getTime() end function love.update(dt) -- update next_time = next_time + min_dt end function love.draw() local status = "BGM Stopped" if bgm:isPaused() then status = "BGM Paused" elseif bgm:isPlaying() then status = "BGM Playing" end -- set canvas love.graphics.setCanvas(canvas) -- draw BG color love.graphics.setColor(0, 0, 0) love.graphics.rectangle("fill", 0, 0, scr_w, scr_h) -- unset canvas love.graphics.setCanvas() -- draw canvas to window love.graphics.setColor(255, 255, 255) love.graphics.draw(canvas, scr_ofsx, scr_ofsy, 0, scr_scale, scr_scale) love.graphics.print("FPS: "..tostring(love.timer.getFPS()), 10, 10) love.graphics.print("z: BGM play/paues , x : stop", 10, 40) love.graphics.print(status, 10, 60) love.graphics.print("a, s: SE play", 10, 100) love.graphics.print("ESC : exit", 10, 140) if love.system.getOS() == "Windows" then -- wait local cur_time = love.timer.getTime() if next_time <= cur_time then next_time = cur_time else love.timer.sleep(next_time - cur_time) end end end function love.keypressed(key, isrepeat) if key == "escape" then -- ESC to exit love.event.quit() elseif key == "z" then -- BGM play or pause if bgm:isPaused() then bgm:resume() elseif bgm:isStopped() then bgm:play() else bgm:pause() end elseif key == "x" then -- BGM stop if bgm:isPlaying() or bgm:isPaused() then bgm:stop() end elseif key == "a" then -- SE play if se:isPlaying() then se:stop() end se:play() elseif key == "s" then -- SE explosion play if se_explosion:isPlaying() then se_explosion:stop() end se_explosion:play() end end