Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23305

How to deal with a wrap-around rectangle for an object in pygame if the object's coordinates are at (0,0)

$
0
0

I have some code to wrap a rectangle around some text in pygame:

import pygame as pgfont = pg.font.SysFont("Comic Sans MS", 30)def wrapRect(obj, color='Black'):    rect = obj.get_rect()    pg.draw.rect(obj, color, rect.inflate(10,10), 2)    return objplayButton = wrapRect(font.render('Play', True, 'Black'))screen.blit(playButton, (200, 170))

I made wrapRect to wrap a rectangle around the object given as a parameter.

This code doesn't work because before the blit() function places the text at the desired coordinates, I'm assuming the play button's default coordinates were (0,0), so when I used the inflate() function, it made those coordinates negative. As a result, the surrounding rectangle did not show. How do I make it so that wrapRect takes into account the fact that I may want to reposition the object beyond (0,0)?


Viewing all articles
Browse latest Browse all 23305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>