Distance Counter For Bb3

Discussion in 'Buildbox 3.0' started by bgwiss, Dec 30, 2018.

  1. bgwiss

    bgwiss Boxer

    Joined:
    Oct 31, 2018
    Messages:
    58
    Likes Received:
    16
    Hi All,

    Have anyone figured out a way to set an event observer for a distance covered by the character?
    I would be really grateful for those who could help.

    Thanks
    Wiss
     
  2. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    222
    Likes Received:
    165
    there is no event observer. you can use this code for distance.
    • let dist = this.scene().path().pathPosition(); //distance
    • log(Math.round(dist));
     
  3. bgwiss

    bgwiss Boxer

    Joined:
    Oct 31, 2018
    Messages:
    58
    Likes Received:
    16
    Ok this is good, but how can I display the log output in a label?
     
  4. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    222
    Likes Received:
    165
    let dist = this.scene().path().pathPosition(); //distance
    this.entity().component('Label').setText(String(Math.round(dist)));
     
    bgwiss likes this.
  5. bgwiss

    bgwiss Boxer

    Joined:
    Oct 31, 2018
    Messages:
    58
    Likes Received:
    16
    I tried it, it gives a value of null
     
  6. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    222
    Likes Received:
    165
  7. bgwiss

    bgwiss Boxer

    Joined:
    Oct 31, 2018
    Messages:
    58
    Likes Received:
    16
    Thank you, it worked :)
     
  8. Tumbleweeds

    Tumbleweeds Boxer

    Joined:
    Dec 18, 2018
    Messages:
    18
    Likes Received:
    8
    Wow! Thank you. Very useful post.
    - 2D text on screen
    - UI buttons with click handlers
    - Settings object
    Curious where you found this functionality. Is this from BuildBox2 or is this from the templates? I don't see any of this listed in the API.
     
  9. Larry Pendleton

    Larry Pendleton Boxer

    Joined:
    Aug 2, 2018
    Messages:
    58
    Likes Received:
    10
    I'd like to see a follow up to this, showing how to find a Label from the Game UI, and assign the dist value to it, instead of it being a component.

    I have already attempted this in update:
    Code:
    let dist = this.scene().path().pathPosition();
    let _distanceLabel = this.ui().find('Distance')[0];
    log(_distanceLabel.text());
    _distanceLabel.setText(String(Math.round(dist)));
    Thanks
    -Larry
     
  10. awais503

    awais503 Boxer

    Joined:
    Sep 8, 2017
    Messages:
    12
    Likes Received:
    1
    Not working with the UI Text.
     
  11. Mrsi

    Mrsi Boxer

    Joined:
    Jul 3, 2018
    Messages:
    30
    Likes Received:
    2
    Does anyone know how I can change the "undefined" and "NaN" text to the level numbers? Also, how do I make the progress bar finish right as a level is complete?

    Thanks

    Screen Shot 2019-04-08 at 7.39.03 PM.png
     
  12. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    222
    Likes Received:
    165
    if(Settings.level === undefined){
    Settings.level = 1;
    }
     
  13. shahar.m192

    shahar.m192 Avid Boxer

    Joined:
    Oct 7, 2018
    Messages:
    144
    Likes Received:
    20
    how can i change the way that the distance are being numbered like its too quick i reached only 10 scenes and im on 33875 something like this can someone help??

    and i removed the
    • log(Math.round(dist));
    and its suppose to make my game run smoother but i think its not help so much.
     
  14. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    222
    Likes Received:
    165
    yes u don't need log. you can use this: Math.round(dist)/100
    33875 this will be 338
     
  15. shahar.m192

    shahar.m192 Avid Boxer

    Joined:
    Oct 7, 2018
    Messages:
    144
    Likes Received:
    20
    Many thanks to you brother and another thing how can i present in game ui my best distance that i have reached?
     
  16. weboha

    weboha Avid Boxer

    Joined:
    Aug 8, 2018
    Messages:
    222
    Likes Received:
    165
    in UI add an asset and add a label inside
    for best score, you can create another global var.
    use if dist>bestdist update bestdist
     
  17. shahar.m192

    shahar.m192 Avid Boxer

    Joined:
    Oct 7, 2018
    Messages:
    144
    Likes Received:
    20
    i put all of this


    let dist = this.scene().path().pathPosition(); //distance

    this.entity().component('Label').setText(String(Math.round(dist)));

    with the label node near this code added math.round(dist)/100

    i exported this as an asset and copy it into the ui but i cant see nothing its not show me the distance please help

    thanks

     
  18. Iman M

    Iman M Boxer

    Joined:
    Sep 26, 2018
    Messages:
    5
    Likes Received:
    0
  19. shahar.m192

    shahar.m192 Avid Boxer

    Joined:
    Oct 7, 2018
    Messages:
    144
    Likes Received:
    20
    this is the code thats working


    function init(){

    }

    function update(dt){

    let dist = this.scene().path().pathPosition();

    this.entity().component('Label').setText(String(Math.round(dist/100)));

    }

    function signal(name, value) {

    }
     
  20. shahar.m192

    shahar.m192 Avid Boxer

    Joined:
    Oct 7, 2018
    Messages:
    144
    Likes Received:
    20
    function init(){

    }

    function update(dt,bestdist='0'){

    let dist = this.scene().path().pathPosition();

    let bestdist = this.scene().path().pathPosition();



    this.entity().component('Label2').setText(String(Math.round(dist/100)));



    if(bestdist==null){



    }



    else(dist>bestdist){

    bestdist.update;

    }

    }

    function signal(name, value) {

    }



    how do i make this like a total coin or somthing like that how can i save the best distance after i close the game?
     

Share This Page