[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Rect attribute on pygame.draw.rect(screen, color, Rect, width=0)
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Rect attribute on pygame.draw.rect(screen, color, Rect, width=0)
- From: Sam Bull <sam.hacking@xxxxxxxx>
- Date: Mon, 03 Sep 2012 15:46:05 +0100
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Mon, 03 Sep 2012 10:46:19 -0400
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sent.com; h= message-id:subject:from:to:date:in-reply-to:references :content-type:mime-version; s=mesmtp; bh=2C3MPTwudrU4xbmRP7aMx8c pn9E=; b=DtteJ48nubK1Hhp9a7aqfM4YZ5unneHdSqgx1gxii2GKt1BkFEnEqEy 7s1C4MggtBdERxNcYYqUHkiu+Y0fRurZbUILKe0WS46S9JuJxQwsIZn9DDTr0HrV f63zU1MA1F2dEsTHIo5H2Ic1sEouP+BlUtK8+J4Pid/mHDY9L9EM=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:subject:from:to:date :in-reply-to:references:content-type:mime-version; s=smtpout; bh=2C3MPTwudrU4xbmRP7aMx8cpn9E=; b=ZYnX98/OgvQYi0krYmRF7eWZwubZ w5I+QIB4O03A6XwKuhPN7xKuabltpVWPyCeBrnaOEoYG7Z2sr9wYHe6bzOrBUosF WV5X2PUpofaTO3YXl4Qydlq4bdsuQBPvgp2hxAWdKtzVYZ78e3VlAI+V4sx/Iz3H 0XvhxTCS2U7Rdjs=
- In-reply-to: <1346619173109-167.post@xxxxxxxxxxxxx>
- References: <1346619173109-167.post@xxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
On Sun, 2012-09-02 at 13:52 -0700, mr_Roboman4321 wrote:
> Hello. I'm trying to assign the rect attribute in a pygame.draw.rect()
> statement to a mouse position. here's my code (it's inside a while True:
> loop):
>
> Mouse = pygame.mouse.get_pos()
> MouseRect = pygame.draw.rect(screen, RED, (Mouse, 100, 100), 1)
pygame.draw.rect(screen, Color("red"), (Mouse, (100, 100)), 1)
will work. The rect argument must be either 4 numbers, or 2 sequences
giving 2 numbers each, i.e. (x,y,w,h) or ((x,y), (w,h)). Mouse is a 2
item sequence.
I also imagine you want it centred so you will also need to change:
Mouse = pygame.mouse.get_pos()
Mouse = (Mouse[0] - 50, Mouse[1] - 50)
> what I am trying to do with this is to see if the mouse has passed over any
> of my sprite rects. If there is an easier way to do this, show that way.
That code only draws a rectangle, it does not do any kind of collision
detection, this will not tell you (or the program) if the mouse is over
a sprite. If you want to actually check collision in your code, you need
something like:
m = pygame.mouse.get_pos()
for s in sprites:
if s.rect.collidepoint(m):
print "Colliding with", s
Attachment:
signature.asc
Description: This is a digitally signed message part