简体   繁体   English

无法使用 pygame.math.Vector 2 定义向量

[英]Can't define a Vector with pygame.math.Vector 2

I'm starting with pygame programming and I've seen vectors are useful x and y variables.我从 pygame 编程开始,我已经看到向量是有用的 x 和 y 变量。

The issue is that i cant even define a vector because pycharm throws the following:问题是我什至无法定义向量,因为 pycharm 抛出以下内容:

在此处输入图像描述

This is the body of the script:这是脚本的主体:

import pygame as pg


class Character(pg.sprite.Sprite):

    def __init__(self, ai_game):
        pg.sprite.Sprite.__init__(self)
        # Game
        self.screen = ai_game.screen
        self.screen_rect = self.screen.get_rect()
        self.settings = ai_game.settings

        'Initialize position'
        self.rect.midbottom = self.screen_rect.midbottom
        self.pos = pg.math.Vector2(1, 2)

Pycharm throws `"Unexpected arguments" and the following inspection Description: Pycharm 抛出`“Unexpected arguments”和以下检查说明:

"Reports discrepancies between declared parameters and actual arguments, as well as incorrect arguments.

I've been looking for the solution for hours but I can't simply make it work.我一直在寻找解决方案几个小时,但我不能简单地让它工作。 The most frustrating part is the everywhere I see they define the vectors the same way I'm trying to, and it looks so simple.最令人沮丧的部分是我看到他们以与我尝试相同的方式定义向量的任何地方,它看起来很简单。

There is no error in your code.您的代码中没有错误。 A pygame.math.Vector2 can be constructed either by a single argument, which is a tuple of 2 coordinates or 2 separate arguments. pygame.math.Vector2可以由单个参数构造,该参数是 2 个坐标的元组或 2 个单独的 arguments。 In fact, you discovered a bug in the IDE.事实上,您在 IDE 中发现了一个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM