Hi, I am currently making a pixel editor. And I was making the drawing tools, when I hit a problem. I was making a system where it will show how the canvas will look like before something is drawn (You will understand it better when you try the script out). The current way I am doing it is by copying the main surface(canvas) to another surface (pre_view) when the mouse is pressed, then it just draws the line on it, then resets the surface(recopying the main canvas). And when it the mouse is released that surface is copied to the main surface. But, the problem is, the line shifts a bit when it is copied to the main surface. I tried may things work on fixing it for many hours , but nothing.
Here is the code:
Here is the code:
#------------------------ Import Bay ------------------------ import pygame #------------------------ loading bay------------------------ pencil = pygame.image.load("Assets/tools/Pencil_tool/Pencil_tool_icon(Large)-export.png") eraser = pygame.image.load("Assets/tools/Eraser_tool/Eraser_tool.png") #------------------------ Variable Bay------------------------ version = "0.0.1" running = True current_tool = 0 colour = (255,255,255) #------------------------Init Bay------------------------ pygame.init() screen = pygame.display.set_mode((800,600)) canvas = pygame.Surface((64, 64)) pre_view = pygame.Surface.copy(canvas) pygame.display.set_caption("Pyxe") icon = pygame.image.load("Assets/icons3.png") pygame.display.set_icon(icon) #------------------------Main Loop------------------------ screen.fill((62,53,70)) while running: mouse = pygame.mouse.get_pos() mouse_buttons = pygame.mouse.get_pressed() scaled_pos = (mouse[0] - 336, mouse[1] - 236 ) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN: Dest =scaled_pos = (mouse[0] - 336, mouse[1] - 236 ) if mouse_buttons[0] == 1: print("button 0 Active") pre_view = pygame.Surface.copy(canvas) pygame.draw.line(pre_view, colour ,Dest, scaled_pos) screen.blit(pre_view, (336,236)) if event.type == pygame.MOUSEMOTION: pre_view == pygame.Surface.copy(canvas) if event.type == pygame.MOUSEBUTTONUP: canvas = pygame.Surface.copy(pre_view) screen.blit(canvas, (336, 236)) if event.type == pygame.KEYDOWN: if event.key == pygame.K_s: pygame.image.save(pre_view, "canvas.png") print("saving......") screen.blit(pencil, (734, 60)) screen.blit(eraser, (734, 120)) pygame.display.update()Thanks for helping
