![](/img/trans.png)
[英]How to fix Type Error in Pygame: TypeError: unsupported operand type(s) for +=: 'int' and 'pygame.math.Vector2'
[英]unsupported operand type(s) for +: 'pygame.math.Vector2' and 'int'
我不知道发生了什么,我找不到其他有同样问题的人。 这是我的代码:
import pygame
import math
import random
import os
SWIDTH = 800
SHEIGHT = 600
vec = pygame.math.Vector2
FRI = 0.3
ACC = 1
这是错误
File "C:\Users\USERNAME\Desktop\games\GAME.py", line 137, in update
self.loc += self.vel + 1 + self.aird
类型错误:+ 不支持的操作数类型:“pygame.math.Vector2”和“int”
self.vel
是pygame.math.Vector2
。 您不能将整数添加到 object。
您可以总结2个向量:
self.loc += self.vel
或者您可以向向量的分量添加一个值(标量):
self.loc.x += self.vel.x + 1
self.loc.y += self.vel.y + 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.