So I am following a tutorial called Coding Math on youtube. It is coded in JS and i try to replicate it with pygame. In order to make a centered arrow on the canvas point toward the position of the mouse cursor. To achieve this the creator of the tutorial uses a method to recalibrate the coordinate system of the canvas calling a context.rotate function and subsequently always draws the arrow for the same coordinates while the coordinate system rotates.
How to achieve this in pygame? I tried using the pg.transform function but it won't do the job.
Here is my code:
center = cx,cy = WIDTH // 2, HEIGHT // 2
radius = 30
pointer = cx+radius, cy
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
sys.exit()
mouse = pg.mouse.get_pos()
screen.fill((25,25,25))
saved_screen = screen.copy()
adjacent = mouse[0] - cx
opposite = mouse[1] - cy
alpha = math.atan2(opposite,adjacent)
screen.blit(pg.transform.rotate(screen, math.degrees(alpha)),(0,0))
# ~ x = math.cos(alpha) * radius +cx
# ~ y = math.sin(alpha) * radius +cy
# ~ pointer = x,y
pg.draw.line(screen, RED, center, pointer, 3)
pg.draw.line(screen, BLUE, center, pointer, 1)
screen = saved_screen
pg.display.flip()
clock.tick(30)
The commented part is how i get it to work by just calculating a new triangle for the updated position of the cursor.
I already tried putting the transform function in various places but none of them achieve what I want.
Thanks in advance