Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old January 22nd, 2003, 05:39 AM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
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

Reply With Quote
  #2  
Old January 22nd, 2003, 07:02 AM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
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.

Reply With Quote
  #3  
Old January 22nd, 2003, 05:20 PM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > som pygame questions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway