No, I'm guessing the actual problem is the fact that the array grows every 0.01 seconds. After a few minutes, the framerate starts dropping because the array is too large, and things only go worse from that.
Is there a way to tho the snake trail without a constantly growing array? I'd kill for the solution...
Edit: Okay, I think I've managed to actually come up with a solution for this. I still have to test it, and there's probably a way to do it with dt to avoid issues with lower framerates, but at least it works from White Claw's principle but without using an ever growing array.
So I have two Sprites:
- Player (the "head" of the snake, which is a bullet)
- Segment (each segment of the body)
The "Segment" has a "SpawnNumber" variable, set on Created, just like in White Claw's version, to keep track of the number of each segment in the body.
There are two arrays, with sizes (X,Y,Z):
- PosX (1000,1,1)
- PosY (1000,1,1)
(1000 is the size I've choose, but you could change it. It should be the value you're using to set the distance (here 10) * the maximum number of segments you're planning on allowing (here 100).)
Every 0.01 seconds, this happens:
- PosX --> push front Player.X on X axis
- PosX --> pop back on X axis
- PosY --> push front Player.Y on X axis
- PosY --> pop back on X axis
(this adds the current X and Y position on the front of each array, pushing the whole array and poping the extra value out, keeping the size constant)
- Segment --> set position to (PosX.at(10*Segment.SpawnNumber),PosYat(10*Segment.SpawnNumber))
(this takes, for each segment, the values for the X and Y coordinates corresponding to its SpawnNumber. Like in WC's version, 10 is just the number used to set the distance, and could be changed as long as the arrays are changed accordingly.)
It was easier than I expected.