Measuring distance traveled

Hi,
I've made a game but I want to calculate the distance traveled. Basically I swipe and the screen moves downward. And after that the image repeatedly repeats itself. But I want to post the distance the person traveled at the end of the game. how would I do that? Is there a way of measuring the number of pixels that passed down the screen or something of that matter? It's basically a very simple game. I'm swiping downwards and making the screen repeat itself. The game/race finishes 30 seconds after you hit start. Sorry it's hard to explain but I hope you guys get the broad idea.

Comments

  • adamhwilkadamhwilk Member, PRO Posts: 11

    If I understand correctly this is a racing game where you swipe down to move forward?

    If there are no obstacles or actors you could track, you could always just code in a counter for each successful swipe. Alternatively you could count each time the image is repeated, a "lap" so to speak. And then just calculate an arbitrary distance based on the number of laps.

  • yna205@nyu.eduyna205@nyu.edu Member Posts: 49

    How exactly would I measure the number of repeated actors (laps)?

  • yna205@nyu.eduyna205@nyu.edu Member Posts: 49

    @adamhwilk said:
    If I understand correctly this is a racing game where you swipe down to move forward?

    If there are no obstacles or actors you could track, you could always just code in a counter for each successful swipe. Alternatively you could count each time the image is repeated, a "lap" so to speak. And then just calculate an arbitrary distance based on the number of laps.

    Bump

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    You'll need to do some math. So store the start position of the swipe then store the end position and subtract the end from the start and you have the distance. Then store that value in an attribute. Each swipe calculation will need to be added to the stored value.

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408

    you can also use magnitude to calculate the distance between two objects, like the start line and the actor by having this on the actor

    magnitude(startX-playerX, startY-playerY)

    that will return the distance in pixels.

Sign In or Register to comment.