• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python How do I make it so that the point of the coin that is at, say (200,200) is the centre point of it? (Pygame)

import pygame

clock = pygame.time.Clock()
fps = 60

screen_size = (1280, 960)
screen = pygame.display.set_mode(screen_size)

# Path to image
path = 'Python/pygame'

# Load the image
img = pygame.image.load(f'{path}/coin.png')

# Get image rectangle
rect = img.get_rect()

# Set image center to screen center
rect.center = ((screen_size[0]/2, screen_size[1]/2))

# Scale image
small_img = pygame.transform.scale(img, (rect[2]/2, rect[3]/2))

# Get small image rect
small_rect = small_img.get_rect()

# Center small image to rect. Note divided screen height as to not place small image on large one
small_rect.center = (screen_size[0]/2, screen_size[1]/4)

running = True
while running:

    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        running = False

    screen.blit(small_img, small_rect)
    screen.blit(img, rect)

Top Bottom