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

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



Some comments:

You should realize that a Sprite is the combination of a Rect + a
Surface.  So you don't need to keep a .posicao attribute.  The
position of the sprite is just the topleft corner of its .rect.

 class Arrow(pygame.sprite.Sprite):
    def __init__(self,a=0,b=0):
           pygame.sprite.Sprite.__init__(self)
           self.image=pygame.image.load("Arrow.png")
           self.rect=self.image.get_rect()
           self.rect.topleft = [a,b]

 def start(self):
       "blits arrow in the screen in position and update"
       R_up.clean(screen,current_background_image)
       a=R_up.draw(screen)
       pygame.display.update(a)



>
> 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.
>>
>>
>
>