Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(4 edits)

full Example :

fullscren on/off

streching on/off

center screen when not streching in fullscreen mode

local GameWidth, GameHeight, ScreenWidth, ScreenHeight, ScreenScaleY, ScreenScaleX, ScreenScale, Center, dx, dy, switchRes, Stretching

GameWidth,GameHeight = 800,600 -- res of your base code

love.window.setFullscreen(true) -- set fullscreen for client


ScreenWidth,ScreenHeight= love.window.getDesktopDimensions() -- get res of client

love.window.setMode(ScreenWidth, ScreenHeight, {resizable=false, vsync=false, minwidth=400, minheight=300}) -- apply res client with setting if you need...

function getScale()
  ScreenWidth, ScreenHeight = love.graphics.getDimensions()
  --
  ScreenScaleY=ScreenHeight/GameHeight  -- calcul scale Y
  ScreenScaleX=ScreenWidth/GameWidth  -- calcul scale X
  if not Stretching then
    ScreenScaleX=math.min(ScreenScaleX,ScreenScaleY) -- get lower scale of x or Y
    ScreenScaleY=math.min(ScreenScaleX,ScreenScaleY) -- get lower scale of x or Y
  end
  --
  dx = (  ScreenWidth  - (GameWidth * ScreenScaleX ) ) / 2 
  dy = (  ScreenHeight - (GameHeight* ScreenScaleY ) ) / 2
end
--

function love.load()
  getScale()
  Center = false
  switchRes = false
  Stretching = false
end
--

function love.update(dt)
  getScale()
end
--

function love.draw()
  if Center then
    love.graphics.translate( dx , dy )
  else
    love.graphics.translate( 0 , 0 )
  end
  --
  love.graphics.scale(ScreenScaleX, ScreenScaleY) -- apply this in your love.draw
  --
  love.graphics.rectangle("line", 0,0,GameWidth, GameHeight, 5) -- 
  --
  love.graphics.print("Scale X = "..ScreenScaleX.."\n".."Scale Y = "..ScreenScaleY.."\n".."dx = "..dx.."\n".."dy = "..dy.."\n".."press escape to quit".."\n".."press C for center true/false : ["..tostring(Center).."]".."\n".."press R for fullscreen true/false : [".. tostring(switchRes).."]".."\n".."press S for Stretching true/false  : ["..tostring(Stretching).."]".."\n", 10, 10)
end
--

function love.keypressed(key)
  if key == "r" then
    switchRes = not switchRes
    if switchRes == false then
      love.window.setMode(ScreenWidth, ScreenHeight, {fullscreen = true,resizable=false, vsync=false, minwidth=400, minheight=300})
    else
      love.window.setMode(GameWidth, GameHeight, {fullscreen = false,resizable=true, vsync=false, minwidth=400, minheight=300})
    end
  elseif key == "c" then
    Center = not Center
  elseif key == "s" then
    Stretching = not Stretching
  elseif key == "escape" then
    love.event.quit()
  end
end
--