Calulate Higest Distance

0 favourites
  • 6 posts
From the Asset Store
This sound library contains 197 rifle sounds. The sounds of gunshots, the sounds of shots from a distance
  • I have multipile player objects. I want to zoom my game out enough to they all will be seen.

    I think that this is most easily be done by just calculating distance between objects and doing re-scaling with it. Higher number, less zoom. If you have better idea to do the same, I'll accept it as answer as well.

    So, how to calculate higest distance between like +4 same objects?

  • Using the search I found these two topics:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • this isn't answer good enough because they work if there is two objects, but number of objects I have can change a lot, even during the game.

  • I guess it will only work with four variables and then something like this:

    LowestX

    HighestX

    LowestY

    HighestY

    every tick

    Set lowestX to 99999999

    Set HighestX to -9999999

    Set lowestY to 99999999

    Set HighestY to -9999999

    for each player

    if player.x < LowestX

    set Lowest.X to player.x

    etcetera

    and then you can change the example from above with these Global Variable values

  • you could also do a:

    for each sprite (ordered by sprite.x, ascending): set lowestx to sprite.x; stop loop

    for each sprite (ordered by sprite.x, descending): set highestx to sprite.x; stop loop

    etc.

    set scrollx to (highestx+lowestx)/2

    set scrolly to (highesty+lowesty)/2

    and calculate the zoom according to your aspect ratio etc.

  • you could also do a:

    for each sprite (ordered by sprite.x, ascending): set lowestx to sprite.x; stop loop

    for each sprite (ordered by sprite.x, descending): set highestx to sprite.x; stop loop

    etc.

    set scrollx to (highestx+lowestx)/2

    set scrolly to (highesty+lowesty)/2

    and calculate the zoom according to your aspect ratio etc.

    Much better solution.

    I'm so not into loops, haha..

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)