title: Sizing and scaling SKSpriteNode
body: <p>I have multiple game objects in my iOS game, some of which have a greater resolution than others. The graphics to use for the game object is chosen randomly at runtime. I'd like to make sure that they all don't go over a certain size when used, so I devised the following algorithm:</p>
  
  <pre><code>while self.spriteNode.rSize.width &gt; 100 &amp;&amp; self.spriteNode.rSize.height &gt; 100 {
      self.xScale -= 0.01
      self.yScale -= 0.01
  }
  </code></pre>
  
  <p>where spriteNode is the object whose texture is the graphic and rSize is an extended computed property on SKSpriteNode that returns the size of the accumulated frame of the node.</p>
  
  <p>Often, this results in an infinite loop. What's the problem?</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>Based on LearnCocos2D's comment, I have tried the following:</p>
  
  <pre><code>let reqXScale = 50/self.spriteNode.rSize.width
  let reqYScale = 50/self.spriteNode.rSize.height
  self.xScale = reqXScale
  self.yScale = reqYScale
  </code></pre>
  
  <p>Though this solves the infinite loop issue, some objects are squished rather than keeping their original aspect ratio.</p>
  
  <p>Also, here's the code that defines rSize:</p>
  
  <pre><code>var rSize: CGSize {
      return self.calculateAccumulatedFrame().size
  }
  </code></pre>
  
  <p>I have used this reliably multiple times before.</p>