How to make something to count the distance and time?

Denisowator

  • Posts: 49
I want there to be a counter on my screen that shows me how far I went in certain directions e.q. Went left: 200, Went right:200 and Played:1hour 20mins. So I basically want there to be 3 counters on top of the screen when you play the game and I want one of them to show how far I went to the left, one of them to show how far I went to the right and one of them to show how long I'm playing for.

Any idea on how to do that.

P.S. The game I'm making is just running for eternity. I still haven't figured out how to make an infinite scene and I posted a question/topic on it earlier. The question/topic is called "How to make a never ending scene and background?".

Thanks in advance. :)

Epic428

  • Posts: 1118
You need the tile API if you plan on using tiles on a never ending scene. You then need to constantly update the tile positions so it appears as though you are moving in a certain direction while leaving the player standing still.

As far as the counter goes. If the player actually moves, you would keep track of the x position of the player. Any time it increases that would add to the right counter.  If it decreases that would add to the left counter.  If the player does not mover and you update tile positions then you would add to the counter every time the player advances a tile same with subtracting.

As far as time goes you would use a counter to keep track of time always updating the counter. There's a caveat though, if the frame rate drops it would affect the counter and not be accurate. Therefore, the best method of tracking time is using a code block to access the step size value of box 2d as this will vary frame to frame. Adding this value to a counter would be the most accurate method of tracking time.

« Last Edit: April 05, 2014, 08:38:42 pm by Epic428 »
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Denisowator

  • Posts: 49
Thanks. Could you please show me a screenshot or something on how to do those things as events?

Epic428

  • Posts: 1118
It'll be a few days before I can access a computer. I'm on my iphone now and I work 12.5 hr shifts an hour away from home so I won't be on the computer till Tuesday.  Some pseudo code would work like this though:

[when created]
LastX = x of self
[Always]
If x of self  > LastX then
Increment "distance right" by x of self - LastX
Otherwise if x of self < LastX then
Increment "distance left" by LastX - x of self


For time tracking if using a basic counter and not tracking step size it would look like this:
[when created]
Counter = 0
Seconds = 0
Minutes = 0

[always]
Increment counter by 1
If counter = 60 then
{Increment seconds by 1
Counter = 0}
If seconds = 60 then
{Increment minutes by 1
Seconds = 0}

If using tile API then every time the tile moves in left/right direction equal to the tile width you would add the tile width to that directions counter.

If using the step size you would add the step size every frame and then if the counter equals 1000 or greater increment seconds by one and reset counter to the difference of itself and 1000.

Keep in mind the first timer assumes u are always running at 60 fps.  Otherwise if u run at less, then the always won't run that often causing a difference in ingame time and real time.
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Denisowator

  • Posts: 49
Thanks again, I think I'll wait till Tuesday because it still looks really confusing to me and when I was doing it as an event while reading the message I was pretty sure I did a lot of things wrong as I got a lot of errors every time I did "Test Scene" after doing the events.

Hope to get this problem of mine completely fixed when you have the chance to do it on Tuesday as events and send some screenshots. :)