Referencing previous frames values Python Pygame -


i have simple piece of code. program loops @ 60 fps want reference previous mouse click state. i.e. have 'one' variable mouse click state, 0 not clicked , 1 clicked. want happen if mouse clicked i.e. 1 = 1 & previous value of 1 0 i.e. unclicked save value of mx , mouse co-ordinates. please see code below:

pdimagefull = pygame.image.load('f:\project files\coils\pdsinwaveresize.jpg') pdresx = 300 pdresy = 720  gamedisplay = pygame.display.set_mode((display_width,display_height))   pygame.display.set_caption('pd diagnostic tool') clock = pygame.time.clock()  def pdimage(x, y):     gamedisplay.blit(pdimagefull, (x, y))  # defining our main programing loop  def mainprogram_loop():     dx1 = (display_width-pdresx)     dy1 = (display_height-pdresy)        gameexit = false  # event handling     while not gameexit:         mx, = pygame.mouse.get_pos()         one, two, 3 = pygame.mouse.get_pressed()         event in pygame.event.get():             if event.type == pygame.quit:                 gameexit = true              # expression controls movement of overall pd graph             # section in if statement defines boundary can move object             if 1 == 1 , mx > dx1 , mx < dx1 + pdresx , > dy1 , < dy1+pdresy:                  dx1 = dx1 + (mx - pdresx)                 dy1 = dy1 + (my - pdresy)          gamedisplay.fill(white)         pdimage(dx1, dy1)         pygame.display.update()         clock.tick(60)   mainprogram_loop() 

just use variable:

prev_one = 1 one, two, 3 = pygame.mouse.get_pressed()  if prev_one == 0 , 1 == 1:     print 'mouse clicked frame' 

be aware have initialise one default value @ start of script.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -