how to add a timer in gameplay

Bilzo12Bilzo12 Member Posts: 70
edited June 2012 in Working with GS (Mac)
hey everyone my problem is i have a game based on how long the hero is alive for now in the top right hand corner i want the time to go up every second by 1 then when the hero dies and the screen comes down it says the time the hero lived for and the high score

if anyone can help me with this problem ill be very happy.

thanks for reading

bilal

Answers

  • HC_DKHC_DK Member Posts: 92
    If you spawn your hero when the game starts you can use the self.Time from the hero actor.
    Contrain the self.Time to a global real attribute (HeroTimer).
    To have it look like: 00:00
    Make an actor do display the time, use the Display Text Beh. and use this expression:
    floor(floor(( game.HeroTimer %3600)/60)/10)..floor((floor( game.HeroTimer %3600)/60)%10)..":"..floor(( game.HeroTimer %60)/10)..floor( game.HeroTimer %10)

    Tested and it works.

    HC
  • Bilzo12Bilzo12 Member Posts: 70
    edited June 2012
    @HenrikChristesnsen Thank you I'll give it a go also will the score save as in high score
  • HC_DKHC_DK Member Posts: 92
    It is not saved before YOU save it. You will have to use the SAVE behaviour before the attribute is saved.
    But the attribute is global which means that you can change scene and display the Hero Active Time on a GAME OVER scene.

    Hope this answered your question.

    HC
  • Bilzo12Bilzo12 Member Posts: 70
    Ok thanks
Sign In or Register to comment.