【问题标题】:I can't draw lines in Pygame我无法在 Pygame 中画线
【发布时间】:2020-12-22 08:15:13
【问题描述】:

我做了一个 Pygame 程序,我试着画一条线。 但每次我运行程序时,它都会向我显示:

  File "/Documents/game.py", line 47
    pygame.draw.line(win, (255,255,255), (0,375), (500,375))
    ^
SyntaxError: invalid syntax

我的代码:

#!/usr/bin/env python
import pygame
from pygame.locals import *
import sys
import threading
import random
import os
base_path = os.path.dirname(__file__)
bg_path = os.path.join(base_path, "imports/bg.png")
bgimg = pygame.image.load(bg_path)
cannon_path = os.path.join(base_path, "imports/cannon.png")
cannonimg = pygame.image.load(cannon_path)
bullet_path = os.path.join(base_path, "imports/bullet.png")
bulletimg = pygame.image.load(bullet_path)
target_path = os.path.join(base_path, "imports/target.png")
targetimg = pygame.image.load(target_path)
icon_path = os.path.join(base_path, "imports/icon.png")
iconimg = pygame.image.load(icon_path)
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption("ShootIt!")
pygame.display.set_icon(iconimg)
while True:
    pygame.time.delay(25)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:           
            pygame.quit()
            sys.exit()     
    keys = pygame.key.get_pressed()
    bg = win.blit(bgimg, (0,0))
    cannon = win.blit(cannonimg, (225,225)
    pygame.draw.line(win, (255,255,255), (0,375), (500,375))
    pygame.display.update()

顺便说一句,我使用的是 Mac OS X、Python 3.8.3 和 Pygame 2.0.0。

【问题讨论】:

    标签: python python-3.x pygame line draw


    【解决方案1】:

    在显示错误的行之前的行中,缺少)

    cannon = win.blit(cannonimg, (225,225)
    

    【讨论】:

    • 哇。太感谢了!你真的帮助了我!
    猜你喜欢
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    • 2020-05-30
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    相关资源
    最近更新 更多