Hi everyone.
How can i get the display width and heigth of computer running my game? I want to use it for love.graphics.setMode, cause if I set width and heigth to 0, my game don't want to draw anything.
Get display width and heigth
Re: Get display width and heigth
love.graphics.getWidth() and love.graphics.getHeight() return the width and the height of the game screen
some tips :
1) if you want to call these functions repeteadly, don't forget you can use something like this in love.load() to accelerate the acces
now use getW() instead of love.graphics.getWidth() in love.update()
2) there is a function i use, inspired from here. it sort screen modes and apply the highest availaible mode and activate fullscreen
some tips :
1) if you want to call these functions repeteadly, don't forget you can use something like this in love.load() to accelerate the acces
Code: Select all
getW, getH = love.graphics.getWidth, love.graphics.getHeight
2) there is a function i use, inspired from here. it sort screen modes and apply the highest availaible mode and activate fullscreen
Code: Select all
function setModeMax()
modes = love.graphics.getModes()
table.sort(modes, function(a, b) return a.width * a.height > b.width * b.height end)
love.graphics.setMode(modes[1].width, modes[1].height, true)
end
Current work : Isömap
Re: Get display width and heigth
If you want to obtain the current width and height of the whole monitor (they could be not the highest possible) you can set width and height to 0 in conf.lua and then get the width and height of the window
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Get display width and heigth
On my display(1440 x 900) game isn't running. How can is solve this problem?
UPD
I just turned fullscreen off. Thanks you, guys. But can i ask another question here? How can i created image, that is fading in? I made some tries, using for , love.setColor(255, 255, 255, FadeAlpha) , but fade is too fast(Fades in one moment).
UPD
I just turned fullscreen off. Thanks you, guys. But can i ask another question here? How can i created image, that is fading in? I made some tries, using for , love.setColor(255, 255, 255, FadeAlpha) , but fade is too fast(Fades in one moment).
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Get display width and heigth
I believe 0.8.0 had a bug with setMode with a width and height of 0, where you had to then setMode again with the actual with and height (gotten from getWidth and getHeight).
As for the fade, just don't increase your alpha that fast.
As for the fade, just don't increase your alpha that fast.
Re: Get display width and heigth
I really don't understand, how to make delays. Who can help, posting, how to make normally fading white rectangle?bartbes wrote: As for the fade, just don't increase your alpha that fast.
Re: Get display width and heigth
Use a smaller number to increment the alpha value.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Re: Get display width and heigth
A common thing to do is to add dt from love.update to a variable, multiplied by another variable which controls the speed.
When changing the alpha value, you'll also what to make sure it doesn't go about the maximum value of 255.
When changing the alpha value, you'll also what to make sure it doesn't go about the maximum value of 255.
Code: Select all
function love.load()
alpha = 0
fade_speed = 100
end
function love.update(dt)
if alpha < 255 then
alpha = alpha + dt * fade_speed
if alpha > 255 then
alpha = 255
end
end
end
function love.draw()
love.graphics.setColor(255, 255, 255, alpha)
love.graphics.rectangle('fill', 200, 200, 200, 200)
end
Re: Get display width and heigth
You can also do:
Code: Select all
a = a + b * dt < 255 and a + b * dt or 255
--OR
a = math.min(255, a + b * dt)
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Get display width and heigth
Here's the trick I use. Call this function at the beginning of your code. (This is basically what Nixola said in code form)Palmar wrote:Hi everyone.
How can i get the display width and heigth of computer running my game? I want to use it for love.graphics.setMode, cause if I set width and heigth to 0, my game don't want to draw anything.
Code: Select all
function getScreenMaxRes()
local oldw, oldh = love.graphics.getWidth(), love.graphics.getHeight()
love.graphics.setMode(0,0,false,false)
screen_width = love.graphics.getWidth()
screen_height = love.graphics.getHeight()
love.graphics.setMode(oldw,oldh,false,false)
end
If you want you can omit the recording of the current size for use later and just use the three middle lines. That's the important part.
Who is online
Users browsing this forum: No registered users and 2 guests