self.direction = pygame.Vector2(1, 0)#Vector2(1,0) ; 属性错误 : '模块'对象没有'Vector2'属性

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

我有这样的错误,我不明白是什么问题,我试过很多方法来解决这个问题,但错误仍然存在。

Vector2替换为Vector2D也没有帮助。 我正在尝试旋转精灵,所以任何替代方法都可以。 我还试着用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)
    
3 个评论
它必须是 self.direction = pygame.math.Vector2(1, 0) 。请看 `pygame.math.Vector2`。
try importing pygame.math . It is required per pygame.org/docs/ref/math.html#pygame.math.Vector2
python
object
module
pygame
attributeerror
Anmol Harsh
Anmol Harsh
发布于 2019-07-28
1 个回答
Rabbid76
Rabbid76
发布于 2019-07-28
已采纳
0 人赞同

你要搜索的类是在 "我的 "中实现的。 pygame.math .
See pygame.math.Vector2

所以它必须是。

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

respectively