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!!
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)
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
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??
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 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?
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 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.
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.
@@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.)
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 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.
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
How could I change the size of a surface, text, or label by clicking a button ? I am creating a grid (similar to a minesweeper game) and I want to change the amount of rows and columns by clicking buttons with options. There is something about the main loop that I am struggling to figure out...
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
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()?
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.
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.
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?
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
@@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!
Sometimes Pygame scale display surface. To avoid that put this function: ctypes.windll.user32.SetProcessDPIAware() Maybe somebody need this for 1080p projects)
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.
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:)
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
You and Tech with Tim are goooold!
yeeeeeeah
Yeeeeeah
you should watch clearcode
Yeeeeeeeah
Yeeeeeah
Forgot to boost the volume. Whoops.
No problem!!
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!!
Hi.
How I can do this?
@@suspensed_ What problem are u facing?
@@vaibhavkrkm I did it, Thanks
@@suspensed_ 👍👍👍
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)
Thank u bro u just started a revolution
This helped a lot. Thank you so much!
That was exactly what I was looking for right now .... Thanks a lot !!!
You get a like on every single pygame video my helpful guy
You make so many useful video's thank you!!!
first!
On this topic, scaling your screen to a specific resolution whould make a great video.
You do that every time you make a window. Just put static values for the dimensions when redefining your screen.
great info, thanks for sharing.
Thank you so much! That was very helpful.
Thanks a lot for this tutorial!
Da color realistic dell monitor, nice
Thank you for this tutorial! It really helped me.
Great video! Just one question: How can I resize the window only internally, without the user being able to resize it themselves?
Just redefine the screen to a different resolution
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
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)
This is what I did too, before starting to use Kivy.
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??
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?
got the same issue the window also becomes borderless
i found a way to fix this, just use pygame.display.toggle_fullscreen()
After switching to fullscreen and then back to normal screen resizing doesn't work
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?
same, have you solved it?
@@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?
@@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.
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.
I did a video on that. It’s called transformations.
@@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.
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.
@@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.)
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.
You can add black borders by adjusting what’s actually drawn in the window.
@@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.
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
You could also use pygame.display.get_desktop_sizes()[0] if you're using pygame 2
Wow ! :o
does anyone know how to use fixed resolutions as mentioned at 0:21?
How could I change the size of a surface, text, or label by clicking a button ? I am creating a grid (similar to a minesweeper game) and I want to change the amount of rows and columns by clicking buttons with options. There is something about the main loop that I am struggling to figure out...
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
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()?
might just test it out and update this.
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.
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.
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?
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
@@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!
@@dominicballinger6536 Thank you!
Nice video, but my problem is the cursor, How to hide the cursor wheen in fullscreen?
Sometimes Pygame scale display surface. To avoid that put this function:
ctypes.windll.user32.SetProcessDPIAware()
Maybe somebody need this for 1080p projects)
I love you bro
Any idea or website where we can learn more pygame physics 🤔🤔
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.
can you make so that as soon as you open your pygame window it automatically fits the screen without clicking the expand button?
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]
Very usefull! But i can't understand how to scale buttons of your example with screen
Could you make a video on how to optimize pygame code?
I spent a decent amount of time on that topic in this video: ruclips.net/video/s3aYw54R5KY/видео.html
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:)
👍🏻
dude this is a bit late but i noticed you have the same dell monitor 😂
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
You need from pygame.locals import *
@@DaFluffyPotato alright, will see if it works! Also Thanks for the reply!
i tried to make it with 2 surface and is a lot of glitches
please make video on coding RPG in pygame
Its not properly working after adding images...
Not working in what sense? As in the images aren't getting bigger/smaller? You have to do that yourself.
that is really nice but damn, that is long calculation
Link is not working !
pastebin is apparently blocked in some countries. I switched to self-hosting stuff for my newer videos though.
notice me senpai
No
:) jk
Stop
coloca legenda em portugues please!
Para de depender desse idioma lixo, se tu quiser ser bem sucedido na tua vida aprende esse idioma o quanto antes