Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
pygame中python的图像不好_Python_Pygame - Fatal编程技术网

pygame中python的图像不好

pygame中python的图像不好,python,pygame,Python,Pygame,我有一个python程序: import sys, random, pygame from pygame.locals import * pygame.init() # Preparing Pygame size = width, height = 718, 502 screen = pygame.display.set_mode(size) framerate = pygame.time.Clock() pygame.display.set_caption('Flappy Cube') #

我有一个python程序:

import sys, random, pygame
from pygame.locals import *
pygame.init()

# Preparing Pygame
size = width, height = 718, 502
screen = pygame.display.set_mode(size)
framerate = pygame.time.Clock()
pygame.display.set_caption('Flappy Cube')

#Peparing background
background_x = 0
background_y = 0
background = pygame.image.load("background.jpg")


#Preparing Cube
cube_x = 100
cube_y = 200
cube_unscaled = pygame.image.load("cube.png")
cube = pygame.transform.smoothscale(cube_unscaled, (64, 64))

#Preparing Tubes
tube_x = 750
tube_y= 300
tube_unscaled = pygame.image.load("tube.png")
tube = pygame.transform.smoothscale(tube_unscaled, (125, 500))



# The main game loop
def exit_game():
        sys.exit()

while True:
        #Background
        screen.blit(background, (background_x,background_y))
        background_x = background_x+254.5
        screen.blit(cube,(cube_x, cube_y))
    #Tube
    tube_x = tube_x -.075
    screen.blit(tube,(tube_x, tube_y))
    # If exit
    for event in pygame.event.get():
            if event.type == pygame.QUIT: exit_game()
    # If Space Key is presed
            elif event.type == pygame.KEYDOWN and event.key == K_SPACE:
                    cube_y = cube_y-10
    #If Clicked
            elif pygame.mouse.get_pressed()[0]:
                    cube_y = cube_y-10   
    framerate.tick(60)
    pygame.display.flip()
run_game()
我得到这个结果:

我必须提高
framerate.tick(60)
framerate.tick(700)
它看起来很油滑。当我对重力进行编程时,多个图像看起来不太好

如何修复屏幕更新前多次绘制的图像?

尝试:

cube_unscaled = pygame.image.load("cube.png").convert_alpha()
你不需要以这种方式提高FPS,60是一个很好的值

另外,我更喜欢主循环的顺序:检查事件、绘制、更新、勾选

我不认为这对你的问题有什么影响,但我认为这样更容易理解

while True:

    # If exit
    for event in pygame.event.get():
        if event.type == pygame.QUIT: exit_game()

        # If Space Key is presed
        elif event.type == pygame.KEYDOWN and event.key == K_SPACE:
            cube_y = cube_y-10

        #If Clicked
        elif pygame.mouse.get_pressed()[0]:
                cube_y = cube_y-10

    #Background
    screen.blit(background, (background_x,background_y))
    background_x = background_x+254.5

    screen.blit(cube,(cube_x, cube_y))

    #Tube
    tube_x = tube_x -.075
    screen.blit(tube,(tube_x, tube_y))

    pygame.display.flip()
    framerate.tick(60)

我修好了!我只需要在“闪动”之前用黑色填充屏幕。

嗯,我想知道你想做什么:Dlol。。。飞鸟关上门后,我出发了。。。但是我在换管子,问题是立方体看起来怎么样,对吗?