adventuregamestudio / ags

AGS editor and engine source code
Other
708 stars 159 forks source link

Engine,Editor: add Touch Script API #2440

Open ericoporto opened 6 months ago

ericoporto commented 6 months ago

fix #1538

A minimal touch api that can be used to detect touching a screen.

void repeatedly_execute_always() 
{
  TouchPoint* points[];
  points = Touch.GetTouchPoints();

  String s = "";
  for(int i=0; i<points.Length; i++)
  {
    TouchPoint* p = points[i];
    if(p.IsDown) {
      s = s.Append(String.Format("P(%d) _DOWN_ (%d, %d)\n", p.ID, p.X, p.Y));      
    } else {
      s = s.Append(String.Format("P(%d) __UP__ (%d, %d)\n", p.ID, p.X, p.Y));
    }
  }

  lbl_dbg.Text = s;
}
ivan-mogilko commented 5 months ago

Trying to understand how this api works, am I right that this returned array is always as long as the maximal number of touches done during the gameplay (it only grows and never shrinks)?

My big question in regards to API is: why return array, and not have an indexed attribute? I mean something like

builtin struct Touch {
  import static TouchPoint* TouchPoints[];
  import static int TouchPointsCount; // or TouchCount
};
ericoporto commented 5 months ago

My big question in regards to API is: why return array, and not have an indexed attribute?

That wasy first sketch of the API, I am not sure which is better.

Currently, each touch point is a position (x,y), if the finger is down or not, and a finger id that is unique.

Now apparently Safari on iPhone currently can only have at maximum 2 touch positions, while on Android Chrome it seems possible to go up to 10. On an Android app it seems, at least on my phone, it goes up to 10 (ignoring the hard limit set in ags in this PR), and in my iPhone I need to test again - I forgot. But I thought about using the max to limit the count to how many touches are actually being used in the application.

I was debating about which way is better, to handle the touch points, for instance, I think I like more the way you mentioned, but I was also thinking about dropping the "is down" property from the touch point and return an array and any items in the array means the finger is down, as I think the position in the touch release may not be relevant.