Pygame FULLSCREEN Display Flag 创建一个对于屏幕来说太大的游戏画面 [英] Pygame FULLSCREEN Display Flag Creates A Game Screen That Is Too Large For The Screen

查看:41
本文介绍了Pygame FULLSCREEN Display Flag 创建一个对于屏幕来说太大的游戏画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新的问题

我发现问题似乎与我使用 FULLSCREEN 显示标志来创建窗口有关.我在scree的左上角(0, 0)添加了一个要绘制的矩形,但是当我运行程序时,它主要是在屏幕外.然后,当我 Alt-Tab 离开和返回时,矩形被适当地放置在 0,0 并且炮塔偏离中心.

I have discovered the issue appears to be with the fact that I am using the FULLSCREEN display flag to create the window. I added a rectangle to be drawn in the top left of the scree (0, 0), but when I run the program, It is mostly off the screen. Then, when I Alt-Tab away and back, the rectangle is appropriately placed at 0,0 and the turret is off center.

所以基本上,当程序启动时,游戏屏幕比我的实际屏幕大,但居中.然后在 Alt-Tab 之后,游戏屏幕与 0,0 对齐,但由于游戏屏幕比我的屏幕大,炮塔看起来偏离中心,但实际上相对于游戏居中.

So basically, when the program starts, the game screen is larger than my actual screen, but centered. Then after Alt-Tab, the game screen is lined up with 0,0 but since the game screen is larger than my screen, the turret looks off center, but is actually centered relative to the game.

所以真正的问题是为什么使用 FULLSCREEN 显示标志会使屏幕比我的电脑屏幕大?

So the real question is why does using the FULLSCREEN display flag make a screen larger than my computer screen?

原始问题

我正在屏幕中央构建一个简单的炮塔演示,它跟随光标的位置,好像要在它所在的位置开火.一切正常,直到我 Alt-Tab 离开屏幕,然后 Alt-Tab 返回.此时炮塔现在偏离中心(向下和向右)

I am building a simple demonstration of a turret in the center of the screen which follows the location of the cursor as if to fire where it is. Everything works perfectly until I Alt-Tab away from the screen, and then Alt-Tab back. At this point to turret is now off center (down and to the right)

import pygame, math
pygame.init()

image_library = {}

screen_dimen = pygame.display.Info()
print("Screen Dimensions ", screen_dimen)

def get_image(name):
    if name not in image_library:
        image = pygame.image.load(name)
        image_library[name] = image
    else:
        image = image_library[name]
    return image

robot_turret_image = get_image('robot_turret.png')

screen = pygame.display.set_mode((0, 0), pygame.`FULLSCREEN`)

done = False

clock = pygame.time.Clock()

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        if event.type == pygame.MOUSEMOTION:
            print(event.pos)
        if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
            done = True

    screen.fill((0, 0, 0))
    pos = pygame.mouse.get_pos()
    angle = 360 - math.atan2(pos[1] - (screen_dimen.current_h / 2),
                             pos[0] - (screen_dimen.current_w / 2)) * 180 / math.pi
    rot_image = pygame.transform.rotate(robot_turret_image, angle)
    rect = rot_image.get_rect(center=(screen_dimen.current_w / 2, screen_dimen.current_h / 2))

    screen.blit(rot_image, rect)

    color = (0, 128, 255)
    pygame.draw.rect(screen, color, pygame.Rect(0, 0, 200, 200))

    pygame.display.update()
    clock.tick(60)

现在好像中心已经关闭了.我已经打印出 Alt-Tab 之前和之后的屏幕尺寸,它们是相同的,所以我无法弄清楚图像移动的原因.我相信我遗漏了一些关于 Pygame 状态变化的信息,但无法弄清楚是什么.如果相关,我使用的是 Windows 10.

It seems that the center is now off. I have printed out the screen dimensions before and after the Alt-Tab and they are the same, so I can't figure out why the image moves. I believe I am missing something regarding state changes with Pygame, but can't figure out what. If it is relevant, I am on Windows 10.

推荐答案

好吧,我从 gamedev.stackexchange

我会在这里重新哈希.问题是使用全屏标签会使屏幕比我的电脑屏幕大.下面的代码解决了这个问题

And I will re-hash it here. The issue was that Using the fullscreen tag was making a screen larger than my computer screen. The following code solves this

import ctypes
ctypes.windll.user32.SetProcessDPIAware()
true_res = (ctypes.windll.user32.GetSystemMetrics(0), ctypes.windll.user32.GetSystemMetrics(1))
pygame.display.set_mode(true_res,pygame.FULLSCREEN)

需要注意的是,这可能只是一个 Windows 修复程序,但我没有其他系统可以对其进行测试.但它适用于带有 python 3.5.1 和 pygame 1.9.2a0 的 Windows 10

It is important to note that this is potentially just a windows fix, but I do not have another system with which to test it on. But It works on Windows 10 with python 3.5.1 and pygame 1.9.2a0

这篇关于Pygame FULLSCREEN Display Flag 创建一个对于屏幕来说太大的游戏画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆