refactor: 修改绘制辅助函数以支持浮点半径,更新精灵结构体以使用浮点数表示半径,确保图形处理更精确。

This commit is contained in:
lixiangwuxian
2025-05-10 12:57:58 +08:00
parent 2c2f855198
commit 0959b16b9d
2 changed files with 15 additions and 15 deletions

View File

@@ -72,7 +72,7 @@ func (l *Line) AddToSprite(sprite *Sprite) {
type Circle struct {
Center image.Point
Radius int
Radius float64
Color color.Color
}
@@ -81,13 +81,13 @@ func (c *Circle) AddToSprite(sprite *Sprite) {
// 检查精灵是否已有图像
if sprite.Image == nil {
// 如果没有图像,创建一个新图像
size := c.Radius * 2
size := int(c.Radius * 2)
img := image.NewRGBA(image.Rect(0, 0, size, size))
sprite.Image = img
// 设置精灵位置为圆心减去半径
sprite.Position = image.Point{
X: c.Center.X - c.Radius,
Y: c.Center.Y - c.Radius,
X: c.Center.X - int(c.Radius),
Y: c.Center.Y - int(c.Radius),
}
}