Reputation: 57
am using this code to draw rectangle in my image,
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image=pygame.image.load(os.path.join(image_folder,"Player.png"))
self.rect = self.image.get_rect()
self.vel_x = 0
self.speed = 30
self.friction = 3.5
self.rect.center = (420,360)
self.delta = clock.tick(FPS) / 1000.00
but the method get_rect() is drawing the rectangle on the entire loaded image like this
Upvotes: 2
Views: 1370
Reputation: 106
You could create a rectangle where you know the hull will be, if the hull will be in the same place and the same size every time
self.rect = pygame.Rect(hulltop,hullleft,hullwidth,hullheight)
In your case hullwidth
might be the image width and hullheight
looks like your image height minus hulltop
.
If you have different hulls, you might consider having the hull and the mast/sail in separate image files, creating your outline of just the hull, then joining the images. Alternatively you could create a dict of the different hull sizes and use that to determine the size and position of the rectangle to draw.
Upvotes: 3
Reputation: 12747
You're getting the Rect
of the image. If you want to have a differently sized Rect
, you're going to need to create one.
Upvotes: 1