2
Like pygame
does not have a function similar to the library SFML -> View, I am developing a "camera" format to scroll the screen and preserve the positions of objects within the general coordinate within the "world".
As a standard of pygame
, use the rectangle.
To facilitate manipulation, I want to change the variables left
and top
obtained in the get_rect, adding camera offset to these variables.
Following this example by @jsbueno, I’m having a hard time:
I have a class class Sprite(pygame.sprite.Sprite)
and inside it I take the rectangle of an image and store self.ret = self.imagem.get_rect()
. So I want to return a different amount than self.ret.left
every time this variable is accessed.
But in declaring @property
and just below def ret.left(self):
i get illegal target for variable annotation
. What would be the correct sitaxe in this case?
import pygame
class Sprite(pygame.sprite.Sprite):
def __init__(self, imagem, x, y):
self.imagem = pygame.image.load('imagem.png')
self.ret = self.imagem.get_rect()
@property
def ret.left(self): # aqui aparece o erro
What would that be
self.ret
within the class, between the two methods? Is it indented wrong or was it to be so? As for the error,ret.left
shouldn’t beret_left
?– Woss
Names of
funções
ormétodos
do not allow use of the character.
.– ThiagoO
@Andersoncarloswoss, sorry, it was an edit error, I corrected.
ret
is an instance of the classpygame.Surface.Rect
(https://www.pygame.org/docs/ref/surface.html#pygame.Surface.get_rect)– Rogério Dec
I’d like to know how I can interfere with reading the variable
self.ret.left
using@property
?– Rogério Dec
I improved the original question at the beginning to clarify my goal.
– Rogério Dec