小编Jak*_*ton的帖子

无法找到Pygame模块

我刚开始使用pygame在python中开发游戏,我有以下代码:

bif="main_background.jpg"
mif="player_head.png"

import pygame, sys
from pygame.locals import *

pygame.init()
screen=pygame.display.set_mode((640,360),0,64)

background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    screen.blit(background, (0,0))

    x,y = pygame.mouse.get_pos()
    x -= mouse_c.get_width()/2
    y -= mouse_c.get_height()/2

    screen.blir(mouse_c,(x,y))

    pygame.display.update()
Run Code Online (Sandbox Code Playgroud)

我在Python中收到以下错误:

Traceback (most recent call last):
  File "C:/Users/Eier/Documents/Code Developments/pygame.py", line 4, in <module>
    import pygame, sys
  File "C:/Users/Eier/Documents/Code Developments\pygame.py", line 5, in <module>
    from pygame.locals import *
ImportError: No module named locals
>>> 
Run Code Online (Sandbox Code Playgroud)

如果有人知道如何让python找到pygame请回复.

谢谢 :)

python pygame

0
推荐指数
1
解决办法
4883
查看次数

我无法理解我在这里做错了什么

我正在学习Pygame,我无法理解我怎么可能搞砸了.我得到的只是黑屏.

import pygame, sys
from pygame.locals import *

pygame.init()

screen = pygame.display.set_mode((640,360),0,32)
pygame.display.set_caption("Game!")

bg = pygame.image.load("graphics/bg.bmp").convert()
chris = pygame.image.load("graphics/chris.bmp").convert_alpha()

x,y=0,0
movex, movey=0,0

while True:

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
            if event.key==K_LEFT:
                movex=-1
            elif event.key==K_RIGHT:
                movex=+1
            elif event.key==K_UP:
                movey=-1
            elif event.key==K_DOWN:
                movey=+1
        if event.type==KEYUP:
            if event.key==K_LEFT:
                movex=0
            elif event.key==K_RIGHT:
                movex=0
            elif event.key==K_UP:
                movey=0
            elif event.key==K_DOWN:
                movey=0

    x+=movex
    y+=movey

    screen.blit(bg, (0,0))
    screen.blit(chris, (100, 100))

    pygame.display.update
Run Code Online (Sandbox Code Playgroud)

我从中得到的只是一个黑屏.bg.bmp是灰色背景图像,chris是具有相同背景的字符.这取自NewBostons教程.复制了一切.我有Python 2.7和Pygame 1.9.2 64bit

请帮忙 :)

python pygame

0
推荐指数
1
解决办法
66
查看次数

标签 统计

pygame ×2

python ×2