Is there a way to maximize the pygame window when intializing the window with set_mode without making it completely fulsscreen. I tried to get the required window_size by printing event.size, when VIDEORESIZE is called, which is (1920, 1017). But if I use this value for my window_size when setting mode I just get a window at the same size of a maximized window. If I press maximize in the top right corner it just switches between a thicker and a thinner border.
Obviously i want the thinner border, is that possible from the start?
You should try to use the
RESIZEABLE
When using set_mode in pygame like
DISPLAYSURF = pygame.display.set_mode((1920,1017), RESIZABLE)
Related
I am making a game using python and pygame. I had a problem a few days ago that I needed to give my games a functionality of being resized and maintain the aspect ratio. Also everything on the screen is resized proportionately. And luckily I got a quick solution to create two different pygame surfaces. One is the screen visible to the user and the other is to manage the blitting functionality. Actually, fake screen has everything blitted and then it itself is blitted to the main screen by using
main_screen.blit((pygame.transform.scale(fake_screen, main_screen.get_rect().size), [0, 0]).
The main problem is that now since the MOUSEBUTTONDOWN events are getting triggered on the main screen and not on fake screen, But
the clicks are getting processed according to the fake screen. This means that when I click on a button after resizing, the button appears to be their but actually its at its respective position on the fake screen. This makes all the buttons loose their functionality after the VIDEORESIZE event. Can anyone help me out with this? I hope that I was able to explain.
Easy answer: use the pygame.SCALED display flag.
It resizes the main screen for you and the mouse events too, without your program needing to know anything about it. Documented on this page: https://www.pygame.org/docs/ref/mixer.html
Using this means you wouldn’t need to use a fake screen at all, or do anything at all with scaling on your end.
DIY answer:
If you still want to control the scaling yourself, you just have to scale the mouse events along with the screen. Like scale then the opposite way you scale the fake screen.
In your case it looks like that would involve dividing the mouse event x by the ratio between fakescreen width and screen width, and same with y (with heights ofc).
I got a very easy solution to this myself. I just after getting mouse x and y coordinates, changed them to proportionately corresponding points. With a simple math. I mean, if x coordinate is 15% of main screen width, then convert it to 15% of fake screen width. This way, the fake screen will get properly scaled coordinates. The mathematical equation can be as follows:-
mouse_x = mouse_x/(xd/100)
mouse_x *= 10
mouse_y = mouse_y/(yd/100)
mouse_y *= 6
Here xd and yd are width and height of the resizable main screen respectively. And 10 and 6 are 1% of 1000 and 600 which are the width and height of the fake screen.
This solved my problem and game is now working perfectly.
Thank You.
I am trying to work with the screen in turtle and am confused about the dimensions of the screen. So in this example:
import turtle
screen = turtle.Screen()
print(screen.screensize())
turtle.done()
Python prints the dimension of the turtle window to be (400,300). However, the screen looks much bigger on the desktop and when I move the turtle by 640 pixels to the right (from the center) or 540 pixels downwards then the edge of the screen is reached. This would indicate that the screensize is 1280 * 1080 pixels.
So my specific questions are:
What information do I get from calling screen.screensize()
When the turtle is moved, is it moved in pixels or is another metric used?
So many thanks in advance!
Let's clear up some misconceptions about turtle window size:
First, the default window you get in standalone turtle is 50% of your display width and 75% of your display height. Which means that not everyone gets the same default window. Something to consider when writing turtle software for others.
You can set the window's size using the setup() method or function. You can get the current window size using the window_width() and window_height() methods or functions.
The screensize() method or function gets/sets the size of the backing store for the window. Generally, the return value is of no use to you, as the area the turtle can travel is the size of the window, so no backing store needed. It's there for folks who, for example, want a 500x500 window onto a 2000x2000 plane that the turtle can wander. Then scrollbars appear to allow you to move that peephole of a window about the larger plane.
You can modify many of turtle's default behaviors with a turtle.cfg file.
You can also find this in the turtle documentation: https://docs.python.org/3/library/turtle.html#screenspecific
I want to create a game in pygame but want it to have pixelated graphics, so instead of resizing a pixelated image, i was hoping to just change the resolution of the pygame screen .
screen = pygame.display.set_mode((width, height))
Thanks.
Make two screens. One with your desired resolution( let's call screen) and the other with your desired screen size(let's call window). Then blit screen into window while scaling it to the size of the window.
window.blit(pygame.transform.scale(screen,(windoWidth,windowHeight)),(0,0))
That should work.
EDIT: As the Ted's comments suggests it will be more easy to understand like this.
resized_screen = pygame.transform.scale(screen, (windoWidth,windowHeight))
window.blit(resized_screen, (0, 0))
So, I'm working on a game using Pyglet for graphics and hardware. The game I am working on requires me to do intensive collision detection using pixels. The game window is created as such:
# Set up buffer variables
bufferedHeight = 256
bufferedWidth = 144
# Create the window
window = pyglet.window.Window(bufferedWidth, bufferedHeight, resizable=True)
I want my game window to increase pixel size accordingly when the window is re-sized. Therefore, the game logic will still think the window is 256 by 145 pixels, however it will display on screen with much larger pixels. How can I go about doing this?
From what I understand, you want BIG pixels to be drawn.
I would suggest rendering your pixel buffer to an openGL texture which could be then in turn rendered to screen and scaled each time the 'resize' event happens..
But you must be aware that the square proprtion of the pixels might not be maintained on resize of the window.
I have a dual monitors set up (laptop screen and external monitor). My laptop screen is my primary display and external monitor is secondary. Both have different screen sizes.
In my python tkinter script, i have used winfo_screenwidth() and winfo_screenheight() to detect the screen width and height so that I can set the root window to become full screen.
Normally, when I run my script, the root window will be the size of my laptop screen. When i move the window to my extended monitor, I want it to auto adjust the width and height to match the external display's width and height.
Is this possible? Is there any way to check if the root window is in primary or secondary display?
Does winfo_screenwidth() detect the width and height of the secondary display?
EDIT: I am using Windows XP Pro 32 bit & Python 2.7.
How I did it:
t = Tk() # new window
t.update()
t.attributes("-alpha", 00)
t.state('zoomed') # maximize the window
height= t.winfo_height() # ...
width= t.winfo_width()
But sadly I do not know of the location of the other screen.
But I think you can do this
create a new window
use winfo_screenheight() and winfo_screenwidth() to find out about the original screen
use geometry() to move the window around
maximize the window (it should always maximize at the screen where it is)
get geometry()
if geometry is at (0, 0) it is the main screen, proceed with 3.
you found another screen