Python Forum
Pygame Class Sprite Placement Confusion
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pygame Class Sprite Placement Confusion
#2
ive got little time so i will be short to at least answer your question.

you need to pass in screen because the Ship object needs to know the size of the screen to be able to put hte ship in the center of the screen.

(Sep-11-2018, 06:22 AM)TheHumbleIdiot Wrote: self.rect.centerx = self.screen_rect.centerx #What the hell is this doing? I have no idea.
self.rect.bottom = self.screen_rect.bottom #Yet again the books explanation doesn't really help nor does google
you are setting the center screen x position (from left to right) to the Ship's object center and setting the rects bottom to the bottom of the screen. This will put the ship in the center of the screen width wise, but at the top-down wise. Pygame rects have positions and you can move the image with the pygame rect instead of saving an x and y coordinate yourself. This is why you blit the image to the rect position because you are moving the rect.

Regardless of the what you think currently, putting the ship content like this in the Ship class makes it much more organized and easier to identify and fix problems. As well as for others like us to understand. So its not complex by any means to us. The ships position, image, drawing ,etc are done inside the class. This clears up your main game loop which is what you want to constantly keep doing. As the Ship class starts to get bigger and bigger you will understand why its all in a class.
Recommended Tutorials:
Reply


Messages In This Thread
RE: Pygame Class Sprite Placement Confusion - by metulburr - Sep-11-2018, 11:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Sprites just randomly appear and dissapear in my pygame.sprite.GoupeSingle trueShadoWrr 2 2,029 Feb-13-2023, 09:34 AM
Last Post: Vadanane
  [PyGame] Pygame is treating blob_group as a surface, when I need it to treat it as a Sprite. Swagford 1 1,342 Jan-24-2023, 09:58 PM
Last Post: metulburr
  FileNotFoundError when I try putting sprite in Pygame zionkozisek 9 16,268 Dec-09-2020, 04:42 AM
Last Post: zionkozisek
  [PyGame] My Pygame Sprite not appearing... noodlespinbot 3 3,880 Oct-30-2020, 06:51 AM
Last Post: robinmurphy
  My Pygame Sprite not appearing... noodlespinbot 1 2,289 Apr-08-2020, 11:25 AM
Last Post: pyzyx3qwerty
  [PyGame] Sprite image.get_rect() moves sprite to 0, 0 michael1789 2 4,634 Dec-13-2019, 08:37 PM
Last Post: michael1789
  Pygame sprite not moving michael1789 1 2,871 Nov-10-2019, 03:54 AM
Last Post: michael1789
  Sprite not rendering Clunk_Head 2 2,184 Oct-03-2019, 11:27 AM
Last Post: Clunk_Head
  Need help making a sprite GalaxyCoyote 4 3,305 Aug-11-2019, 09:12 PM
Last Post: metulburr
  moving a sprite pfaber11 3 2,633 May-15-2019, 12:52 PM
Last Post: pfaber11

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020