- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在 Pygame 中编写游戏。我一直遇到这个错误,但我不明白如何修复它。它运行pauseMenu()init并打印其中的内容,以便它可以运行它,但之后我陷入困境。任何帮助将不胜感激。
确切的错误:
Traceback (most recent call last):
File "C:/Users/derek/Desktop/current workspace/Red_Fox/main.py", line 85, in <module>
start()
File "C:/Users/derek/Desktop/current workspace/Red_Fox/main.py", line 37, in start
60
mainLoop()
File "C:/Users/derek/Desktop/current workspace/Red_Fox/main.py", line 67, in mainLoop
pauseMenu.pauseMenuFunct(DISPLAYSURF,(WINWIDTH,WINHEIGHT))
TypeError: pauseMenuFunct() missing 1 required positional argument: 'WINDIM'
main 在这里,我调用的文件在它下面。
import pygame,sys
from Player import *
from Block import *
from menu import *
from pauseMenu import *
from pygame.locals import *
goToMenu = True
def start():
pygame.init()
menuScreen = MenuScreen()
pMenu = pauseMenu()
global DISPLAYSURF,BRIGHTBLUE,FPSCLOCK, \
FPS,player,objects, \
WINHEIGHT,WINWIDTH,goToMenu, \
objectsFP,WINDIM
FPS = 60 # frames per second to upate the screen
WINWIDTH = 800 # width of the program's window, in pixels
WINHEIGHT = 600 # height in pixels
WINDIM = WINWIDTH,WINHEIGHT
#WINWIDTH = 1920 # width of the program's window, in pixels
#WINHEIGHT = 1080 # height in pixels
FPSCLOCK = pygame.time.Clock()
BRIGHTBLUE = ( 0, 170, 255)
DISPLAYSURF = pygame.display.set_mode((WINWIDTH, WINHEIGHT))
FPSCLOCK = pygame.time.Clock()
#player = Player(100,100)
objects = []
objectsFP = []
if goToMenu:
goToMenu = False
menuState = menuScreen.menuFunct(DISPLAYSURF,WINDIM,BRIGHTBLUE)
if menuState == 0:
initGame()
worldGen()
mainLoop()
elif menuState == 1:
print('Will have options here')
#global DISPLAYSURF,BRIGHTBLUE,FPSCLOCK,FPS
def worldGen():
for i in range(int(WINHEIGHT/2),WINHEIGHT,10):
for j in range(0,WINWIDTH,10):
objects.append(Block(j,i))
if(i == int(WINHEIGHT/2)):
objectsFP.append(Block(j,i))
print('happened dawg')
for o in objectsFP:
o.draw(DISPLAYSURF)
def initGame():
print('in initGame()')
objects.append(Player(100,100))
def mainLoop():
while True:
DISPLAYSURF.fill(BRIGHTBLUE)
for event in pygame.event.get():
if event.type == QUIT:
quitCleanUp()
elif event.type == KEYDOWN:
objects[0].keyDownUpdate(event)
if event.key == K_ESCAPE:
print(FPS)
pauseMenu.pauseMenuFunct(DISPLAYSURF,(WINWIDTH,WINHEIGHT))
elif event.type == KEYUP:
objects[0].keyUpUpdate(event)
for i in objects:
i.update()
i.draw(DISPLAYSURF)
#objectsFP = objects.copy()
objects[0].objUpdate(objectsFP)
#player.update()
#player.draw(DISPLAYSURF)
pygame.display.update()
FPSCLOCK.tick(FPS)
def quitCleanUp():
pygame.quit()
sys.exit()
if __name__ == '__main__':
start()
这是我试图调用的另一个类。
import pygame,time,sys
from pygame import *
class pauseMenu():
goToMenu = False
imageDict = {}
textDict = {}
rectDict = {}
Clicked_Button = ''
DarkGrey = (134, 134, 134)
volume = 10
FPSCLOCK = pygame.time.Clock()
def pauseMenuFunct(self,screen,WINDIM):
print("made it here")
def check_collisions(self,pos,list):
# iterate dict, check for collisions in systems
# print('Made it to teh da function')
for k,v in list.items():
# print('Made into to the for loop')
if v.collidepoint(pos):
# print(v)
# print("clicked button:", k)
self.Clicked_Button = k
# print(self.Clicked_Button)
return True,k
WINWIDTH,WINHEIGHT = WINDIM
# print('Made it to the function')
# screen.fill(background)
imageDict = {'buttons': pygame.image.load('Resources/Pics/PauseOptions.png')
}
imageDict['buttons']=pygame.transform.smoothscale(imageDict['buttons'],(int(WINWIDTH*.2),(int(WINHEIGHT*.1))))
buttonX,buttonY= imageDict['buttons'].get_size()
# print(buttonX , buttonY)
textSize = int(buttonY/2)
# print(textSize)
self.font = pygame.font.Font('Resources/chunkfont.ttf', textSize)
textOptions = self.font.render("Options", 1, self.DarkGrey)
textSave = self.font.render("Save", 1, self.DarkGrey)
textQuit = self.font.render("Quit", 1, self.DarkGrey)
textVolume = self.font.render("Volume", 1, self.DarkGrey)
textBackToGame = self.font.render('Return', 1, self.DarkGrey)
VolumePopUp = self.font.render(str(self.volume), 1, self.DarkGrey)
textBackToMenu = self.font.render('Menu', 1 , self.DarkGrey)
self.rectDict['Options'] = screen.blit(imageDict['buttons'], (WINWIDTH/4,(WINHEIGHT/3)))
self.rectDict['Save'] = screen.blit(imageDict['buttons'], (WINWIDTH/2+60.5,WINHEIGHT/3))
self.rectDict['Quit'] = screen.blit(imageDict['buttons'], (WINWIDTH/4,(WINHEIGHT/2)))
self.rectDict['Volume'] = screen.blit(imageDict['buttons'], ((WINWIDTH/2+60.5),(WINHEIGHT/2)))
self.rectDict['Return'] = screen.blit(imageDict['buttons'], (WINWIDTH/4,(WINHEIGHT/1.5)))
self.rectDict['Menu'] = screen.blit(imageDict['buttons'], (WINWIDTH/2+60.5,WINHEIGHT/1.5))
self.textDict['textOptions'] = screen.blit(textOptions,(WINWIDTH/4 + (buttonX/4),(WINHEIGHT/3+textSize/2)))
self.textDict['textQuit'] = screen.blit(textQuit,(WINWIDTH/4 + (buttonX/4),(WINHEIGHT/2+textSize/2)))
self.textDict['textSave'] = screen.blit(textSave,(WINWIDTH/2+60.5 + (buttonX/3),(WINHEIGHT/3+textSize/2)))
self.textDict['textVolume'] = screen.blit(textVolume,(WINWIDTH/2+50.5 + (buttonX/4.5),(WINHEIGHT/2+textSize/2)))
self.textDict['textBacktoGame']= screen.blit(textBackToGame,(WINWIDTH/4+ (buttonX/4),(WINHEIGHT/1.5+textSize/2)))
self.textDict['textMenu']= screen.blit(textBackToMenu,(WINWIDTH/2+60.5+ (buttonX/4),(WINHEIGHT/1.5+textSize/2)))
self.textDict['volumeNum']= screen.blit(VolumePopUp,(WINWIDTH/2+55.5 + buttonX/1.25,(WINHEIGHT/2+textSize/2)))
pygame.display.update()
print('made it to the update')
while True:
self.FPSCLOCK.tick(60)
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit()
elif event.type == MOUSEBUTTONDOWN:
if event.button == 1:
if check_collisions(self,event.pos,self.rectDict):
# print('Button Clicked from Event Loop is: '+self.Clicked_Button)
if self.Clicked_Button == 'Quit':
sys.exit()
elif self.Clicked_Button == 'Save':
print('It will be saved later')
elif self.Clicked_Button == 'Volume' and self.volume>0:
self.volume -= 1
print(self.volume)
VolumePopUp = self.font.render(str(self.volume), 1, self.DarkGrey)
screen.blit(imageDict['buttons'], ((WINWIDTH/2+60.5),(WINHEIGHT/2)))
screen.blit(VolumePopUp,(WINWIDTH/2+55.5 + buttonX/1.25,(WINHEIGHT/2+textSize/2)))
pygame.display.update(self.textDict['volumeNum'])
elif self.Clicked_Button == 'Return':
print('This will close the menu and you return you to the game.')
elif self.Clicked_Button == 'Options':
print('This will take you to an options screen')
#TODO Return values
elif self.Clicked_Button == 'Menu':
print('Will take you to main menu sooner or later')
elif event.button == 3:
if check_collisions(self,event.pos,self.rectDict):
if self.Clicked_Button == 'Volume' and self.volume<10:
self.volume += 1
print(self.volume)
VolumePopUp = self.font.render(str(self.volume), 1, self.DarkGrey)
screen.blit(imageDict['buttons'], ((WINWIDTH/2+60.5),(WINHEIGHT/2)))
screen.blit(VolumePopUp,(WINWIDTH/2+55.5 + buttonX/1.25,(WINHEIGHT/2+textSize/2)))
pygame.display.update(self.textDict['volumeNum'])
#TODO Return volume values
def __init__(self):
print('PauseMenu _init_ ran')
最佳答案
您正在类本身上调用 pauseMenu
:
pauseMenu.pauseMenuFunct(DISPLAYSURF,(WINWIDTH,WINHEIGHT))
这是一个未绑定(bind)的函数,因此不会为您填写 self
。
您还在某处创建了一个实例:
def start():
pygame.init()
menuScreen = MenuScreen()
pMenu = pauseMenu()
也许您打算改为调用 pMenu.pauseMenuFunct()
?
关于python - Pygame 类型错误 : missing 1 required positional argument:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19034714/
Surface.blit在 1.8 中有一个新参数:混合。定义了以下值: BLEND_ADD BLEND_SUB BLEND_MULT BLEND_MIN BLEND_MAX BLEND_RGBA_A
import sys import pygame import pygame.locals as pgl class Test: def __init__(self): pyg
我对 PyGame 比较陌生。我正在尝试制作一个简单的程序来显示表示鼠标在屏幕上的位置的字符串。 import pygame, sys from pygame.locals import * pyga
我有总是在后台运行的音乐和一些在触发时会播放声音的事件。音乐效果很好。 pygame.mixer.music.load(os.path.join(SOUND_FOLDER, 'WateryGrave.
我有这些代码 FONT = pygame.font.Font("font/calibri.ttf", 50) FONT.size = 25 但是编译器说 AttributeError: 'pygame
有我正在导入的图像: look_1 = pygame.image.load('data\\png\\look1.png').convert_alpha() 我试图减少它的大小是这样的: pygame.
我正在为我的 pygame 制作一个帮助屏幕,每当我运行它时,我都会收到此错误消息: > self.surface.blit(self.helpscreen) TypeError: argument
在 pyGame 中应用程序,我想渲染 SVG 中描述的无分辨率 GUI 小部件。 我怎样才能做到这一点? (我喜欢 OCEMP GUI 工具包,但它的渲染似乎依赖于位图) 最佳答案 这是一个完整的例
有没有办法将多首歌曲加载到 Pygame 中?我不是在谈论这样的音效; crash_sound = pygame.mixer.Sound("crash.ogg") #and pygame.mixer.
我还有一个问题。当我尝试运行我的代码时,pygame 启动然后立即停止。 这是我的代码: import pygame import os import time import random pygam
我正在使用 pymunk 和 pygame 开发一个项目。我正在使用 PivotJoint 约束将我的 body 连接在一起。如果可能的话,我想让关节不可见 - 有什么办法可以做到这一点吗?现在关节在
我使用 fedora 20、Python 2.7 和 virtualenv 1.10.1。我想在 virtualenv 中安装 pygame,我得到了 You are installing a pot
尝试将文本添加到矩形中并使用箭头键在屏幕上移动矩形。我想让文字不会超出边缘。到目前为止,我已经在没有将其放入 Rect 中的情况下工作了,但我想让 Rect 函数工作。现在文本只是反弹回来,我不知道要
我是第一次玩 pygame(总的来说我是 python 的新手),想知道是否有人可以帮助我... 我正在制作一款小型射击游戏,希望能够为坏人创建一个类。我的想法是类应该继承自 pygame.Surfa
我在 Windows 10 机器上运行了 python 3.9.1。我通过 pip 在我的机器上安装了 pygame 2.0.1 (python -m pip install https://gith
错误: File "/home/alien/cncell/core/animator.py", line 413, in create_animation_from_data pygame
这是代码。 5000 个弹跳旋转的红色方块。 (16x16 png) 在 pygame 版本上,我获得 30 fps,但使用 pyglet 获得 10 fps。对于这种事情,OpenGl 不应该更快吗
我以为 pygame.font.Font 是用来加载 .ttf 字体的,如果没有 .ttf 文件在同一个目录下就无法加载字体,但我看过一个视频,有人在没有 .ttf 文件的情况下加载字体。 ttf 字
我正在尝试使用 Travis CI 设置一个项目。项目也使用 pygame。我曾多次尝试设置它 - 但它似乎失败了。 我得到的最接近的是以下内容: .travis.yml : language: py
这个问题已经有答案了: Python error "ImportError: No module named" (38 个回答) 已关闭 3 年前。 我正在使用 Mac 并输入 pip install
我是一名优秀的程序员,十分优秀!