我是一个刚接触 pygame 库的开发人员,我想找出问题所在。我目前正在尝试开发迷你高尔夫游戏,但这是主要问题。显示的错误是:TypeError: invalid position for blit
power = 0
angle = 0
ballPos = (width//2 - golfBallWidth//2, 550)
ballVel = [0, 0] # x and y velocity components of the ball
ballAcc = [0, 0] # x and y acceleration components of the ball
ballMass = 0.0459 # mass of the golf ball in kg
frictionCoeff = 0.15 # coefficient of friction between ball and ground
holePos = (holePosX, holePosY)
def friction():
global ballVel, ballAcc
frictionalForce = frictionCoeff * ballMass * 9.81 #Calculates frictional force
frictionalDirection = math.atan2(-ballVel[1], -ballVel[0]) #Direction of friction
frictionalX = frictionalForce * math.cos(frictionalDirection) #components of frictional force
frictionalY = frictionalForce * math.sin(frictionalDirection)
ballAcc[0] += frictionalX/ballMass #applying fric force to ball
ballAcc[1] += frictionalY/ballMass
def setBallVelocity(power, angle, ballVel):
ballVel[0] = power * math.cos(angle)
ballVel[1] = power * math.sin(angle)
def ballPositioning():
global ballPos
ballPos = list(ballPos)
ballPos[0] += ballVel[0] * oneFrame
ballPos[1] += ballVel[1] * oneFrame
ballPos = tuple(ballPos)
def drawLevelOne(ballPos)
friction()
setBallVelocity(power, angle, ballVel)
ballPositioning()
WIN.blit(levelBackground, (0,0))
WIN.blit(courseHole, (holePosX, holePosY))
WIN.blit(golfBall, (ballPos))
pygame.display.update()`
我尝试在两个不同的地方打印变量 ballPos。一个紧随其后
ballPos = tuple(ballPos)
就在排队之前
WIN.blit(golfBall, (ballPos))
我认为两者都有一个元组值,但只有在“ballPos = tuple(ballPos)”行之后打印的那个正在打印并且实际上在其中有一个值。老实说,我不太确定出了什么问题。第二行之后的输出只是'()'
如果有人能提供帮助,将不胜感激! :)