Game speed to time conversion...

Discussion in 'Technical Discussion' started by heathclose, Mar 28, 2016.

  1. heathclose

    heathclose Miniboss Boxer

    Joined:
    Jan 28, 2016
    Messages:
    1,810
    Likes Received:
    1,026
    @Andy what is the equation for game speed in seconds given the multiplier...

    for example... If i tell the player "collect as many coins as you can in the next 30 seconds"... and my non stop game speed is 40... how do i know what the score multiplier needs to be for the event observer to figure up 30 seconds? like game speed 40 x score multiplier = 1 score per second... or some such mathicals...
     
  2. Andy

    Andy Miniboss Boxer

    Joined:
    Sep 24, 2015
    Messages:
    2,152
    Likes Received:
    1,546
    Hmmm.... good question. I'm attempting to find out what exactly what measurement our Speed setting pertains to in real life.

    Until then Distance is pixels, so if you set a stop watch for 30 seconds and then die, you can see the distance in pixels traveled and use that value in the event observer. Knowing the following equations and using a stopwatch you could work this backward to a fairly accurate calculation by taking measurements at several different speeds.

    s2table1.gif
     
    energizerlithium likes this.
  3. heathclose

    heathclose Miniboss Boxer

    Joined:
    Jan 28, 2016
    Messages:
    1,810
    Likes Received:
    1,026
    awesome... I appreciate the preliminary ideas in the meantime
     
  4. JustWatchApps

    JustWatchApps Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    315
    Likes Received:
    145
    one other thought is that the 'timer' potentially could provide a different result on each device type/iOS version due to run time? If it cant be exact - you could always change your description to 'before the timer reaches 30' just a thought
     
  5. Andy

    Andy Miniboss Boxer

    Joined:
    Sep 24, 2015
    Messages:
    2,152
    Likes Received:
    1,546
    Time should be fairly consistent... as long as you don't have noticeable lagging or slowdowns. Modern games use time based game loops, back in the old days game loops were tied to the CPU ticks and this was more of a concern.
    .
     
  6. JustWatchApps

    JustWatchApps Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    315
    Likes Received:
    145
    You calling me old @Andy ? I resemble that remark! lol :D
     
  7. Andy

    Andy Miniboss Boxer

    Joined:
    Sep 24, 2015
    Messages:
    2,152
    Likes Received:
    1,546
    Hahaha, you and me both! ;-)
     
  8. Andy

    Andy Miniboss Boxer

    Joined:
    Sep 24, 2015
    Messages:
    2,152
    Likes Received:
    1,546
    OK, I don't have a better answer for measuring Time. There are potentially too many factors involved to give solid answer. But Nik had the better idea of recording your gameplay to get a more accurate reading on the Time. Much better than a stop watch. :)

    Doing this you can at least figure out the pixels per second for your gameplay as long as you are using a constant speed. Here is hypothetical example:

    120000 pixels / 30 seconds = 4000 pixels per second
    4000 pixels per second / 40 units (game speed) = 100 pixels per second per unit of game sped​

    Working backwards you can figure out what distance in pixels you need to use if you want to change the game speed. Let's say I have a game speed of 50 instead... here is how I can calculate the distance.

    100 pixels per unit of game speed x 50 units (game speed) = 5000 pixels per second
    5000 pixels per second x 30 seconds = 150000 pixels in total distance​

    Now if you want to set a distance multiplier instead:

    1 second / 5000 pixels per second = 0.0002 score multiplier (we should probably rename this to distance multiplier in BB2)​

    That should give you a second timer for you game it you want to display it using a label for distance traveled. Remember this is a hypothetical, you will need to at least time your gameplay once to come up with valid numbers.

    Hope this helps (and all my math is correct)... I probably spent too much time figuring this out. :)
     
    trudnai likes this.
  9. heathclose

    heathclose Miniboss Boxer

    Joined:
    Jan 28, 2016
    Messages:
    1,810
    Likes Received:
    1,026
    Epic. Thanks for the legwork on that @Andy and whoever helped. Really appreciate that.
     
  10. kodagames

    kodagames Avid Boxer

    Joined:
    Oct 11, 2015
    Messages:
    294
    Likes Received:
    115
    This is fantastic!!!
     
  11. donshire

    donshire Boxer

    Joined:
    May 3, 2016
    Messages:
    22
    Likes Received:
    0
    i dont get it , where can i find the distance multiplier ?
     
  12. donshire

    donshire Boxer

    Joined:
    May 3, 2016
    Messages:
    22
    Likes Received:
    0
    nvm kinda got it but unfortunately if the speed changes, the time does too.. -_- i dont want to keep the game at the same speed all the time ..
     
  13. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    Thanks @Andy, it is definitely useful, however, for the non-constant game speed this does not work -- so I have come up with a different solution. It is based on spawning objects with action in it.

    Steps:
    1. Create an Action with no action with duration to 0
    2. Set Coin to 0 and Score to 1 and untick Show Coin and Point reward
    3. Delete Default Animation of the Action
    4. Create an Object
    5. Delete Default Animation of the Object
    6. Add the Action to the Scene
    7. Make sure the added Action is selected and cut it to the clipboard by pressing Ctrl+X (or Cmd+X if you are on a Mac)
    8. Edit Default Animation of the Object
    9. Paste the Action to it by pressing Ctrl+V (or Cmd+V)
    10. Make sure Action is at position 0,0
    11. Edit Character's Default Animation
    12. Add this created Object to the Animation from the object list
    13. Add spawn component and set to 1
    14. Make sure the Object is at 0,0 and it is Decoration
    15. Add a high speed velocity to the spawning Object, something like -1000 to the Y coordinates if your game direction is upwards or to the X if the direction is to the left (This will help to avoid crazy counter spinnings as well as helps to delete the spawned objects and therefore avoiding keep adding new objects until memory is full)
    Now you can display elapsed time as Score Point label, add Event Observer etc...

    Timer, however, aka counting back with Point Rewards -1 is a lot more trickier. The problem is that you cannot observe "less-than" events, only "equal or greater" -- In other words if you start at 15 Points and add Observer for Point 0 what will happen is the event triggers immediately... Therefore we keep Points as above, and use Coins to count down:
    1. Do as above and set Coin Rewards to -1
    2. Create another Action with Coin rewards 15 for 15 seconds
    3. Remove its Default animation
    4. Place this action on Start screen to the exact same location as your character
    5. Now display Session Coins as a Timer count down, and Observe Session Points for Game End or other events
    Obviously the cons for this solution is that you lose the possibility to collect coins... So alternatively you exploit Health and Damage:
    1. Do as above but do not use Coin, set Point Rewards to -1 instead
    2. Create another Action with Point rewards 15 for 15 seconds
    3. Remove its Default animation
    4. Place this action on Start screen to the exact same location as your character
    5. Now display Session Points as a Timer count down
    6. Now you have two options:
      1. Add Health component to Character, set it to 15 for 15 seconds... (obviously then you cannot set different times for different worlds)
      2. Or do something with a non-colliding Enemy object with a damage of -15 but that for some reason did not work for me. I thought negative damage would be like health pack?
    It would be a really useful addition to be able to observe "less-than things", not to mention a real timer :)

    Anyway, hope it is useful!
    EDIT: Modified the description a little bit to make it a bit more obvious and also corrected a little detail about automatic object deletion
     
    Last edited: Sep 8, 2016
    Christoph, fez_94, blackswan and 3 others like this.
  14. playsgames6666

    playsgames6666 Miniboss Boxer

    Joined:
    Nov 13, 2015
    Messages:
    1,168
    Likes Received:
    745
    wow,
     
  15. heathclose

    heathclose Miniboss Boxer

    Joined:
    Jan 28, 2016
    Messages:
    1,810
    Likes Received:
    1,026
    Uhhhhhhh.... Hold on I need to read this seven more times while I collect my mind shards that just blew everywhere...
     
    jimmiethekid likes this.
  16. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    Haha, it is lot more easy to do than read how to do it :)
     
    Christoph likes this.
  17. khalid

    khalid Avid Boxer

    Joined:
    Feb 17, 2016
    Messages:
    343
    Likes Received:
    67
    @trudnai
    Your steps:
    1. Create an Action with no action with duration to 0
    2. Set Coin to 0 and Score to 1 and untick Show Coin and Point reward
    3. Delete Default Animation
    4. Create an Object
    5. Delete Default Animation of the object
    6. Edit Default Animation of the object and add the Action to it
    I can't add what is underlined above, we can't add action to default animation
    BB 2.2.4
     
  18. trudnai

    trudnai Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,235
    Likes Received:
    701
    You need to do a little trick there as Actions cannot be added by the standard way. You need to add the Action to the scene first, then Ctrl+X (or Cmd+X if you are on a Mac) so it will Cut the Action and place that into the clipboard, then open the Default Animation and Ctrl+V (Paste) into it. Now the trick is that the pasted Action might inherit its position from the scene and that may let the Action invisible on your Animation Editor until you zoom out the editor window. Instead of zooming out just enter 0,0 to the positions (right after you paste the Action in the Action will be selected so you literately just enter the numbers on the right hand side). Now you should see the Action in there...
     
    khalid likes this.
  19. khalid

    khalid Avid Boxer

    Joined:
    Feb 17, 2016
    Messages:
    343
    Likes Received:
    67
    I see.. I will try it now
     
  20. khalid

    khalid Avid Boxer

    Joined:
    Feb 17, 2016
    Messages:
    343
    Likes Received:
    67
    @trudnai

    It is working but on jumping game the numbers are going crazy!! do you want me to attach a file?!
     

Share This Page