Hey, I'm kinda new to Love 2d, still learning it all. I've tried everything to make a button that makes the game full screen, and if it's full screen to close it.
Can any of you help me?
Full Screen button
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Full Screen button
I think you may re-state the problem.
Is that a programming issue (you don't how to do it as well) or you are just stucked with Löve API (as you're new to Löve)...
If you tried something, upload the *.love file, so that one can help.
Is that a programming issue (you don't how to do it as well) or you are just stucked with Löve API (as you're new to Löve)...
If you tried something, upload the *.love file, so that one can help.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Full Screen button
I believe there is a fullscreen toggle function, but I prefer to set it manually each time by setting a variable. An "Is currently fullscreen" variable that is false at startup until you call the toggle function at which point it does something along the lines of..
Though mine is more complicated and gives me more control. I don't believe in using fullscreen mode with any resolution other than native* so instead my games all have a "game width" and "game height" variable and a "scale" variable and when in fullscreen it scales the game to fill the screen height, while in windowed the user sets the scale. I like it much better, but the above method should work fine.
*If you try to set a resolution to fullscreen that the display does not support, Löve, at least as of the older versions, would just go dark or sometimes become unable to exit out while black screened. So I prefer control and native resolution. They may have fixed it by now, but let's say I've been burned on using fullscreen without native resolution that I simply won't even attempt it anymore. Even if they fixed it.
Code: Select all
function toggleFullscreen()
<fullscreen preference> = not <fullscreen preference>
love.graphics.setMode(<width>, <height>, <fullscreen preference>, <vsync preference>)
end
*If you try to set a resolution to fullscreen that the display does not support, Löve, at least as of the older versions, would just go dark or sometimes become unable to exit out while black screened. So I prefer control and native resolution. They may have fixed it by now, but let's say I've been burned on using fullscreen without native resolution that I simply won't even attempt it anymore. Even if they fixed it.
Re: Full Screen button
An easy way to overcome that issue, Jasoco, would be to provide one of those "Are these settings ok?" or "Do you see this window" dialogues post-resolution change. Also, whilst it is nice to use native resolution for fullscreen games, sometimes you can get better performance by having it a little lower. Plus, on large resolutions it can be hard to read GUIs/HUDs that don't scale.
EDIT: I missed the "unable to exit" part. That is a problem, haha.
This solves your black screen issue:
love.graphics.getModes
This solves your black screen issue:
Code: Select all
modes = love.graphics.getModes()
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: Full Screen button
Yeah, it takes a little more coding, but you'd have the game show a "Can you see this?" message that counts down 15 seconds and waits for the user to press a key they won't normally accidentally press (To prevent accidental acceptance) or a mouse click on a "Yes" button. But I prefer my method since it will work 100% (He says as cocky as a sunrise, so sure of his coding abilities) basically...
My game first at load sets the window size to 0, 0 which means full width and height, then use the love.graphics.getWidth() and love.graphics.getHeight() functions to record the size to variables for later. (I do this because I had problems with Löve stopping drawing when I just set the res to 0, 0 within the game, so I need to record the values and set the window to that size when the time comes...)
Then when it's in windowed it uses love.graphics.setMode(draw_width, draw_height, false) and for fullscreen setMode(screen_width, screen_height, true) and calculate the scale to draw at by taking the window_height and / by the draw_height. (i.e. a game of 200 pixels height and a display height of 800 is a 4x scale.)
I created a template for myself to use in the future that has a complete menu system, game mode system and screen manipulating all built-in as well as an editor placeholder and transitions between modes and placeholders for start-up logo screens complete with time delays. I want to post a video of it in action when I get around to it. And probably make the code available if I optimize it for use.
My game first at load sets the window size to 0, 0 which means full width and height, then use the love.graphics.getWidth() and love.graphics.getHeight() functions to record the size to variables for later. (I do this because I had problems with Löve stopping drawing when I just set the res to 0, 0 within the game, so I need to record the values and set the window to that size when the time comes...)
Then when it's in windowed it uses love.graphics.setMode(draw_width, draw_height, false) and for fullscreen setMode(screen_width, screen_height, true) and calculate the scale to draw at by taking the window_height and / by the draw_height. (i.e. a game of 200 pixels height and a display height of 800 is a 4x scale.)
I created a template for myself to use in the future that has a complete menu system, game mode system and screen manipulating all built-in as well as an editor placeholder and transitions between modes and placeholders for start-up logo screens complete with time delays. I want to post a video of it in action when I get around to it. And probably make the code available if I optimize it for use.
Re: Full Screen button
In your screen scaling and such, how do you account for different aspect ratios?
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: Full Screen button
Can't you do?
Code: Select all
love.graphics.toggleFullscreen( )
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Full Screen button
It scales and centers the final image to fit.Lafolie wrote:In your screen scaling and such, how do you account for different aspect ratios?
Toggle takes the current window size and tries to set the display to that size which doesn't always work as it should since every display has a different list of resolutions it supports. My method throws that all out the window and simply sets the window size to the exact resolution of your display and scales the graphics for a crisper image without the blurring you get on flatscreen displays when setting them to lower resolutions.Davidobot wrote:Can't you do?Code: Select all
love.graphics.toggleFullscreen( )
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Full Screen button
I see what you did there.Jasoco wrote:My method throws that all out the window
Help us help you: attach a .love.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Full Screen button
...Robin wrote:I see what you did there.Jasoco wrote:My method throws that all out the window
Oh, lol. It's funny. Yes. It is. Hee-larious.
I like my method because it's more modern and resolution agnostic. It doesn't matter how high or low the resolution is, the game (As long as it's a fixed draw resolution) will be scaled to fit. Right now it only deals with resolutions smaller than my display but I'm working on making it so you can conceivably set your game's "draw resolution" to something high like 1680x1050 and it'll scale it down to your display if you say only have 1280x800 or so.
It's a more modern approach to game displaying. Changing the resolution is such an archaic way of doing it. Modern processors these days are more than capable of just scaling things when needed. Many emulators do it this way too and have options for scaling to whole numbers or stretching to fit.
Of course this is only applicable for games with mostly fixed draw resolutions. Not ones where you can change the internal resolution itself from within the game. That would use a different method.
Who is online
Users browsing this forum: Semrush [Bot] and 5 guests