# Trouble with sprite not matching with a canvas.draw Text, same x & y

I am making an app that shows the trajectory of the sun and the moon .

I did my homework with gathering all the necessary equations that I tested first in an Arduino project.

I made a canevas, and drawed an ellipse figuring the place (defined by latitude and longitude). I also drawed one ellipse figuring the sun trajectory with numbers figuring the hours and the same for the moon.

The trouble came with the 2 image sprites representing the sun and the moon. These sprites aren’t placing themselves where they should be, following the hours of the ellipses.

I am struggling to understand why the sprites are perfectly placed according to the X but most of the time the Y is wrong, above the ellipse, though I strictly use the same equations for ellipses and sprites.

I made a test, placing a canevas.draw text « S » at x=150 y = 150 and sprite same x=150 and y = 150, and stunningly same trouble, the sprite is placed as if y would be +/- 110.

I am completely at lost for 2 days.

Does somebody have an explanation please ? Thanks.

1 Like

I don't think the problem is with App Inventor in this case. Have you checked your calculations well? Can you show the source where you got those from and we can help you check if your blocks are correctly placed.

Attached the procedure for the canevas animation , name « canevas ».

Attached the procedure for calcultions, « topocentric ». This procedure requires constants : Julian Day, latitude, longitude, DST and Timezone. It has been tested many time and is accurate. Based on Meeus and Duffet-Smith publication.

Thanks!

Sorry, but I will not check all those blocks for you, It's way more than I was expecting. And besides I'm not familiar with the subject either, so I wouldn't know what to look for.
I was talking more about the source from where you got the math to compare it to the blocks you placed. With blocks is very easy to nest or mix blocks and mistakenly perform one operation before another one, getting a wrong result.
So I suggest you look for that kind of occurrence in your code.

Example of what I'm saying

Two ideas for you ...

Sprites x,y values are for the upper left corner, not their center.

(sample video)

Another idea for you ...

The Canvas has a Text Alignment property.
Play with its settings, to nudge the text on the Canvas.

thanks a lot. Right now in France it's a bit late and I have to spend some time with my family. Thanks, I am going to check all of this tomorrow morning as I'll not working then. So heartwarming

After having posted the procedures on the forum I left for spending some time with my family during and after dinner. When coming back to close my program I was amazed to see that sprites and canevas.draw texts matched. Why ? I didn’t change my code. I have just translated the names of the variables in English for clarity. To confirm it I created 2 more labels for showing the respective x and y and they are the same. I suspect an instability in my coding /. Especially having to deal with conflicting hours. Displayed hours are 2 hours ahead of hours required for calculating azimut and altitude at GMT (Greenwich Mean Time), time zone 1h and DST 1h in France.
I am going to check the previous versions for finding the glitch, not bad, usually one back-tracks because being hanged up. Thanks for Your support, and Abraham thanks for showing me how to proceed.

See the time calculation articles at Faq Section: Clock

There was an important post by @Ghica in the old board on combining Date and Time Instants with time zone compensation, but unfortunately I have lost track of it.

Thanks a lot Abraham, that's very valuable and useful.

A post is evoking DAYLIGHT SAVING TIME (DST) but I didn't find any post treating this subject. I am currently using procedures for easily calculating DST. Either for the whole world, either for EU or USA-CANADA use.
I wonder whether it can help ?

Since ABG asked for a reply from me, I am replying here. Can you tell a bit more about how you are calculating dates and times? From your very small print I cannot figure out what you are trying to do.
Are you using milliseconds for date/time calculations?
In app inventor the date blocks are quite OK, still depending on your time zone, but the time blocks may be offset. If you make a time instant from 0 milliseconds, then you will get 01:00:00 in my time zone (Netherlands). Here is an .aia that plays around with this testPastPres_2.aia (3.4 KB)
This was from a question where someone wanted to know if a combination of a date and time picker result was in the past or future and he wanted to be able to add/subtract time.
Maybe it is of some help. Cheers, Ghica.

1 Like

Thank You.
Right now my app is working flawlessly. This app is showing the progression of the sun and the moon all day long, calculating the azimuts and altitudes (arbitrary) every second, and also showing hours of rise and set. I was stuck with sprites and canevas.draw Text not matching, due to a varying discrepancy between legal hour and GMT hour, but also to a not refreshing screen while testing, the animation being triggered by « when screen1 initialize » instead of « when clock1 timer », terrible practice. Anyhow, calculations every second is arbitrary, it could be every minute as well, the animation is as slow as sun and moon travels.

Now all is solved thanks to this forum for pointing out what I was neglecting.

My last post is about Daylight Saving Time. I am forced to use it because all the astronomic calculations are done in Greenwich Mean Time (and sideral time, it’s another story) but the app should show the results in legal time, European Summer Time, 2 hours ahead for us.

Abraham provided me with excellent posts. One of them mentions DST without going any further.

As I am permanently using DST, I am asking whether some people could be interested in simple formulas for calculating DST anywhere in the world ?, as far as their respective countries observe DST.