title: Move a sprite along a particular direction cocos2d
body: <p>I want to move a sprite along a particular direction until next keypress in cocos2d. </p>
  
  <p>The code to handle a keypress is as follows,</p>
  
  <pre><code>    def on_key_press(self, symbol, modifiers):
      if symbol == key.LEFT:
          DIRECTION="left"
          before=self.player.position
          height=self.player.position[1]
          width=self.player.position[0]-1
          self.player.position=width,height
          self.player.rotation=-90
          if(height&gt;=600 or height&lt;=0):
              print ("you lose)
          if(width&gt;=800 or width&lt;=0):
              print ("you lose)
  
  
      elif symbol == key.RIGHT:
          DIRECTION="right"
          before=self.player.position
          height=self.player.position[1]
          width=self.player.position[0]+1
          self.player.position=width,height
          self.player.rotation=90
          if(height&gt;=600 or height&lt;=0):
              print ("you lose)
          if(width&gt;=800 or width&lt;=0):
              print ("you lose")
          ...
  </code></pre>
  
  <p>I tried this function which calls the above function to keep the sprite moving along a direction,</p>
  
  <pre><code>    def keep_going(self,DIRECTION):
          if(DIRECTION=="left"):
              self.on_key_press(key.LEFT,512)
          ...
  </code></pre>
  
  <p>but the sprite easily goes beyond the screen boundaries, Is there a way to make the sprite move along the direction in a controlled fashion?</p>