Offline cache - keeping current position of app

Hi,
I made a little app! Only issue is that, if you are part way through the timeline process, pressing the Home button (iPhone, and then reopening) makes the animation restart at the beginning. What I’d really like is to reopen the app at the same point.

Can this be done?

Basically you have to store the timecode of your timelines in question and restore them on a reload. To move this variables across page refreshes you can use LocalStorage.

I just today wrote a wrapper for Hype for LocalConnection. It offers some Hype specific perks to LocalStorage and I might write a helper function to store and restore timeline positions but for now it only gives you a basic interface to LocalConnection.

If either option is to complicated maybe somebody else on the forum can help you to write the needed JS (for either option). I certainly will reply to this post if I add timeline positions to Hype StateKit.

1 Like

Accidentally replied on the other post about this. Thanks for the reply. It’s a little over my head, admittedly, but I’m going to show it to a JS coder I know for help!

The simplest way (using localStorage directly) if you only have one timeline is to just store the timecode, direction and play state in regular intervals … and on scene load restore it :

var tlTime = Number(localStorage.tlTime);
var tlDir = Number(localStorage.tlDir);
var tlPlay = Boolean(localStorage.tlPlay);

if (!isNaN(tlTime)){
	hypeDocument.goToTimeInTimelineNamed(tlTime, 'Main Timeline');
	if (tlPlay) {
		hypeDocument.continueTimelineNamed('Main Timeline', tlDir, false);
	}
}

setInterval( function(){
	localStorage.tlTime = hypeDocument.currentTimeInTimelineNamed('Main Timeline');
	localStorage.tlDir = hypeDocument.currentDirectionForTimelineNamed('Main Timeline');
	localStorage.tlPlay = hypeDocument.isPlayingTimelineNamed('Main Timeline');
} , 1000/60);

That should do the trick for a simple one scene Hype file.

if you ever need to reset just call (that kills all localStorage data)

localStorage.clear();

Example:
persistantTimeline.hype.zip (21,9 KB)

3 Likes

Is there a way to do multiple timelines? Here’s a test persistantTimeline-DUB2.hype.zip (27.5 KB)