[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] moving a filled circle from top to bottom



Changing the order might help with procedural images. Then you can make the rect's attributes work for you.

        self.rect = pygame.Rect(0,0,50,50)
        self.image = pygame.surface.Surface(self.rect.size)
        pygame.draw.circle(self.image, pygame.Color(0, 0, 255), self.rect.center, self.rect.width/2)
        self.image.set_colorkey(pygame.Color('black'))
        self.rect.center = 320,0

Gumm

On Mon, Sep 27, 2010 at 2:40 PM, kevin hayes <kevinosky@xxxxxxxxx> wrote:
Hey...thank you!  I'm now on someone else's computer, so I can't edit the code, but I trust that you are correct. Thanks again. Kevin


On Mon, Sep 27, 2010 at 1:37 PM, Christopher Night <cosmologicon@xxxxxxxxx> wrote:
It's extremely minor. Change the center of your circle from (320, 0) to (25, 25). The coordinates are with respect to self.image, not to screen.

-Christopher


On Mon, Sep 27, 2010 at 4:32 PM, kevin hayes <kevinosky@xxxxxxxxx> wrote:
Hi,
        This is my attempt at sending a circle(Sprite) vertically from the top of the screen to the bottom.  Can someone
tell me how to change the code so it works?  Currently it is just creating a white screen. Thanks in advance. Kevin

"""Attempt at moving a circle(Sprite) from top(of screen) to bottom"""

import pygame
pygame.init()

screen = pygame.display.set_mode((640, 480))

class Circle(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((50, 50))
        self.image.fill((255, 255, 255))                                        #fill with white to hide square???
        pygame.draw.circle(self.image, (0, 0, 255), (320, 0), 25)
        self.rect = self.image.get_rect()
        self.rect.centerx = 320
        self.rect.centery = 0

    def update(self):
        self.rect.centery += 5
        if self.rect.top > screen.get_height():
            self.rect.bottom = 0


def main():
    pygame.display.set_caption("Verticle Circle Sprite")

    background = "">
    background.fill((255, 255, 255))
    screen.blit(background, (0, 0))

    circle = Circle()
    allSprites = pygame.sprite.Group(circle)

    clock = pygame.time.Clock()
    keepGoing = True
    while keepGoing:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                keepGoing == False

        allSprites.clear(screen, background)
        allSprites.update()
        allSprites.draw(screen)

        pygame.display.flip()

if __name__ == "__main__":
    main()

pygame.quit()