Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engine,Editor: add Touch Script API #2440

Draft
wants to merge 1 commit into
base: ags4
Choose a base branch
from

Conversation

ericoporto
Copy link
Member

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 ivan-mogilko added ags 4 related to the ags4 development context: script api labels Jun 2, 2024
@ivan-mogilko ivan-mogilko added this to the 4.0.0 (preliminary) milestone Jun 2, 2024
DynObjectRef create_touchpoint(int n)
{
if (n < 0 || n >= tp::MAX_POINTERS)
quit("!Touch: invalid index for touchpoint");
Copy link
Contributor

@ivan-mogilko ivan-mogilko Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good idea to use quit here, for something that is neither a fatal error nor a user's fault.
An assertion and returning null should be enough.

But seeing how this function is used, I am not sure why is it needed at all.
The loop in Touch_GetTouchPoints() below could call CreateTouchPointRef directly instead, and limit iterations to MAX_POINTERS too.

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Jun 12, 2024

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
Copy link
Member Author

ericoporto commented Jun 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ags 4 related to the ags4 development context: script api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants