Last change
on this file since 1d1c77e was 1d1c77e, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 8 years ago |
Correctly detect the native resolution on Mac
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[3960923] | 1 | import pygame, platform
|
---|
| 2 |
|
---|
| 3 | system = platform.system()
|
---|
| 4 |
|
---|
| 5 | [w, h] = [0, 0]
|
---|
| 6 |
|
---|
| 7 | if system == 'Windows':
|
---|
| 8 | print("Windows detected")
|
---|
| 9 |
|
---|
| 10 | import ctypes
|
---|
| 11 | user32 = ctypes.windll.user32
|
---|
[b632a7c] | 12 | w = user32.GetSystemMetrics(0)
|
---|
| 13 | h = user32.GetSystemMetrics(1)
|
---|
[3960923] | 14 | elif system == 'Linux':
|
---|
| 15 | print("Linux detected")
|
---|
[b632a7c] | 16 |
|
---|
| 17 | import tkinter
|
---|
| 18 | root = tkinter.Tk()
|
---|
| 19 | w = root.winfo_screenwidth()
|
---|
| 20 | h = root.winfo_screenheight()
|
---|
[1d1c77e] | 21 | elif system == 'Darwin':
|
---|
| 22 | print("Mac detected")
|
---|
| 23 |
|
---|
| 24 | from AppKit import NSScreen
|
---|
| 25 | res = NSScreen.mainScreen().frame().size
|
---|
| 26 | w = int(res.width)
|
---|
| 27 | h = int(res.height)
|
---|
[3960923] | 28 | else:
|
---|
| 29 | print("Unknown OS: " + system)
|
---|
| 30 |
|
---|
| 31 | print("Detected native resolution: {:d}x{:d}".format(w, h))
|
---|
| 32 |
|
---|
| 33 | pygame.init()
|
---|
| 34 |
|
---|
| 35 | if w == 0 and h == 0:
|
---|
| 36 | print("Not using fullscreen")
|
---|
| 37 | gameDisplay = pygame.display.set_mode((800, 600))
|
---|
| 38 | else:
|
---|
| 39 | gameDisplay = pygame.display.set_mode((w, h), pygame.FULLSCREEN)
|
---|
| 40 |
|
---|
| 41 | pygame.display.set_caption('Space Game')
|
---|
| 42 |
|
---|
| 43 | clock = pygame.time.Clock()
|
---|
| 44 |
|
---|
| 45 | running = True
|
---|
| 46 |
|
---|
| 47 | while running:
|
---|
| 48 | for event in pygame.event.get():
|
---|
| 49 | if event.type == pygame.QUIT:
|
---|
| 50 | running = False
|
---|
| 51 | elif event.type == pygame.KEYDOWN:
|
---|
| 52 | if event.key == pygame.K_ESCAPE:
|
---|
| 53 | running = False
|
---|
| 54 |
|
---|
| 55 | #print(event)
|
---|
| 56 |
|
---|
| 57 | pygame.display.update()
|
---|
| 58 | clock.tick(60)
|
---|
| 59 |
|
---|
| 60 | pygame.quit()
|
---|
| 61 | print("Game ended")
|
---|
[b632a7c] | 62 | quit()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.