Try to figure it out with this:

class image_button():
    def __init__(self, img, x, y, function=None):
        self.img=image.load(img)
        self.x,self.y=x,y
        self.function=function
        win.push_handlers(self.on_mouse_press)
    def __inside(self, x, y):
        in_x=(x>=self.x) and (x<=self.x+self.img.width)
        in_y=(y>=self.y) and (y<=self.y+self.img.height)
        return in_x and in_y
    def on_mouse_press(self, x, y, button, modifiers):
        if self.__inside(x,y): self.click()
    def click(self):
        if self.function!=None: self.function()
    def blit(self):
        self.img.blit(self.x,self.y,0)

----- Original Message ----- 
From: <[EMAIL PROTECTED]>
To: "pyglet-users" <[email protected]>
Sent: Sunday, February 17, 2008 5:02 PM
Subject: Re: Draw animations, graphic buttons


>
> There are plenty of basic game programming tutorials on the internet
> that tell you how to do this. Google 'rectangle collision' or
> something.
>
> On Feb 17, 7:44 am, yoshi <[EMAIL PROTECTED]> wrote:
>> How can you check if the mouse is within the bounding box of an
>> image ?
>>
>> On Feb 16, 11:21 pm, "Drew Smathers" <[EMAIL PROTECTED]> wrote:
>>
>> > On Feb 16, 2008 7:37 AM, Zaka <[EMAIL PROTECTED]> wrote:
>>
>> > > Hi.I'm new in pyglat and python. I write my first code. And i have 
>> > > one
>> > > question how to write my animations when i click WSAD or other
>> > > buttons.
>>
>> > This has all the information you need:
>>
>> >http://pyglet.org/doc/programming_guide/image_sequences.html
>>
>> > There are plenty of examples in the pyglet source code 
>> > (pyglet/examples) you
>> > can look at for inspiration as well.  (Use the source Luke!)
>>
>> > And my other question. How to make graphic button i try make GUI.
>>
>> > Make a rectangle (glBegin(GL_QUADS) ... glEnd()) or load an image that 
>> > looks
>> > like a button.  In your mouse handler, check to see if you're inside 
>> > the
>> > bounding box of the button when you've clicked.  If you are, call a 
>> > function
>> > associated with the button that does something interesting.
>>
>> > (If you're unimpressed, understand that pyglet is not high-level GUI 
>> > toolkit
>> > with out-of-the box widgets, etc.)
>>
>> > Cheers,
>> > --
>> > \\\\\/\"/\\\\\\\\\\\
>> > \\\\/ // //\/\\\\\\\
>> > \\\/  \\// /\ \/\\\\
>> > \\/ /\/ / /\/ /\ \\\
>> > \/ / /\/ /\  /\\\ \\
>> > / /\\\  /\\\ \\\\\/\
>> > \/\\\\\/\\\\\/\\\\\\
>> >               d.p.s
> >
>
>
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.516 / Virus Database: 269.20.7/1283 - Release Date: 
> 16/02/2008 14:16
>
> 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to