【问题标题】:Get X and Y Cordinates from Vector2从 Vector2 获取 X 和 Y 坐标
【发布时间】:2021-03-15 14:00:16
【问题描述】:

如何确定pygame.math.Vector2 对象的 x 和 y 坐标?

self.position = Vector2(x, y)

这是 Vector2 中 x 和 y 的输出:

[5,14.5]

【问题讨论】:

  • 在不知道Vector2() 是什么的情况下很难提供帮助。
  • 它是一个导入:from pygame.math import Vector2

标签: python vector pygame output coordinates


【解决方案1】:

来自docs

可以使用属性检索或设置向量的坐标 或下标

v = pygame.Vector3()

v.x = 5 
v[1] = 2 * v.x 
print(v[1]) # 10

v.x == v[0] 
v.y == v[1] 
v.z == v[2]

可以使用切片或混合设置多个坐标

v = pygame.Vector2()  
v.xy = 1, 2  
v[:] = 1, 2

【讨论】:

  • 只需使用self.position.xself.position.y,如您在示例中所见。
  • 我在上一条评论中确实做到了
  • 我不知道你的期望是什么
猜你喜欢
  • 1970-01-01
  • 2022-11-13
  • 2012-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多