Can someone Explain Touch.X vs Touch.XAt()

Get help using Construct 2

Post » Fri Mar 03, 2017 1:50 am

I seemingly have a basic understanding of it. I read it in the manual, but I am not 100% sure.
I don't want to accidentally confuse someone else learning about it too.

I understand
Touch.XAt(0),Touch.YAt(0)
is getting the location of a touch, what is the At(0) part?

Would
Touch.X,Touch.Y
Do the same?

or would it be Touch.X(0), Touch.Y(0)?

Is Touch.XAt(0) needed in order to get X of two Touches?

https://www.scirra.com/manual/119/touch
B
65
S
37
G
13
Posts: 240
Reputation: 12,703

Post » Fri Mar 03, 2017 2:13 am

yes, as you read there, Touch plugin supports multiple touches... the touch.XAt(0) is the id of the first finger on screen or touch detected... then 1,2 ,3 are other touches in same time... usually used for zoom in and stuff like that however i never had a need to use it. most game dont require multiple touches. you can work around it with visuals.

any captain here to explain this better?
B
77
S
23
G
69
Posts: 1,353
Reputation: 43,958

Post » Fri Mar 03, 2017 2:17 am

Unconnected wrote:I seemingly have a basic understanding of it. I read it in the manual, but I am not 100% sure.
I don't want to accidentally confuse someone else learning about it too.

I understand
Touch.XAt(0),Touch.YAt(0)
is getting the location of a touch, what is the At(0) part?

Would
Touch.X,Touch.Y
Do the same?

or would it be Touch.X(0), Touch.Y(0)?


Is Touch.XAt(0) needed in order to get X of two Touches?

https://www.scirra.com/manual/119/touch


You are looking at the values if you want to use Absolute X and Y for coordinates.

In most cases that is not needed and touch.X and touch.Y gives you the coordinates for the position of the touch on the screen based on 0,0 being top left corner of your layout.

If you are using different layers with different size layouts or transferring coordinates between layouts or using multiple touches then using Absolute also allows you to specify which layer and on what touch the command is used.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Fri Mar 03, 2017 3:34 am

@gamecorpstudio
@Lamar

I was mostly confused on what At( ) meant in XAt( ).
The Manual refereed to "At" Expression as Absolute and I didn't realize "At" meant Absolute.
I looked it up on the Touch Page of the Manual because of Lamar.
It makes me assume Touch.X would be relative if a layer was rotated, I didn't even think of that possibility until then.

I was only familiar with Abs() as Absolute.

Abs() of course makes any value positive.
abs( 5 - 10) will return 5 instead of -5
-Abs() will make any value negative.
-abs( 10 - 5) will return -5 instead of 5

It is used to keep any math in the abs() expression to always have positive or negative results.
These are of course different Absolutes, just tossing it in to help some readers.

I only tried to find/search for "XAt".
I thought trying to search for At would have been difficult, since it is a common word.
I missed the quote below, because it was under AbsoluteX in the manual.

"The At expressions can return the absolute position of any touch given its zero-based index, and the ForID expressions return the position of a touch with a specific ID."

Some Examples for the above Quote:
XAt(index)
XAt(index, "layer")
XForID(index)
XForID(id, "layer")


After finding Absolute in the Manual, I read the At expression returned the Absolute position.
I then noticed this.

AbsoluteXAt(index)

What is the need for Absolute if At expression does Absolute?

Does AbsoluteX do the same as XAt?
B
65
S
37
G
13
Posts: 240
Reputation: 12,703

Post » Fri Mar 03, 2017 4:22 am

Unconnected wrote:@gamecorpstudio
@Lamar

I was mostly confused on what At( ) meant in XAt( ).
The Manual refereed to "At" Expression as Absolute and I didn't realize "At" meant Absolute.
I looked it up on the Touch Page of the Manual because of Lamar.
It makes me assume Touch.X would be relative if a layer was rotated, I didn't even think of that possibility until then.

I was only familiar with Abs() as Absolute.

Abs() of course makes any value positive.
abs( 5 - 10) will return 5 instead of -5
-Abs() will make any value negative.
-abs( 10 - 5) will return -5 instead of 5

It is used to keep any math in the abs() expression to always have positive or negative results.
These are of course different Absolutes, just tossing it in to help some readers.

I only tried to find/search for "XAt".
I thought trying to search for At would have been difficult, since it is a common word.
I missed the quote below, because it was under AbsoluteX in the manual.

"The At expressions can return the absolute position of any touch given its zero-based index, and the ForID expressions return the position of a touch with a specific ID."

Some Examples for the above Quote:
XAt(index)
XAt(index, "layer")
XForID(index)
XForID(id, "layer")


After finding Absolute in the Manual, I read the At expression returned the Absolute position.
I then noticed this.

AbsoluteXAt(index)

What is the need for Absolute if At expression does Absolute?

Does AbsoluteX do the same as XAt?


Absolutes in touch can be used for drawing lines and creating shapes which is I think it's primary purpose. I haven't found any use for it but other people might.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Sat Mar 04, 2017 12:38 am

Touch.AbsoluteX is the same as Touch.AbsoluteXAt(0).
Touch.AbsoluteX just does not take an index as parameter, and is always about index zero. (index in the list of touches)

Since 'Absolute' (in this case) means position on the canvas, with x=zero and y=zero at left-up your SCREEN, it can not take the "layer" as parameter.

TouchID is an expression (a number) that identificates roughly a 'gesture'.
If you use 'on any touch', that expression holds a number corresponding with all the touches that are on that moment on screen. So, everywhere you see 'id' like in 'Touch.AbsoluteYForID(ID)' .... that ID is a number retrieved and stored with the TouchID expression.

I think that most people get the x/y coordinates from a HUD layer with no parallax when they want absolute x/y coordinates. After all thats kinda the same.

Now, wherever you see 'Get ..... coordinate in the layout (with x=zero and y=zero at the zero points in the layout) you can specify a "layer" in the parameters. And this absolutely necessary.
Consider this example:
https://www.dropbox.com/s/bxnfx9snt60j9 ... .capx?dl=0

I have a rotating layer with parallax. When i fire bullets at touch.x,touch.y (layout coordinates) ... then the bullets are not going direction the touch position. That is because the layer with the turrets is (with its own coordinates) moving inside the layout.

To fix this, we need the layout parameter.
https://www.dropbox.com/s/gn013jr7lwvki ... .capx?dl=0

Surely hope i helped you some.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: beohs, divsyntax, tunepunk and 7 guests