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

Re: [pygame] [pygame ] Having trouble with RenderUpdate



Hi Hugo.

Yeah, what u said it was right mutch easier doing self.rect.topleft being self.rect= image.get_rect()
ok. so i`ve done that.
Thanks on that one, lol i was planing something way to complicated.

So it is solved thanks i realized i must call the group.clean to work right?

so now i have this:

class Arrow(pygame.sprite.Sprite):
    def __init__(self,a=0,b=0):
           #iniciates position and image
           pygame.sprite.Sprite.__init__(self)
           self.image=pygame.image.load("Arrow.png")
           self.posicao=[a,b]
           self.rect=self.image.get_rect()
def start(self):
       "blits arrow in the screen in position and update"
R_up.clean(screen,current_background_image) #clears the sprite self.rect.topleft=((self.posicao[0],self.posicao[1])) #gets position a=R_up.draw(screen) #blits to screen pygame.display.update(a) #updates the 2 rect, the former from clear and the new one


Thanks a lot guys.
I think i got it.
Is this how it is suposed to work right?
It works fine the arrow now, then i press up or down it moves acordingly and it delets the former.




Hugo Arts wrote:
using self.rect = image.get_rect() gets you a rect with the correct size. you can use self.rect.topleft = (100, 200) to set the position, that will save you some lines. saw this second e-mail only after replying to the first one. sorry.

On Mon, Sep 15, 2008 at 9:16 AM, KKarasu <catsareninja@xxxxxxxxx <mailto:catsareninja@xxxxxxxxx>> wrote:

    Thanks Andy.

    I think i understood.the get rect always returned at (0,0) and
    that was a problem.
    so basicaly my code did was: create surface at 0,0 and move it to
    posicao=[x,y] (yes posicao is position i used my own language
    variables and forgot to translate, sorry)
    then draw it with group.draw, updating the (0,0) surface,right?
    what happened was this:
    http://kkarasu.deviantart.com/art/second-title-screen-97971437
    #tìs my devart site, it got the screen shot there

    So i need to keep track of where the surface is at a moment.
    shall i create an artificial rect class?

    Example:

    class Arrow(pygame.sprite.Sprite):
        #this is the possition of the sprite and size
        self.x = 100
        self.y=  200
        self.height = 90
        self.width = 70
        self.rect= pygame.Rect(self.x,self.y,self.width,self.height)

        def DRAW(self):
                       a=R_up.draw(screen) #this will use .draw in the
    R_up== RenderUpdate group with arrow in it using suposedly the
    self.rect to track position
                       pygame.display.update(a)

      #to move the arrow i just have to update the self.x and self.y
    values and call self.rect again to update its values

    would this work? or theres a better option?
    I thinking loud here, im gonna try it now.