Fullscreen & Resizing - Pygame Tutorial

  Рет қаралды 60,647

DaFluffyPotato

DaFluffyPotato

Күн бұрын

Window resizing and fullscreen are pretty important, so I made a video on them. [WARNING] This implementation only works with Pygame 1.x. If you're using Pygame 2.x, you will need to mess around with some things to make it work.
The script from the video:
pastebin.com/h...
Discord:
/ discord
Twitter:
/ dafluffypotato
This video and the code produced in it are released under: CC0 1.0 Universal (CC0 1.0). This puts the video and code produced in it in the public domain, so use it for whatever you want.
#pygame #python #gamedevelopment

Пікірлер: 94
@Traumatizes
@Traumatizes 4 жыл бұрын
You and Tech with Tim are goooold!
@forgandorgan7552
@forgandorgan7552 4 жыл бұрын
yeeeeeeah
@will_warrior351
@will_warrior351 4 жыл бұрын
Yeeeeeah
@shauryaiguess5155
@shauryaiguess5155 4 жыл бұрын
you should watch clearcode
@kronokun
@kronokun 3 жыл бұрын
Yeeeeeeeah
@leobozkir5425
@leobozkir5425 3 жыл бұрын
Yeeeeeah
@DaFluffyPotato
@DaFluffyPotato 5 жыл бұрын
Forgot to boost the volume. Whoops.
@vaibhavkrkm
@vaibhavkrkm 4 жыл бұрын
No problem!!
@vaibhavkrkm
@vaibhavkrkm 4 жыл бұрын
Nice tutorial!! By the way, I have a tip, if anyone is having issues with the monitor resolutions in full screen mode, you can also give default window or any custom resolutions which can fix the problem as well, and that may fix the issue, cuz in some cases, we may have problems to properly set the window size to the monitor size accordingly with all the elements of the game!!
@suspensed_
@suspensed_ 4 жыл бұрын
Hi. How I can do this?
@vaibhavkrkm
@vaibhavkrkm 4 жыл бұрын
@@suspensed_ What problem are u facing?
@suspensed_
@suspensed_ 4 жыл бұрын
@@vaibhavkrkm I did it, Thanks
@vaibhavkrkm
@vaibhavkrkm 4 жыл бұрын
@@suspensed_ 👍👍👍
@powerupminion
@powerupminion 2 жыл бұрын
Currently recoding my pygame framework that i use for my projects. Quickly implemented your method with the choice when creating the framework object, you have a setting if the window should be resizable or not (of cource along with some scaling features and that sort of stuff): def __init__(self, title: str, windowSize: (int, int), quitMethod: staticmethod = pgQuit, backgroundColor: (int, int, int) = color.black, fps: int = 0, windowResizable: [True, False] = False): """Pygame setup rutine with all my preffered settings""" @property def windowSize(self) -> (int, int): """Shorthand for getting the size as (x, y) of the current window""" def windowSizeSet(self, windowSize: (int, int)): """Manual screen size setting""" def windowScaleReset(self): """Reset the origin screen size value that controls the scaling calulation""" @property def windowScale(self) -> (float, float): """A tuple (x, y) of the scaling from the original window size (current / origin)""" @property def windowPoints(self) -> list: """8 points on the screen (corners, middle edges and window center) dynamicly changing with screen size that can easily be used as anchers for elements""" I use a programmable event handler build on top of pygames event handler. The user can assign keys and assosiate a method to run when that key is in a chosen state. This is the buisness end of that honestly beautiful method (I realy love this kind of thing): def tick(self): """Run event handler. Must be run each frame.""" for event in pg.event.get(): if event.type == pg.QUIT: self.__eventQuit() elif event.type == pg.VIDEORESIZE: windowNew((event.w, event.h), self.__allowWindowResize) elif event.type == pg.KEYDOWN: self.__keyTest(event, self.keyDown) elif event.type == pg.KEYUP: self.__keyTest(event, self.keyUp) if len(self.__events["held"]) > 0: keys = pg.key.get_pressed() for event in self.__events["held"]: if keys[event[0]]: event[1]() I break my code up into very small snippits of code so this alone will do pretty much nothing on its own. The last line does however provide a significant clue to what this event handler does to execute functions according to key presses. What is missing here is the data handling and my underlying library build on top of pygame witch is where functions like "windowNew" comes from. My framework is just for the purpose of I can just call: WINDOW = framework("title", (x, y)...) ...and have all the stuff i need such as event handler, rendering, resizing, drawing, sound and much more already implemented from the start and then I can focus on my actual project. btw... If you are playing with pygame or other similar things in python, you NEED stuff like this: from dataclasses import dataclass @dataclass class color: """The 8 basic colors. teachengineering.org/content/spfun_/maker_challenges/spfun_rgbcolor_maker1_image1.png""" black: tuple = (0, 0, 0) white: tuple = (255, 255, 255) red: tuple = (255, 0, 0) green: tuple = (0, 255, 0) blue: tuple = (0, 0, 255) cyan: tuple = (0, 255, 255) magenta: tuple = (255, 0, 255) yellow: tuple = (255, 255, 0) @dataclass class resolution: """Basic screen resolutions.""" x360p = (640, 360) x480p = (854, 480) x720p = (1280, 720) x1080p = (1920, 1080) x2k = (2560, 1440) x2_7k = (2704, 1520) x4k = (3840, 2160) x8k = (7680, 4320)
@muhammadharisaamir3952
@muhammadharisaamir3952 4 жыл бұрын
That was exactly what I was looking for right now .... Thanks a lot !!!
@ajiteshkumar
@ajiteshkumar 4 жыл бұрын
This helped a lot. Thank you so much!
@KaleakEnma
@KaleakEnma 2 жыл бұрын
Thank u bro u just started a revolution
@dartznight
@dartznight 4 жыл бұрын
You get a like on every single pygame video my helpful guy
@juniorgamerguy6074
@juniorgamerguy6074 5 жыл бұрын
You make so many useful video's thank you!!!
@bencusb
@bencusb 5 жыл бұрын
first! On this topic, scaling your screen to a specific resolution whould make a great video.
@dafluffypotatovr7362
@dafluffypotatovr7362 5 жыл бұрын
You do that every time you make a window. Just put static values for the dimensions when redefining your screen.
@emmanuelwestra6524
@emmanuelwestra6524 3 жыл бұрын
Thank you so much! That was very helpful.
@Iuigi_t
@Iuigi_t 2 жыл бұрын
Da color realistic dell monitor, nice
@unabonger777
@unabonger777 4 жыл бұрын
great info, thanks for sharing.
@ktrilex7001
@ktrilex7001 2 жыл бұрын
Thank you for this tutorial! It really helped me.
@azalty
@azalty 2 жыл бұрын
Thanks a lot for this tutorial!
@MaxwellPrehoda
@MaxwellPrehoda 4 жыл бұрын
Are you gonna make any new tutorials soon? Love your videos and have learned PyGame and started developing my own platformer solely with the resources you've shown on your channel
@dafluffypotatovr7362
@dafluffypotatovr7362 4 жыл бұрын
Yep. I've just been a bit busy with work lately. I'm hoping to record another video tomorrow. (It may not be edited & published then though)
@kefrov
@kefrov 3 жыл бұрын
This is what I did too, before starting to use Kivy.
@wolnyczowiek8705
@wolnyczowiek8705 2 жыл бұрын
After switching to fullscreen and then back to normal screen resizing doesn't work
@VictorPerez-od7zh
@VictorPerez-od7zh 2 жыл бұрын
You could also use pygame.display.get_desktop_sizes()[0] if you're using pygame 2
@aarushiswinner
@aarushiswinner 3 жыл бұрын
Nice video, but my problem is the cursor, How to hide the cursor wheen in fullscreen?
@gavinthecrafter
@gavinthecrafter 4 жыл бұрын
Great video! Just one question: How can I resize the window only internally, without the user being able to resize it themselves?
@DaFluffyPotato
@DaFluffyPotato 4 жыл бұрын
Just redefine the screen to a different resolution
@vissandre3845
@vissandre3845 3 жыл бұрын
YOO ok thats cool but when I go to fullscreen and then go back to small screen the placement of the window is topleft and I cant grab the top bar to move it down what do I do??
@AntoineVanGeyseghem
@AntoineVanGeyseghem Жыл бұрын
Wow ! :o
@matter8405
@matter8405 4 жыл бұрын
When i resize back to normal it puts the window in the top left of the screen instead of the middle. How do I fix that?
@aarondraws7699
@aarondraws7699 3 жыл бұрын
got the same issue the window also becomes borderless
@sn0wyb0ss53
@sn0wyb0ss53 3 жыл бұрын
i found a way to fix this, just use pygame.display.toggle_fullscreen()
@redthunder6183
@redthunder6183 3 жыл бұрын
I was working on my second game and I wanted it to have fullscreen capabilities, however, I think it would be really annoying if there isn't a way to exit fullscreen mode and when ever I try to exit the full-screen mode by using "screen= pygame.display.set_mode((500,500), pygame.RESIZABLE)" it makes a smaller window in the top left corner 500 by 500, but there isn't a task bar at the top that will let you drag the window around (the second you resize the window, the bar pops up again). What can I do to get it to go back to the basic window with the taskbar at the top, and have the window at the center of the screen rather than the top left?
@hexagoat4915
@hexagoat4915 3 жыл бұрын
same, have you solved it?
@redthunder6183
@redthunder6183 3 жыл бұрын
@@hexagoat4915 no, I have no clue what to do, but if I ever activate the videoresize in event.get, even if I don’t resize it at all, the bar pops back up again. Have you fixed it at all?
@pyplatformer869
@pyplatformer869 3 жыл бұрын
@@redthunder6183 pygame 1.9.6 doesn't have this issue as far as I know, I personally have only faced this problem with pygame 2.
@threepoint1434
@threepoint1434 4 жыл бұрын
How can one do this with images? Like, how to make an image stretch like that rectangle...? An an extra video about that would be nice. I can't find an answer to this question anywhere else.
@DaFluffyPotato
@DaFluffyPotato 4 жыл бұрын
I did a video on that. It’s called transformations.
@threepoint1434
@threepoint1434 4 жыл бұрын
@@DaFluffyPotato Yes. I know how transformations work. But when stretching the image it gets cut off. Like, after I just resized the actually window, the image also resizes like it should. The problem is; the new area where the image should stretch to, there is nothing, but black. It's rather tricky so explain. It's like the new black area is overlapping everything else. I don't know if you have a solution for this. I'll try some ideas of my own. I've already tried to blit the image after the screen, but that didn't work.
@threepoint1434
@threepoint1434 4 жыл бұрын
Never mind. I found something relevant to my question: import os import pygame from pygame.locals import * pygame.init() screen = pygame.display.set_mode((500, 500), HWSURFACE | DOUBLEBUF | RESIZABLE) pic = pygame.image.load("image.png") screen.blit(pygame.transform.scale(pic, (500, 500)), (0, 0)) pygame.display.flip() while True: pygame.event.pump() event = pygame.event.wait() if event.type == QUIT: pygame.display.quit() elif event.type == VIDEORESIZE: screen = pygame.display.set_mode( event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE) screen.blit(pygame.transform.scale(pic, event.dict['size']), (0, 0)) pygame.display.flip() This will cause the image to fill the window, like a background.
@dafluffypotatovr7362
@dafluffypotatovr7362 4 жыл бұрын
@@threepoint1434 So you're saying that the new space added to the window is black after you resize the window? That's what happens when you don't redefine the screen with the resolution of the resized window. (I believe I covered that in this video.)
@arbitervildred8999
@arbitervildred8999 Жыл бұрын
but when you go into fullscreen, how do you make it to not stretch your image having specific resolutions doesn't always scale well sometimes it stretches the image for example a game resolution of 1728x972 would stretch bad on a wide/ultra wide monitor, even on a 1920x1080 monitor and lose the pixel art style
@LawrenceAaronLuther
@LawrenceAaronLuther 9 ай бұрын
does anyone know how to use fixed resolutions as mentioned at 0:21?
@earthbender731
@earthbender731 6 ай бұрын
dude this is a bit late but i noticed you have the same dell monitor 😂
@TheOfficialKingIdea
@TheOfficialKingIdea 2 жыл бұрын
CAN YOU PLEASE MAKE A TUTORIAL FOR THE RECTANGLE!? Like a full explanation for how it works? I really need help with scaling the rectangle with the screen in my game. if you respond, then Thank you:)
@FreeForParrots
@FreeForParrots 2 жыл бұрын
Very usefull! But i can't understand how to scale buttons of your example with screen
@yurii.okereshko
@yurii.okereshko 5 жыл бұрын
Sometimes Pygame scale display surface. To avoid that put this function: ctypes.windll.user32.SetProcessDPIAware() Maybe somebody need this for 1080p projects)
@rickysacco2720
@rickysacco2720 4 жыл бұрын
I love you bro
@ahmednader1887
@ahmednader1887 3 жыл бұрын
i tried to make it with 2 surface and is a lot of glitches
@tanwyhang
@tanwyhang 3 жыл бұрын
hi dafluffy potato, can i know where did you get the white border for your videos , or did you draw it urself, because i wish to use it on my game project
@Klannahar
@Klannahar 4 жыл бұрын
Hi, Can u make smaller resolution on fullscreen mode then the actual screen resolution? I mean if u have a full HD resolution but u wana use only a half of that screen size in your project in full screen mode. Full HD is not a good resolution for pixel art, unless u using big sprites what will have a hell lot of pain to animate them.
@DaFluffyPotato
@DaFluffyPotato 4 жыл бұрын
You can add black borders by adjusting what’s actually drawn in the window.
@Klannahar
@Klannahar 4 жыл бұрын
@@DaFluffyPotato It is already adding black borders around the "screen" if it is smaller then the actual monitor resolution what i do not want. I wanted to try to avoid to scale up every image what i am blit-ing on screen.
@machinze_edits
@machinze_edits 3 жыл бұрын
Any idea or website where we can learn more pygame physics 🤔🤔
@basukhadka
@basukhadka 3 жыл бұрын
can you make so that as soon as you open your pygame window it automatically fits the screen without clicking the expand button?
@dtimer319
@dtimer319 2 жыл бұрын
Just as soon as you define your screen set the resolution to that of monitor_size = [pygame.display.Info().current_w, pygame.display.Info().current_h]
@ashmitgarg8930
@ashmitgarg8930 3 жыл бұрын
👍🏻
@tristandombroski9677
@tristandombroski9677 2 жыл бұрын
working with a program that has multiple menu's (based off your menu example in another video) where would I put the if event.type == VIDEORESIZE: ? would I put it in the def main_menu() or def game()?
@tristandombroski9677
@tristandombroski9677 2 жыл бұрын
might just test it out and update this.
@tristandombroski9677
@tristandombroski9677 2 жыл бұрын
so oddly enough throwing that in the def main_menu loop with the other if event statements bugged my screen out saying: Traceback (most recent call last): Python\Python311\Click Ranger\ClickRanger.py", line 91, in main_menu() Python\Python311\Click Ranger\ClickRanger.py", line 41, in main_menu screen.fill('gray') UnboundLocalError: cannot access local variable 'screen' where it is not associated with a value going to keep moving stuff around, I thought about defining a new class like def window_resize, but then I realized what if the player resizes in a different menu like options, the game screen, ect. Should I just stick to static resolutions like you mentioned? create an options menu with buttons that change the resolution when clicked? That is do-able.
@tristandombroski9677
@tristandombroski9677 2 жыл бұрын
okay, an update to that again, because I am using a screen.fill('lightgray') whenever I resize, it's all normals and my buttons are locked into place..... I don't need to handle all that other stuff I guess. I am still new-ish to this, about a month now.
@dominicballinger6536
@dominicballinger6536 2 жыл бұрын
Thanks! I've been wondering about this for a bit. One thing though, could I get pygame to keep the shape of the objects the same if I make the window the same aspect ratio of the monitor? I.E. if I make my window some values that keep a ratio of 16:9 would all the shapes stay the same when it goes to full screen?
@hiposter2601
@hiposter2601 2 жыл бұрын
hi, I also faced such a problem, here I think you can initially make sprites of a small shape, so that when you stretch the tap they are as shape as you want
@dominicballinger6536
@dominicballinger6536 2 жыл бұрын
@@hiposter2601 I just figured it out! So there is a pygame.FULLSCREEN parameter you can feed to the display. But then if you type in " | pygame.SCALED" it scales to your monitor very easily!
@hiposter2601
@hiposter2601 2 жыл бұрын
@@dominicballinger6536 Thank you!
@Step-a-Sight
@Step-a-Sight 4 жыл бұрын
I faced a problem. Whenever I try to resize the window, the extended part becomes white and the window does not fit the frame. I am using pygame 2.0.0. Please advise.
@robertspakarklis3125
@robertspakarklis3125 5 жыл бұрын
Could you make a video on how to optimize pygame code?
@DaFluffyPotato
@DaFluffyPotato 5 жыл бұрын
I spent a decent amount of time on that topic in this video: kzbin.info/www/bejne/qWTEiqprabdogbs
@gnanarajsubramanian851
@gnanarajsubramanian851 4 жыл бұрын
Its not properly working after adding images...
@DaFluffyPotato
@DaFluffyPotato 4 жыл бұрын
Not working in what sense? As in the images aren't getting bigger/smaller? You have to do that yourself.
@Dragon20C
@Dragon20C 4 жыл бұрын
When I type VIDEORESIZE it says Traceback (most recent call last): File "/home/user/PycharmProjects/Game/main.py", line 30, in if event.type == VIDEORESIZE: NameError: name 'VIDEORESIZE' is not defined
@DaFluffyPotato
@DaFluffyPotato 4 жыл бұрын
You need from pygame.locals import *
@Dragon20C
@Dragon20C 4 жыл бұрын
@@DaFluffyPotato alright, will see if it works! Also Thanks for the reply!
@juicedelemon
@juicedelemon 2 жыл бұрын
that is really nice but damn, that is long calculation
@disdis6127
@disdis6127 4 жыл бұрын
please make video on coding RPG in pygame
@generalpilipi3201
@generalpilipi3201 2 жыл бұрын
Link is not working !
@DaFluffyPotato
@DaFluffyPotato 2 жыл бұрын
pastebin is apparently blocked in some countries. I switched to self-hosting stuff for my newer videos though.
@GeJunior
@GeJunior 4 жыл бұрын
coloca legenda em portugues please!
@electricimpulsetoprogramming
@electricimpulsetoprogramming 3 жыл бұрын
Para de depender desse idioma lixo, se tu quiser ser bem sucedido na tua vida aprende esse idioma o quanto antes
@rotcbsu1651
@rotcbsu1651 5 жыл бұрын
notice me senpai
@will_warrior351
@will_warrior351 4 жыл бұрын
No
@will_warrior351
@will_warrior351 4 жыл бұрын
:) jk
@homeless5913
@homeless5913 3 жыл бұрын
Stop
How to Code (almost) Any Feature
9:48
DaFluffyPotato
Рет қаралды 718 М.
Saving and loading in pygame with json
25:23
Clear Code
Рет қаралды 30 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
I made Games with Python for 10 Years...
28:52
DaFluffyPotato
Рет қаралды 398 М.
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,6 МЛН
How to Make Full Screen and Resizable Python Games with Pygame!
7:16
Pygame CE - Better & Faster
6:29
DaFluffyPotato
Рет қаралды 43 М.
I Made The Ultimate Cheating Device
9:39
ChromaLock
Рет қаралды 1,9 МЛН
C++ Developer Learns Python
9:26
PolyMars
Рет қаралды 2,8 МЛН
Get Started in Pygame in 10 minutes!
10:19
Coding With Russ
Рет қаралды 413 М.
When Python is too Slow for my Steam Game
5:30
DaFluffyPotato
Рет қаралды 53 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.