title: Rect that is different sized than image
body: <p>I wanted to try something new and found <a href="https://www.youtube.com/watch?v=VO8rTszcW4s&amp;list=PLsk-HSGFjnaH5yghzu7PcOzm9NhsW0Urw&amp;index=1" rel="nofollow noreferrer">this tutorial</a> on the web. I used it and tweaked it a little. My goal is to create a zelda clone, meaning my game will be Tile-Based</p>
  
  <p>Now for the problem.
  All my sprites are not in 1:1 Ratio. The rect's size I created is TILESIZE * TILESIZE (=64 height, 64 width). </p>
  
  <p>Now the rect sticks to the top:</p>
  
  <p><a href="https://i.stack.imgur.com/FoS57.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FoS57.png" alt="enter image description here"></a></p>
  
  <p>but I need it to stick to the bottom center of my sprite:</p>
  
  <p><a href="https://i.stack.imgur.com/GMHMt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GMHMt.png" alt="enter image description here"></a></p>
  
  <p>for collision detection.</p>
  
  <p>I tried numerous ways and asked my workmates, but they can't help me either.</p>
  
  <pre><code>class Player(pg.sprite.Sprite):
      def __init__(self, game, x, y):
          self.groups = game.all_sprites
          pg.sprite.Sprite.__init__(self, self.groups)
          self.images = []
  
          def addImage(image):
              self.images.append(load_image(path.join(img_folder, "zelda_green", image)))
              print(self.images[-1].get_size())
              scale = TILESIZE/self.images[-1].get_width()
              #print(tuple([scale*x for x in self.images[-1].get_size()]))
              print(scale)
              self.images[-1] = pg.transform.scale(self.images[-1], tuple([int(scale*x) for x in self.images[-1].get_size()]))
  
          addImage("walk1.png")
          addImage("walk2.png")
          addImage("walk3.png")
          addImage("walk4.png")
          addImage("walk5.png")
          addImage("walk6.png")
          addImage("walk7.png")
          addImage("walk8.png")
          addImage("walk9.png")
          addImage("walk10.png")
  
          self.index = 0
          self.image = self.images[self.index]
          self.rect = pg.Rect(0, 0, TILESIZE, TILESIZE)
          self.game = game
          self.vel = vec(0,0)
          self.pos = vec(x,y) * TILESIZE
          self.vx, self.vy = 0,0
          self.x = x * TILESIZE
          self.y = y * TILESIZE
  
      def get_keys(self):
          self.vel = vec(0,0)
          keys = pg.key.get_pressed()
          if keys[pg.K_LEFT] or keys[pg.K_a]:
              self.vel.x = -PLAYER_SPEED
          if keys[pg.K_RIGHT] or keys[pg.K_d]:
              self.vel.x = PLAYER_SPEED
          if keys[pg.K_UP] or keys[pg.K_w]:
              self.vel.y = -PLAYER_SPEED
          if keys[pg.K_DOWN] or keys[pg.K_s]:
              self.vel.y = PLAYER_SPEED
          if self.vel.x != 0 and self.vy != 0:
              self.vel.x *= 0.7071
              self.vel.y *= 0.7071
  
      def move(self, dx=0, dy=0):
          if not self.collide_with_walls(dx, dy):
              self.x += dx
              self.y += dy
  
      def collide_with_walls(self, dir):     
          if dir == 'x':
              hits = pg.sprite.spritecollide(self, self.game.walls, False)
              if hits:
                  if self.vel.x &gt; 0:
                      self.pos.x = hits[0].rect.left - self.rect.width
                  if self.vel.x &lt; 0:
                      self.pos.x = hits[0].rect.right
                  self.vel.x = 0
                  self.rect.x = self.pos.x
          if dir == 'y':
              hits = pg.sprite.spritecollide(self, self.game.walls, False)
              if hits:
                  if self.vel.y &gt; 0:
                      self.pos.y = hits[0].rect.top - self.rect.height
                  if self.vel.y &lt; 0:
                      self.pos.y = hits[0].rect.bottom
                  self.vel.y = 0
                  self.rect.y = self.pos.y
  
      def update(self):
          global initTime
          frameTime = time.time() - initTime
  
          if frameTime &gt;= 0.075:
              initTime = time.time()
              self.index += 1
          if self.index &gt;= len(self.images):
              self.index = 0
          self.image = self.images[self.index]
          self.get_keys()
          self.pos += self.vel * self.game.dt
          self.rect.x = self.pos.x
          self.collide_with_walls('x')
          self.rect.y = self.pos.y
          self.collide_with_walls('y')
  </code></pre>