程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么我的屏幕不能用 pygame 在 python 中更新?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决为什么我的屏幕不能用 pygame 在 python 中更新??

开发过程中遇到为什么我的屏幕不能用 pygame 在 python 中更新?的问题如何解决?下面主要结合日常开发的经验,给出你关于为什么我的屏幕不能用 pygame 在 python 中更新?的解决方法建议,希望对你解决为什么我的屏幕不能用 pygame 在 python 中更新?有所启发或帮助;

我正在用 pygame 编写代码,但我的屏幕没有用 pygame.display.flip() 更新 有人可以帮我吗?

我的代码: 主文件:

import pygame
pygame.init()
from game import Game

pygame.display.set_caption("Run !")
screen = pygame.display.set_mode((1080,680))

game = Game()

running = True

while running:
    game.update(screen)

    pygame.display.flip()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = false
            pygame.quit()
        elif event.type == pygame.KEYDOWN:
            game.key_pressed[event.key] = True
        elif event.type == pygame.KEYUP:
            game.key_pressed[event.key] = false
@H_262_8@

游戏文件:

import pygame
from player import Player

class Game(pygame.sprite.SpritE):

    def __init__(self):
        super().__init__()
        self.player = Player()
        self.key_pressed = {}

    def update(self,screen):
        screen.blit(self.player.image,self.player.rect)


        if self.key_pressed.get(pygame.K_RIGHT):
            self.player.move_right()
        if self.key_pressed.get(pygame.K_left):
            self.player.move_left()
        if self.key_pressed.get(pygame.K_Up):
            self.player.move_up()
        if self.key_pressed.get(pygame.K_DOWN):
            self.player.move_down()

        pygame.display.flip()


@H_262_8@

和播放器文件:

import pygame

class Player(pygame.sprite.SpritE):

    def __init__(self):
        super().__init__()
        self.veLocity = 3
        self.image = pygame.image.load('res/player.png')
        self.image = pygame.transform.rotozoom(self.image,0.9)
        self.rect = self.image.get_rect()

    def move_right(self):
        self.rect.x += self.veLocity

    def move_left(self):
        self.rect.x -= self.veLocity

    def move_up(self):
        self.rect.y -= self.veLocity

    def move_down(self):
        self.rect.y += self.veLocity

@H_262_8@

我可以看到玩家移动(它是一个蓝色方块),但之前的图像没有被删除。所以当它移动时我看到一条蓝线而不是一个正方形

非常感谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的为什么我的屏幕不能用 pygame 在 python 中更新?全部内容,希望文章能够帮你解决为什么我的屏幕不能用 pygame 在 python 中更新?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:pygame