I have an animated GIF that is set to play just once rather than loop. Placed within a scene it plays as you would expect. When I navigate away from the scene, and then back again, the GIF does not play again, it just displays the last frame.
This could be useful for some situations but I would ideally like it to trigger every time the scene is visited (which I would have expected to be the default). Is there a way to achieve this without any clever timeline jumping to force it?
You would need to set a On Scene load action to set the inner HTML of an element to contain the image. When this is set, the image will be re-added to the DOM and will play from the beginning:
I have not had any luck with this one i’m afraid. Attached is a simple working file to test the process. Are you able to shed light as to where I am going wrong?
Thanks Mark. Yes that has fixed the pulling in of the image, but as you say, the refreshing of the GIF does not occur. Do you have any other ideas how I might achieve this?
I got one of the ideas working. I actually tried this this morning but used the pure date instead of the just the time, which did not work.
var d = new Date();
hypeDocument.getElementById("imgcontainer").innerHTML = '<img src="' + '${resourcesFolderName}/test.gif?dummy=' + d.getTime() + '">';
you should also clear the interval when leaving the scene before the animation is complete. also may consider requestAnimationFrame insteadof setInterval
I assume this is better because it works on the natural frame rate of the browser which is what this example is aiming for, so thats why it is better in this case ?..
I tried your coding but the display of the gif seems wrong. Can you please help me to identify where i have gone wrong? Punjabi_Version_2.hype.zip (2.4 MB)
I have attached the gif file where it should be and the hype file.
this line sets the name of the image: imgcontainer.style.backgroundImage = 'url( ${resourcesFolderName}/test_' + ('0' + imageNumber).slice(-2) + '.gif)'
Hi @MarkHunte I have followed your example (test_MHv3) and have it running successfully with my own gif. However the gif I have created I believe is 25 fps, whereas I understand a browsers natural frame rate is 60fps so the gif is playing to fast. Is there a way I could resolve this?
Thanks
Update: I have looked at test_MHv2 and changed the ‘33’ in the last section of code to a higher number (100) and this has slowed the frame rate down to nearly match the original gif.