无极限 2020-08-24 14:38 采纳率: 75%
浏览 91
已采纳

pygame2D开放世界中 世界扩展与滑动观察问题

实现整个世界的滑动与观察动态

    在过程中 我使用了移动整个屏幕的方式,实现开放世界的滑动与观察

    但还是出现了两个难以解决的问题:
        1、窗口的上下左右移动都会使屏幕边缘会出闪白边 或 黑色的边
        2、移动过程中 一些表面也会跟着闪动  # (图片界面大的明显)

询问下各位大佬,在pygame中是否 能被装载到 其他窗口中运行、 从而实现屏幕的移动操作

如下代码: #


import pygame
from pygame.locals import *
from sys import exit
import pygame

import win32gui
import win32con
import pyautogui as pag

Windows_x = 0
Windows_y = 0
Windows_x4 = 0
Windows_y4 = 0
pygame.init()
#设置窗口的大小
screen = pygame.display.set_mode((9999, 9999))  # 设置窗口大小   pygame.NOFRAME 设置无标题会有些明显
bg = pygame.image.load('6666.jpg').convert() #6666*6666大小图
bbbb= pygame.image.load('指针手.png').convert_alpha()
pygame.display.set_caption("测试窗口") #

mouse_cursor = pygame.image.load('指针手.png').convert_alpha()
上=[pygame.image.load("s镜头动{0}.png".format(i)).convert_alpha() for i in range(0, 3)]
下=[pygame.image.load("x镜头动{0}.png".format(i)).convert_alpha() for i in range(0, 3)]
左=[pygame.image.load("z镜头动{0}.png".format(i)).convert_alpha() for i in range(0, 3)]
右=[pygame.image.load("y镜头动{0}.png".format(i)).convert_alpha() for i in range(0, 3)]
Pointer = True
index = 1
while True:
  for event in pygame.event.get():
    if event.type == QUIT:
      exit()
  screen.blit(bg, (0, 0))
  screen.blit(bbbb, (0, 0))

  for x in range(4):
    hWndList = []
    win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), hWndList)
    for hwnd in hWndList:
      title = win32gui.GetWindowText(hwnd)
      if (title.find("测试窗口") >= 0):                #移动窗口的位置设置  与打开大小设置
        win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, Windows_x, Windows_y, 6666, 6666, win32con.SWP_SHOWWINDOW)

    a1, b1 = pygame.mouse.get_pos()  # 获取游戏中的窗口坐标..
    窗口大小Width, 窗口大小Height = pag.size()  # 获取屏幕的尺寸
    ptx, pty = pag.position()  # 获取当前鼠标的位置
    a, b = str(ptx).rjust(2), str(pty).rjust(4)
    鼠标_x = int(a)
    鼠标_y = int(b)
    # 1920 1080
    print(a,b)
    """
    上 = 0,0 - 1920,0
    左 = 0,0 - 0,1080
    下 = 0,1080 - 1920,1080
    右 = 1920,0 - 1920,1080
    """
    windows_speed = 35
    # 屏幕移动
    if 鼠标_x > 0 and 鼠标_y == 0:
      Windows_y += 1 * windows_speed
    if 鼠标_x == 0 and 鼠标_y > 0:
      Windows_x += 1 * windows_speed
    if 鼠标_x > 0 and 鼠标_y == 1079:
      Windows_y -= 1 * windows_speed
    if 鼠标_x == 1919 and  鼠标_y > 0:
      Windows_x -= 1 * windows_speed



  x, y = pygame.mouse.get_pos()
  pygame.mouse.set_visible(False)
  if x>=0 and y==0:
    screen.blit(上[index % 3], (x,y))
    Pointer = False
  elif x>=0 and y==0:
    screen.blit(上[index % 3], (x,y))
    Pointer = False
    screen.blit(asd,(x, y))
  elif  x >= 0 and y == 1079:
    Pointer = False
  elif  x==1919 and y >= 0 :
    screen.blit(右[index % 3], (x,y))
    Pointer = False
  else:
    Pointer = True
    if Pointer:
      screen.blit(mouse_cursor, (x, y))

  index += 1


  pygame.display.update()



  • 写回答

1条回答 默认 最新

  • dabocaiqq 2020-08-24 15:02
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行