0

I am working on a platformer game. There is a lot of code which I am not including here. I am including my imports and the method which is giving me the problem. This is a button function which should change color when hovered over. The action has not been added yet, I am still trying to figure out why pygame.mouse.get_pos() is not working as it should.

 import pygame as pg
 import random
 from settings import *
 from sprites import *
 from os import path

 def botton(self,rectac,rectic,txtc,f_size,x,y,w,h,txt,xt,yt,action=None):

    mouse = pg.mouse.get_pos()

    print(mouse)

    if x+w>mouse[0]>x and y+h>mouse[1]>y:

        pg.draw.rect(self.screen,rectac,(x,y,w,h))
    else:
        pg.draw.rect(self.screen,rectic,(x,y,w,h))

    self.draw_text(txt,f_size,txtc,xt,yt)

 print(x,y)

But, when I run the program, I noticed that the program does not enter the if condition. So, I printed mouse. The result I get is just one set of coordinates,that is, the position of the mouse when I run the program. It does not give me anything else.

P.S. This is not a homework problem, it is a personal project that I am working on.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • is `botton` being called inside some sort of loop? It'll only print the mouse coordinates when it's called, and if it isn't called after the program starts, the mouse position value isn't going to update. – numbermaniac May 27 '17 at 08:04
  • It isn't directly in a loop. The botton method is being called by another 'start screen' method, and this in turn is being called by the game loop method. – Anirudh Gottiparthy May 28 '17 at 15:31

0 Answers0