Проблема:
переменные offset_x, offset_y, в блоке "event.type == pg.MOUSEMOTION" выдают ошибку SyntaxError: имя 'offset_x' присваивается перед нелокальным объявлением Я попытался объявить эти переменные глобальными, но получаю то же сообщение об ошибке. я не знаю что делать.
import pygame as pg
import settings
from pointer import Pointer
import fractaltree
from railslider import Rail
pg.init()
# clock
clock = pg.time.Clock()
def screen_info_and_setfsrcreen():
fullscreen_sz = pg.display.Info().current_w, pg.display.Info().current_h
print('screen size =', fullscreen_sz)
#if pg.display.Info().current_w != settings.width or pg.display.Info().current_h != settings.height:
# settings.screensize = (pg.display.Info().current_w - 100, pg.display.Info().current_h - 100)
screen_info_and_setfsrcreen()
screen = pg.display.set_mode(settings.screensize, pg.RESIZABLE)
# drawline for branches
global offset_x
global offset_y
offset_x = 0
offset_y = 0
def mousetraking(pointer):
dragging = True
if event.type == pg.MOUSEBUTTONDOWN:
if event.button == 1:
if pointer.collidepoint(*pg.mouse.get_pos()):
dragging = True
(Xmouse, Ymouse) = pg.mouse.get_pos()
offset_x = pointer.posx - Xmouse
offset_y = pointer.posy - Ymouse
elif event.type == pg.MOUSEBUTTONUP:
if event.button == 1:
dragging = False
elif event.type == pg.MOUSEMOTION:
if dragging:
mouse_x, mouse_y = event.pos
pointer.update(mouse_x + offset_x, mouse_y + offset_y)
print("did something")
if dragging == False or event.type == pg.MOUSEBUTTONUP or event.type == pg.MOUSEBUTTONDOWN or event.type == pg.MOUSEMOTION:
pointer.update(pointer.posx, pointer.posy)
# main loop
rail = Rail(20, 20, screen)
pointer = Pointer(20,20,screen)
dragging = False
displaying = True
while displaying:
for event in pg.event.get():
if event.type == pg.QUIT:
displaying = False
mousetraking(pointer)
rail.update()
pg.display.flip()
clock.tick(60)
screen.fill(settings.white)
pg.quit()