自我方向 = pygame。矢量2(1, 0)#Vector2(1,0) ;属性错误:'module'对象没有属性'Vector2'


self.direction = pygame.Vector2(1, 0)#Vector2(1,0) 
AttributeError: 'module' object has no attribute 'Vector2'

我对此有错误,我不明白问题是什么,我尝试了很多事情来解决此问题,但是错误弹出了相同的

Vector2D替换Vector2也没有帮助我试图旋转精灵,以便任何替代方案也可以做我还尝试使用math.Vector2D,但它没有识别它,并且导入错误弹出

import pygame
import random
##from pygame import Vector2
from os import path
import os
import sys
import math
..
..
self.direction = pygame.Vector2(1, 0)

您要搜索的类是在pygame.math中实现的。
请参阅pygame.math.Vector2

所以必须是:

import pygame
self.direction = pygame.math.Vector2(1, 0)

分别

from pygame.math import Vector2
self.direction = Vector2(1, 0)

最新更新