使用 vector2 时,我在 pygame 中遇到错误

问题描述

我得到一个

不支持 += 的操作数类型:'nonetype' 和 'pygame.math.Vector2'

运行以下代码

#tab-button {
  display: table;
  table-layout: fixed;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

#tab-button li a {
  display: block;
  padding: 0.5em;
  background: #95a5a6;
  text-align: center;
  color: #000;
  text-decoration: none;
  height: 100%;
}

错误在第 15 行

解决方法

方法 return 中缺少 Player.get_pix_pos 语句:

class Player:
    # [...]

    def get_pix_pos (self):
        return vec((self.grid_pos.x*self.app.cell_width)+TOP_BOTTOM_BUFFER//2+self.app.cell_width//2,(self.grid_pos.y*self.app.cell_height)+TOP_BOTTOM_BUFFER//2+self.app.cell_height//2)