Hello !
I would like to move a sprite (sun) around a circle. I managed to spin it all around the circle, but I can’t calculate its speed (a).
Indeed I would like to do a day / night cycle. Let’s assume that a day lasts 12sec (12000 frames), and that my circle has a radius of 580px (size which will change according to the size of the screen).
In the example I found, “a” is incremented by 0.05 with each update.
Do you have a formula that can help me calculate this “a” based on the length of my day?
Or another method (a tween?).
Here is my current code (sorry i can’t seem to format the code on the forum ):
created(){
this.sunSprite.setData(‘vector’, new Phaser.Math.Vector2())
}
update()
{
this.a += 0.05;
if (this.a > 1)
{
this.a = 0;
}
var vect = this.sunSprite.getData('vector')
this.circle.getPoint(this.a, vect);
this.sunSprite.setPosition(vect.x, vect.y)
this.graphics.clear();
this.graphics.lineStyle(2, 0x00ff00);
this.graphics.strokeCircleShape(this.circle);
}
I tried something like that, but it is not conclusive:
this.speed = 2 * Math.PI * radius / 12000
thank you in advance