real time count-down

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

real time count-down

Post by pielago »

okay here is my question is there a code i can have
that got to do with real time countdown?
i have one that starts at any minute to 0
but the sad part its that when it hits like (10 secs)
it goes to a single number :(

scene 1
example ( 2:10)
example ( 2: 9) <-- don't want that!
example ( 2: 8) <-- don't want that!
example ( 0: 0) <-- don't want that!

scene 2
example ( 2:10)
example ( 2:09)<---- i want that
example ( 2:08)<---- i want that
example ( 0:00)<---- i want that
scene 1 is what i have BUT scene 2 is what i seek for.. can someone help me?????
User avatar
mickeyjm
Party member
Posts: 237
Joined: Thu Dec 29, 2011 11:41 am

Re: real time count-down

Post by mickeyjm »

You can use string.format when displaying the time to achieve this
For example:

Code: Select all

string.format("%02.0f",seconds)
Or, to format the minutes aswell:

Code: Select all

string.format("%02.0f:%02.0f",minutes,seconds)
Your screen is very zoomed in...
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: real time count-down

Post by pielago »

?? how do i use that?
like can u give me an easy example?(code)
do i put that under load or update?
User avatar
mickeyjm
Party member
Posts: 237
Joined: Thu Dec 29, 2011 11:41 am

Re: real time count-down

Post by mickeyjm »

You use this when you actually want to get a string representation of the timer.
For example if you are writing the timer in the top left corner of the screen you might do

Code: Select all

love.graphics.print(string.format("%02.0f:%02.0f",minutes,seconds),0,0) --Print formatted time at 0,0
Or if you are assigning the time to a variable for later use you might do

Code: Select all

local timerAsString = string.format("%02.0f:%02.0f",minutes,seconds)
Your screen is very zoomed in...
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: real time count-down

Post by Robin »

Or, y'know, simply:

Code: Select all

local timerAsString = string.format("%02d:%02d",minutes,seconds)
Help us help you: attach a .love.
pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: real time count-down

Post by pielago »

ugh can you do a .love with a simple countdown from 2:00 to 0:00
it will be a great help for me and also for who ever comes across this problem :|
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: real time count-down

Post by Plu »

I think this works, but I cannot test it right now. (You can just put this as main.lua and run it)

Code: Select all

function love.load()
  time = 120 -- initial value in seconds
end

function love.update( dt )
  time = time - dt -- make it count down
  if time < 0 then
    time = 0 -- make it stop at 0 in the sloppiest way possible
  end
end

function love.draw()

  local minutes = math.floor( time / 60 ) -- calculate how many minutes are left
  local seconds = math.floor( time % 60 ) -- calculate how many seconds are left

  love.graphics.print( string.format("%02d:%02d",minutes,seconds), 400, 300 ) -- print it somewhere near the middle of the screen with proper formatting
end

pielago
Party member
Posts: 142
Joined: Fri Jun 14, 2013 10:41 am

Re: real time count-down

Post by pielago »

it works i see thank you so much..
I need to learn more about TIME...:)
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests