omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    [SOLVED] Player Scale Acting Up

    Pythonista
    1
    2
    649
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RocketBlaster05
      RocketBlaster05 last edited by ccc

      Hello! I have a player where I need to scale them down to properly fit the size I need, and I also need to change their x_scale to make them flip. However If I set the overall scale before the x_scale, it results in the player being stretched outwards horizontally. If I put the overall scale AFTER the x_scale, the character remains small but does not flip directions. Here is the code I am using:

      #This is the code that results in the character not flipping directions
      #All necessary imports are present
      #And yes, this is working off of the built in game tutorial example
      def cmp(a, b)
          return ((a > b) - (a < b))
      
      def update_player(self):
          g = gravity()
          if abs(g.x) > 0.05:
              self.player.x_scale = cmp(g.x, 0)
              self.player.scale = (0.1) #scale comes after x_scale
              x = self.player.position.x
              max_speed = 40
              x = max(0, min(self.size.w, x + g.x * max_speed))
              self.player.position = x, 32
              step = int(self.player.position.x / 40) % 2
              if step != self.walk_step:
                  self.player.texture = walk_textures[step]
                  sound.play_effect('rpg:Footstep00', 0.05, 1.0 + 0.5 * step)
                  self.walk_step = step
          else:
              self.player.texture = standing_texture
              self.walk_step = -1
      
      #------------------------------------------------------------
      
      #This is the code that results in the character stretching horizontally
      #All necessary imports are present
      #And yes, this is working off of the built in game tutorial example
      def cmp(a, b)
          return ((a > b) - (a , b))
      
      def update_player(self):
          g = gravity()
          if abs(g.x) > 0.05:
              self.player.scale = (0.1) #scale comes before x_scale
              self.player.x_scale = cmp(g.x, 0)
              x = self.player.position.x
              max_speed = 40
              x = max(0, min(self.size.w, x + g.x * max_speed))
              self.player.position = x, 32
              step = int(self.player.position.x / 40) % 2
              if step != self.walk_step:
                  self.player.texture = walk_textures[step]
                  sound.play_effect('rpg:Footstep00', 0.05, 1.0 + 0.5 * step)
                  self.walk_step = step
          else:
              self.player.texture = standing_texture
              self.walk_step = -1
      
      
      1 Reply Last reply Reply Quote 0
      • RocketBlaster05
        RocketBlaster05 last edited by

        Nevermind I solved it by dividing the x_scale value by (in my case) 10 and now it works fine.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB Forums | Contributors