(Taifun's) Compass (tutorials) suddenly does not work properly (sprite X,Y is no longer the upper left corner if you change the) Origin

Hi,
I have hiking app with compass function. I was correcting some problems with location and after fix it, I noticed that compass is not working properly anymore.

As I could not find any error in blocks (not first time to reblock something by accident) I tried Taifuns compass.aia and bearing.aia. But the problem was still there:

ImageSprite is not moving around it center point, instead it is moving outside of the canvas/screen edge like it is moving around some point outside of the screen.

Then I installed some random compass app from Google Play and behavior of compass was ok. Also I checked and calibrated built-in compass (i have Samsung Galaxy S22) and it is ok as well.

Pls let me know where could be the error? As I said, before recent update of my app compass was working ok.

Thx

Please provide a simple aia project that repeats this behaviour.

Pls find attached Taifun's two simple compass projects.

I have problems with both of them. Compass part of code inside my app is based on Taifun's bearing.aia and it worked as expected untill today.

bearing.aia (28.1 KB)
compass.aia (22.4 KB)

A recent AI2 update add support for setting the center of a Sprite for rotation.

Your symptoms sound like a problem with that setting.

(Have not opened the aia files yet.)

2 Likes

for the bearing aia:

Thats it. Place the marker in the centre of the compass.

Not sure what to do with the pointer, yet

ABG is right. The Sprite rotates around (0,0), which is the bottom-left corner. Set OriginX and OriginY to half of the width and height values of the Canvas.

Those settings are tricky.

Turns out they range from 0 to 1, as I discovered the hard way on testing.

Old

New

bearing (1).aia (28.4 KB)

1 Like

Upper left, as I recall?

1 Like

Hi,

thx for your kind help which helped me to solve the problem described.

But then another one appeard. I had problem to center ImageSprite. In Taifuns app they sticked to top part of canvas and in my app to the left part of canvas.

I think I found a solution with using following formula:

instead of the old one:

Pls advise any opinion.

Thx

Your solution would position those sprites with their upper left corner at the center of the canvas.

Is that what you want?

Note that Canvas.Width and Height are not stable in Screen.Initialize, because the Screen has not finished drawing yet.

I have no idea what the apps are supposed to look like.
Maybe where you found the apps?

1 Like

I want to put imagesprite to the center of canvas with its central point and make it to act as a compass.

But what ever I tried the only formula that works for me is this one:

Then I check documentation and it says:
OriginX
Horizontal unit coordinate of the origin with respect to left edge. Permitted values in [0, 1]. A value of 0.0 means the origin lies on the left edge, 0.5 means the origin lies in the middle and 1.0 means the origin is on the right edge.
OriginY
Vertical unit coordinate of the origin with respect to top edge. Permitted values in [0, 1]. A value of 0.0 means the origin lies on the top edge, 0.5 means the origin lies in the middle and 1.0 means the origin is on the bottom edge

X
The horizontal coordinate of the origin of the ImageSprite, increasing as the ImageSprite moves right.
Y
The vertical coordinate of the origin of the ImageSprite, increasing as the ImageSprite moves down.

Is it possible that since inclusion of OriginX/OriginY setup of canvas/imagessprite is different as before?
or I am making mistake that negates my mistake?

Try this:

bearing.aia (27.8 KB)

All positional settings made in designer for screen, canvas and sprites

Yes, the new settings changed the interpretation of X and Y.

Thanks for pointing that out.

I didn't know that.

So X,Y is no longer the upper left corner if you change the Origin.

I guess my problem is solved. Thx ABG, TIMAIA2 for your kind support.