Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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)

Python:
import pygame

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

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

# 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:
    screen.fill('white')

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

    screen.blit(small_img, small_rect)
    screen.blit(img, rect)
    pygame.display.flip()
    clock.tick(60)

1671781628466.png
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom