如何解决此弃用警告

时间:2019-12-14 16:19:08

标签: python python-3.x pygame

  

DeprecationWarning:必需为整数(got类型为float)。不建议使用int隐式转换为整数,并且可以在以后的Python版本中删除。

win.blit(playerStand, (x, y))

  

DeprecationWarning:必需为整数(got类型为float)。不建议使用int隐式转换为整数,并且可以在以后的Python版本中删除。

win.blit(walkLeft[animCount // 5], (x, y))

2 个答案:

答案 0 :(得分:0)

警告与blit()的坐标参数有关。浮点坐标将意味着Surface的原点在窗口像素之间。那没有多大意义。坐标会自动隐式地截断,并通过警告指示。
使用intround将浮点坐标转换为整数:

win.blit(playerStand, (round(x), round(y)))

答案 1 :(得分:-1)

该消息还会进行显式转换,因此,为了安全起见,请执行以下操作:

struct AnyShape: Shape {
    init<S: Shape>(_ wrapped: S) {
        _path = { rect in
            let path = wrapped.path(in: rect)
            return path
        }
    }

    func path(in rect: CGRect) -> Path {
        return _path(rect)
    }

    private let _path: (CGRect) -> Path
}

func shape(_ shape: SetGameModel.Card.Shape) -> some Shape {
    if shape == .diamond {
        return AnyShape(Diamond())
    } else if shape == .squiggle {
        return AnyShape(Rectangle())
    } else {
        return AnyShape(Ellipse())
    }
}

W1JGH

相关问题