#1
  1. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14

    som pygame questions


    I've recently started fiddling with pygame (python's SDL wrappings), and I'm getting a little stuck, due to lack of documentation (i.e. docs that help newbies, not reference material for people who already know how to use most of pygame's features).

    I'm trying to make some simple concept games just to feel my way in, and in one I want to make a menu that runs along the top of the screen, with some buttons in it. I want to constrict the mouse's movements so it can only move within this menu, and then I want to bind functions to each button.

    To begin with, I cannot figure out a nice way to constrict the mouse. The only way I can think of is to use the get_pos() and set_pos() functions, and every time set_pos() finds a y value greater than the border of the menu, I set_pos() the y value to be the border value, so I kep pushing it back. Is that the only way?

    Secondly, this should be really simple, but I haven't been able to get at any example code to find out (I'm on a windoze machine in uni that doesn't have anything installed to handle Zips, and I don't have permission to install anything that will): I want to have buttons to click on. Now I've blitted the images up, I've got objects for their rectangles - what is the code to then check if, on MOUSEBUTTONUP, the mouse is in that rectangle?

    Thanks for any pointers
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    14
    I've only done very little with pygame, so I'm not incredibly familiar with their API. But, your logic for constricting the mouse seems sound enough. If there's a better way, I don't know what it is. And for your second question, though I imagine there's an easier way, one way you can test to see if anything is within the rectangle is simply to get the object position, width, and height and check if its x coordinate is between the min_x and max_x for the object, and if they y coord is between the min_y and max_y.
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  4. #3
  5. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14
    With the mouse thing, I tried that, and it was incredibly jittery - the mouse would move out by a few pixels, then jump back, and continue doing that. It looks awful, so I'm sure there's a nicer way, but maybe that's not implemented in pygame

    Thanks, though

IMN logo majestic logo threadwatch logo seochat tools logo