хорошо, я хочу нарисовать круг с начальной точкой, и координаты конечной точки, начальная точка и конечная точка оба Vector2
startpoint = pygame.math.Vector2(0, 0)
endpoint = pygame.math.Vector2(0, 0)
def redraw_game_window():
win.fill((0,0,0))
line_one = line(startpoint, endpoint, (255,0,0), 2)
line_one.draw(win)
print("EndPoint: ",endpoint)
print("StartPoint: ",startpoint)
pygame.draw.circle(win, (0,0,255), startpoint, 3, 0)
pygame.draw.circle(win, (0,255,0), endpoint, 3, 0)
pygame.display.update()
"pygame.draw.circle ..." - проблема, ошибка равно
File "lines.py", line 43, in redraw_game_window
pygame.draw.circle(win, (0,0,255), startpoint, 3, 0)
TypeError: integer argument expected, got float
, и когда я ввожу любые другие координаты, например:
pygame.draw.circle(win, (0,0,255), (500, 250), 3, 0)
pygame.draw.circle(win, (0,255,0), (100, 147), 3, 0)
, тогда он работает нормально, например, почему? почему Vector2 не работает (вот полный код)
#Lines
import pygame
import os
import sys
import random
import math
#Init the game
pygame.init()
#Display
win_width = 800
win_height = 600
win = pygame.display.set_mode((win_width, win_height))
#Display settings
pygame.display.set_caption("lines")
#Variables
startpoint = pygame.math.Vector2(0, 0)
endpoint = pygame.math.Vector2(0, 0)
class line():
def __init__(self, start, end, color, thickness):
self.start = start
self.end = end
self.color = color
self.thickness = thickness
def draw(self, win):
pygame.draw.line(win, self.color, self.start, self.end, self.thickness)
def redraw_game_window():
win.fill((0,0,0))
line_one = line(startpoint, endpoint, (255,0,0), 2)
line_one.draw(win)
print("EndPoint: ",endpoint)
print("StartPoint: ",startpoint)
pygame.draw.circle(win, (0,0,255), startpoint, 3, 0)
pygame.draw.circle(win, (0,255,0), endpoint, 3, 0)
pygame.display.update()
run = True
while run:
#Quit event
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
mousex, mousey = pygame.mouse.get_pos()
startpoint = pygame.math.Vector2(mousex, mousey)
print("LEFT CLICK")
if event.button == 3:
mousex, mousey = pygame.mouse.get_pos()
endpoint = pygame.math.Vector2(mousex, mousey)
print("RIGHT CLICK")
#Redraw game window
redraw_game_window()
pygame.quit()
Спасибо, ребята.