Author Topic: Touch / Click position on a Sprite in percent?  (Read 1247 times)

JazzMasta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Touch / Click position on a Sprite in percent?
« on: September 25, 2014, 03:57:39 AM »

How do you get the width/height of a UISprite and touch/position?

I'm want something like this (psuedo code):

float percentX = touch.x / width;
float percentY = touch.y / height;


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Touch / Click position on a Sprite in percent?
« Reply #1 on: September 25, 2014, 07:36:54 PM »
Touch position is in screen space. You need to transform from screen space to world space, then from world space to local space (relative to widget.transform.parent). You then get widget.localCorners, where corner[0] is bottom left and corner[2] is top-right. So (transformedTouchPosition - corner[0]) / (corner[2] - corner[0]).