-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopable.cs
More file actions
34 lines (31 loc) · 1.19 KB
/
Loopable.cs
File metadata and controls
34 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Godot;
/**
* <summary>A general class of textures on the chart which should have a position at which point they loop around.
* Mostly a study for modulo arithmetic.</summary>
*/
public partial class Loopable : Sprite2D
{
[Export]
public float LoopOffset = 700f; //px Pos to loop or do something at.
public override void _Process(double delta)
{
UpdatePos();
}
//Loop position over the course of time across a loop
private void UpdatePos()
{
Vector2 newPos = Position;
float interval = (float)TimeKeeper.ChartWidth;
double relativePosition =
TimeKeeper.CurrentTime / TimeKeeper.LoopLength * TimeKeeper.ChartWidth;
newPos.X =
//Yes I know. Hard to parse math. https://www.desmos.com/calculator/fkmoqi50ee
//(velocity*Pos - (horizontal shift)) % interval - (vertical shift)
//We want something to be at x=0 at a specific time/beat and having it drift cleanly off and on screen
(float)TimeKeeper.PosMod(-relativePosition - interval / 2, interval)
- interval / 2
+ LoopOffset;
if (!float.IsNaN(newPos.X))
Position = newPos;
}
}