title: How should I set up my touch controls in starling?
body: <p>I am developing a game in starling that has two controls. One will be the users left thumb touching anywhere on the left side of the screen, which drags the character up and down the y axis. The other control that I am having trouble implementing is a single button in the bottom right of the screen that will make the character fire a bullet.</p>
  
  <p>My question is how do I set this up without having the character jump down to the bottom of the screen whenever the button is pressed.</p>
  
  <p>Will I need to mess with multi-touch in order to get this running?</p>
  
  <p>A more specific question I have is how do I define a rectangle for a sprite in starling? Since starling has no drawing API, I can't just do this...</p>
  
  <pre><code>        touchLayer.graphics.beginFill(0x000000, 0);
          touchLayer.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
          touchLayer.graphics.endFill(); 
  </code></pre>
  
  <p>Currently my character drag is working, but the touch registers everywhere on the screen (im not sure how to make it just the left side of the screen...)</p>
  
  <p>Any advise would be appreciated, thank you.</p>
  
  <p>Here is the complete code for my InGame class as requested.</p>
  
  <pre><code>package screens
  {
      import flash.geom.Point;
      import flash.geom.Rectangle;
      import flash.utils.getTimer;
  
      import objects.Enemy;
      import objects.GameBackground;
      import objects.Laser;
      import objects.Scarlet;
      import objects.SnowBall;
  
      import starling.display.Button;
      import starling.display.Sprite;
      import starling.events.Event;
      import starling.events.Touch;
      import starling.events.TouchEvent;
      import starling.utils.RectangleUtil;
      import starling.utils.deg2rad;
  
      public class InGame extends Sprite
      {
          private var startBtn:Button;
          private var fireBtn:Button;
          private var bg:GameBackground;
          private var scarlet:Scarlet;
  
          private var enemies:Array;
          private var lasers:Array;
          private var scarletLocation:Point;
  
          private var lasersLayer:Sprite;
          private var enemiesLayer:Sprite;
          private var touchLayer:Sprite;
  
          private var enemySpawnDelay:Number;
          private var enemySpawnCounter:Number;
  
          private var difficulty:Number;
          private var difficultyRate:Number;
  
          private var timePrevious:Number;
          private var timeCurrent:Number;
          private var elapsed:Number;
  
          private var gameState:String;
          private var playerSpeed:Number;
          private const MIN_SPEED:Number = 650;
  
          //private var scoreDistance:int;
  
          private var gameArea:Rectangle;
          private var touchArea:Rectangle;
          private var shape:starling.display.Sprite = new starling.display.Sprite();
  
          private var target:Point = new Point(100, 100);
  
          private var touch:Touch;
          private var touchX:Number;
          private var touchY:Number;
  
          public function InGame()
          {
              super();
              this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedToStage);
          }
  
          private function onAddedToStage(event:Event):void
          {
              this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
              drawGame();
          }
  
          private function drawGame():void
          {
              bg = new GameBackground();
              this.addChild(bg);
  
              scarlet = new Scarlet;
              scarlet.x = stage.stageWidth/2;
              scarlet.y = stage.stageHeight/2;
              this.addChild(scarlet);
  
              startBtn = new Button(Assets.getTexture("PlayBtn"));
              startBtn.x = stage.stageWidth * 0.5 - startBtn.width * 0.5;
              startBtn.y = stage.stageHeight * 0.5 - startBtn.height * 0.5 + 35;
              this.addChild(startBtn);
  
              fireBtn = new Button(Assets.getTexture("FireBtn"));
              fireBtn.x = 675;
              fireBtn.y = 435;
              this.addChild(fireBtn);
  
              //defines area scarlet can fly in
              gameArea = new Rectangle(0, 15, stage.stageWidth, stage.stageHeight - 150);
          }
  
          public function disposeTemporarily():void
          {
              this.visible = false;
          }
  
          public function initialize():void
          {
              this.visible = true;
  
              this.addEventListener(Event.ENTER_FRAME, checkElapsed);
  
              scarlet.x = -stage.stageWidth;
              scarlet.y = stage.stageHeight * 0.5;
  
              gameState = "idle";
  
              playerSpeed = 0;
  
              difficultyRate = 0.3;
              difficulty = 1;
              enemySpawnDelay = enemySpawnCounter = 100;
  
              enemies = new Array();
              lasers = new Array();
  
              scarletLocation = new Point(200, 400);
  
              addEventListener(Event.ENTER_FRAME, update);
  
              lasersLayer = new Sprite();
              enemiesLayer = new Sprite();
              touchLayer = new Sprite();
  
              addChild(lasersLayer);
              addChild(enemiesLayer);
              addChild(touchLayer);
  
              addEventListener(Event.ADDED_TO_STAGE, setupTouchLayer);
              touchLayer.addEventListener(Event.TRIGGERED, shootLaser);
  
              //scoreDistance = 0;
  
              startBtn.addEventListener(Event.TRIGGERED, onStartBtnClick);
  
              this.addEventListener(TouchEvent.TOUCH, onTouch);
          }
  
          private function onStartBtnClick(event:Event):void
          {
              startBtn.visible = false;
              startBtn.removeEventListener(Event.TRIGGERED, onStartBtnClick);
  
              launchScarlet();
          }
  
          private function launchScarlet():void
          {
              this.addEventListener(TouchEvent.TOUCH, onTouch);
              this.addEventListener(Event.ENTER_FRAME, onGameTick);
          }
  
          private function onTouch(event:TouchEvent):void
          {
              touch = event.getTouch(stage);
  
              touchX = touch.globalX;
              touchY = touch.globalY;
  
              target.x = event.touches[0].globalX;
              target.y = event.touches[0].globalY;
          }
  
          private function onGameTick(event:Event):void
          {
              switch(gameState)
              {
                  case"idle":
                      //Take off
                      if (scarlet.x &lt; stage.stageWidth * 0.5 * 0.5)
                      {
                          scarlet.x += ((stage.stageWidth * 0.5 * 0.5 + 10) - scarlet.x) * 0.5;
                          scarlet.y = stage.stageHeight * 0.5;
  
                          playerSpeed += (MIN_SPEED - playerSpeed) * 0.05;
                      }
                      else
                      {
                          gameState = "flying";
                      }
                      break;
                  case"flying":
                      playerSpeed -= (playerSpeed - MIN_SPEED) * 0.01;
  
                      scarlet.y -= (scarlet.y - touchY) * 0.1;
  
                      if (-(scarlet.y - touchY) &lt; 150 &amp;&amp; -(scarlet.y - touchY) &gt; -150)
                      {
                          scarlet.rotation = deg2rad(-(scarlet.y - touchY) * 0.075);
                      }
  
                      if (scarlet.y &gt; gameArea.bottom - scarlet.height * 0.5)
                      {
                          scarlet.y = gameArea.bottom - scarlet.height * 0.5;
                          scarlet.rotation = deg2rad(0);
                      }
                      if (scarlet.y &lt; gameArea.top + scarlet.height * 0.5)
                      {
                          scarlet.y = gameArea.top + scarlet.height * 0.5;
                          scarlet.rotation = deg2rad(0);
                      }
  
                      //scoreDistance += (playerSpeed * elapsed) * 0.1;
                      //trace(scoreDistance);
  
                      break;
                  case"over":
                      break;
              }
          }
  
          //addapted from "Shoot"
          private function setupTouchLayer(event:Event):void
          {
              touchLayer.graphics.beginFill(0x000000, 0);
              touchLayer.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
              touchLayer.graphics.endFill();
  
              touchArea = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
          }
  
          private function shootLaser(event:TouchEvent):void
          {
              makeLaser(scarletLocation);
          }
  
          private function makeLaser(scarletLocation:Point):void
          {
              var newLaser:Laser = new Laser();
  
              newLaser.x = scarletLocation.x;
              newLaser.y = scarletLocation.y;
  
              newLaser.xVel = 5;
              newLaser.yVel = 5;
  
              newLaser.addEventListener(Laser.PURGE_EVENT, purgeLaserHandler);
  
              lasersLayer.addChild(newLaser);
              lasers.push(newLaser);
          }
  
          private function purgeLaserHandler(event:Event):void
          {
              var targetLaser:Laser = Laser(event.target);
              purgeLaser(targetLaser);
          }
  
          private function purgeLaser(targetLaser:Laser):void
          {
              targetLaser.removeEventListener(Laser.PURGE_EVENT, purgeLaserHandler);
              try
              {
                  var i:int;
                  for (i = 0; i &lt; lasers.length; i++)
                  {
                      if (lasers[i].name == targetLaser.name)
                      {
                          lasers.splice(i, 1);
                          lasersLayer.removeChild(targetLaser);
                          i = lasers.length;
                      }
                  }
              }
              catch(e:Error)
              {
                  trace("Failed to delete laser!", e);
              }
          }
  
          private function makeEnemies():void
          {
              enemySpawnCounter++;
  
              if (enemySpawnCounter &gt; enemySpawnDelay)
              {
                  enemySpawnCounter = 0;
                  enemySpawnDelay -= difficultyRate;
                  difficulty += difficultyRate;
                  makeEnemy();
              }
          }
  
          private function makeEnemy():void
          {
  
              var i:int;
              for (i = 0; i &lt; Math.floor(difficulty); i++)
              {
                  var newEnemy:Enemy = new SnowBall();
  
                  newEnemy.x = 925;
                  newEnemy.y = Math.random() * 375 + 50;
                  //trace(newEnemy.x); trace(newEnemy.y);
                  newEnemy.xVel = (-Math.random() * difficulty) - 5;
                  newEnemy.sinMeter = Math.random() * 10;
                  newEnemy.bobValue = Math.random() * difficulty;
  
                  newEnemy.addEventListener(Enemy.PURGE_EVENT, purgeEnemyHandler);
  
                  enemiesLayer.addChild(newEnemy);
                  enemies.push(newEnemy);
              }
          }
  
          private function purgeEnemyHandler(event:Event):void
          {
              var targetEnemy:Enemy = Enemy(event.target);
              purgeEnemy(targetEnemy);
          }
  
          private function purgeEnemy(targetEnemy:Enemy):void
          {
              targetEnemy.removeEventListener(Enemy.PURGE_EVENT, purgeLaserHandler);
              try
              {
                  var i:int;
                  for (i = 0; i &lt; enemies.length; i++)
                  {
                      if (enemies[i].name == targetEnemy.name)
                      {
                          enemies.splice(i, 1);
                          enemiesLayer.removeChild(targetEnemy);
                          i = enemies.length;
                      }
                  }
              }
              catch(e:Error)
              {
                  trace("Failed to delete enemy!", e);
              }
          }
  
          private function newHitTest(laser:Laser):void
          {
              for each (var enemy:Enemy in enemies)
              {
                  if (enemy.status != "Dead" &amp;&amp; enemy.hitTest(new Point(laser.x, laser.y)))
                  {
                      enemy.destroy();
                      purgeLaser(laser);
                  }
              }
          }
  
          private function checkElapsed(event:Event):void
          {
              timePrevious = timeCurrent;
              timeCurrent = getTimer();
              elapsed = (timeCurrent - timePrevious) * 0.001;
          }
  
          private function update():void
          {
              //trace(enemies.length, lasers.length);
  
              for each (var enemy:Enemy in enemies)
              {
                  enemy.update();
              }
  
              for each (var laser:Laser in lasers)
              {
                  laser.update();
                  newHitTest(laser);
              }
  
              makeEnemies();
          }
          //addapted from "Shoot"
      }
  }
  </code></pre>