Snake Trail - Example -

Show us your completed creations made in Construct 2

Post » Mon Mar 18, 2013 2:12 am

@Whiteclaws

Cheers thanks. Good solution.

I changed formula to 10*(fps/60) and then it works. Before you had a divide so only FPS the gap was getting larger.

B
31
S
8
G
5
Posts: 436
Reputation: 5,836

Post » Mon Mar 18, 2013 11:22 am

Oops , math misurstanding by me ;P
Well , you found it anyways !
B
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

Post » Tue Oct 01, 2013 11:04 pm

[QUOTE=Whiteclaws] http://dl.dropbox.com/u/89532891/Others/C2HowdoI/MaybeFixed.capx%20[/QUOTE]

Hi, I wonder if there's any chance of you sharing this again? I'm having the same problem with the segments spreading far apart whenever the frame rate drops a bit, and unfortunately the link to your solution no longer works.

Thanks!
B
6
Posts: 13
Reputation: 276

Post » Wed Oct 02, 2013 12:23 am

@czar , do you always have the capx , I think I lost mine
B
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

Post » Wed Oct 02, 2013 11:16 am

Oh, that's a shame...

I did tried solving the issue, and this is what kind of worked. I took the expression

Pos.At(MaxArrayW-10*Crystal.SpawnNumber,0)

and changed it to

Pos.At(MaxArrayW-10*(fps/60)*Crystal.SpawnNumber,0)

The result was that the segments no longer started spacing apart, because the distance kept adjusting. But also because of that, the size of the snake kept changing slightly, resulting in a constant twitch.

Was this your approach?
B
6
Posts: 13
Reputation: 276

Post » Wed Oct 02, 2013 5:07 pm

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.Parkaboy2013-10-02 17:51:44
B
6
Posts: 13
Reputation: 276

Post » Wed Oct 02, 2013 8:07 pm

@whiteclaws, I believe this was the original one

https://www.dropbox.com/s/wosoblc9vu8nn5i/SNakeCapx.capx

and this is a later version

@parkaboy
https://www.dropbox.com/s/tugff4fzju4m4oz/SnakeGameLater.capx

B
31
S
8
G
5
Posts: 436
Reputation: 5,836

Post » Thu Oct 03, 2013 3:28 pm

Thanks a lot!
B
6
Posts: 13
Reputation: 276

Post » Thu Oct 15, 2015 5:59 pm

I see another issue, the array should be cleaned from time to time.
It increases too quick making the game slower.

Is there a way to remove the older positions from it as the player keep moving?
B
84
S
30
G
22
Posts: 384
Reputation: 18,462

Post » Sun Oct 18, 2015 5:00 pm

@jogosgratispro, you have to use a static sized array and push/pop the new positions. Here's a quick example.
https://dl.dropboxusercontent.com/u/895 ... Snake.capx
Edit: Ninja'd by Peter Parker
@czar, The later version looks so cool :)
B
34
S
16
G
16
Posts: 2,222
Reputation: 16,564

PreviousNext

Return to Completed Creations

Who is online

Users browsing this forum: No registered users and 0 guests