How to make a status like HP decrease after closing the app?

Anything libgdx related goes here!

How to make a status like HP decrease after closing the app?

Postby BulbulitusPrime » Sun Nov 11, 2018 8:28 pm

So i'm trying to make a virtual pet game but I can't figure out how to make the statuses decrease automatically even after closing the app. Do you compare the date/time after closing the app and opening it again, to calculate the status loss? If so, how do you do that? Or is there a better way of doing it?
BulbulitusPrime
 
Posts: 4
Joined: Sun Nov 11, 2018 8:20 pm

Re: How to make a status like HP decrease after closing the

Postby evilentity » Sun Nov 11, 2018 9:38 pm

Thats exactly how you do it. You compare closing and starting times and calculate change based on that. You change it the same way you already do it, just the delta will be larger.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4555
Joined: Wed Aug 24, 2011 11:37 am

Re: How to make a status like HP decrease after closing the

Postby BulbulitusPrime » Sun Nov 11, 2018 10:04 pm

evilentity wrote:Thats exactly how you do it. You compare closing and starting times and calculate change based on that. You change it the same way you already do it, just the delta will be larger.


Thanks for your help! Is there a Libgdx class to acquire the system's date? Sorry, i'm pretty new with libgdx so this might be a stupid question
BulbulitusPrime
 
Posts: 4
Joined: Sun Nov 11, 2018 8:20 pm

Re: How to make a status like HP decrease after closing the

Postby Magnesus » Sun Nov 11, 2018 11:21 pm

Just use Java.

Date currentTime = Calendar.getInstance().getTime();

Or just:

Calendar calendar = Calendar.getInstance();
calendar.get(Calendar.YEAR); // check what other values that enum has


Should work on all platforms.


Other method would be to use unixtime:

// gets time in seconds since 1980 or something like that :) easy to compare how many seconds passed since previous time you saved the value
public static long getUnixtime()
{
return (long) (System.currentTimeMillis() / 1000L);
}
Magnesus
 
Posts: 1649
Joined: Sun Sep 25, 2011 3:50 pm

Re: How to make a status like HP decrease after closing the

Postby BulbulitusPrime » Mon Nov 12, 2018 11:24 am

Thanks! Will mess around with it after learning how to save
BulbulitusPrime
 
Posts: 4
Joined: Sun Nov 11, 2018 8:20 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest