0

Im not trying to use classes for this cause im trying to get the cords of my mouse then test if they are in the posistion of a blit which moves an image over to the button and when nopt hovering over it it is not there, images are at the bottom, i want it to show that im hovering over it if that makes sense

import pygame as pg

def window_settings():
    global screen, size, clock, FPS
    FPS = 60
    pg.init()
    size = (900,900)
    screen = pg.display.set_mode(size)
    clock = pg.time.Clock()
    pg.display.set_caption("CHESS")

#---------------IMAGES---------------#
titleIMG = pg.image.load('sprites/titleIMG.png')
hoverPlayIMG = pg.image.load('sprites/hoverPlayIMG.png')

#----------------DEF-----------------#
title_screen = True
BLACK = (0,0,0)
playIMG = 1000
hoverOver = False

def titleScreen():
    global playIMG, mposHover1, mposHover2, hoverOver
    if mposHover1 >= 279 and mposHover1 <= 603 and mposHover2 >= 513 and mposHover2 <= 625 and hoverOver == False:
        hoverOver = True
        playIMG -= 1000
    if hoverOver == True and playIMG == 0:
        print('hi')
        playIMG += 1000
        hoverOver == False

window_settings()
run = True
while run == True:
    screen.fill(BLACK)
    for event in pg.event.get():
        if event.type == pg.QUIT:
            run = False
        if title_screen == True:
            mposHover1, mposHover2 = pg.mouse.get_pos()
            #print(mposHover1, mposHover2)
            if event.type == pg.MOUSEBUTTONDOWN:
                mpos1, mpos2 = pg.mouse.get_pos()
                print(mpos1, mpos2)

        titleScreen()

    screen.blit(titleIMG, [0,0])
    screen.blit(hoverPlayIMG, [playIMG,playIMG])

    pg.display.flip()   
    clock.tick(FPS)

pg.quit()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • That is answered several times. e.g. [Pygame mouse clicking detection](https://stackoverflow.com/questions/10990137/pygame-mouse-clicking-detection/64533684#64533684). – Rabbid76 Aug 10 '21 at 20:09
  • There is typo in `titleScreen`. `hoverOver == False` must be `hoverOver = False` – Rabbid76 Aug 10 '21 at 20:53
  • `hoverOver` is a variable in global namespace. Therefore it is not necessary to change the coordinate. Draw the image depending on `hoverOver`: e.g: `if hoverOver:` `screen.blit(hoverPlayIMG, (279, 513))` – Rabbid76 Aug 10 '21 at 20:56

0 Answers0