[英]Moving mouse in the game window stops the game (pygame)
問題:
如果我的鼠標光標在窗口外,我的游戲就會運行,但是如果我的光標在控制台內,則會出現此錯誤
Traceback (most recent call last):
File "c:/Users/jackw/Desktop/New folder/main.py", line 36, in <module>
if event.type == pg.QUIT():
TypeError: 'int' object is not callable
繼承人我的代碼
import pygame as pg
from Config import *
from bin import *
# initialising pygame
pg.init()
class Game():
def background(self,background):
window.blit(background, (0,0))
# defining classes for use
g = Game()
# game loop
while isrunning:
# making sure the game is running on a constant clock
time.tick(fps)
# add background
g.background(gameback)
# setting up events
for event in pg.event.get():
# closing window event
if event.type == pg.QUIT():
isrunning = False
# input events
# show finished frame
pg.display.flip()
# Last code before closing the window
# closing the window
pg.quit()
大多數變量定義在不同的文件配置文件gamevars 文件中
該程序在 macOS 上運行良好,我只在 Windows 10 上出現此錯誤。這是該錯誤的 視頻
QUIT
不是一個方法或函數,它是一個枚舉常量,它指定了事件的類型(參見pygame.event.Event()
)。
去掉括號解決問題:
if event.type == pg.QUIT():
if event.type == pg.QUIT:
pg.QUIT 是一個枚舉值。 它基本上是一個整數。 您的代碼出於某種原因添加了括號; 這是無效的語法。 僅使用
if event.type == pg.QUIT:
你編碼的東西有點像
if event.type == 4():
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.