Controlling Gifs and SPA's

From PowerUI
Revision as of 18:17, 24 February 2017 by Bablakeluke (talk | contribs) (Events)
Jump to: navigation, search

When you display a GIF with PowerUI, it runs as a Sprite Animaton (SPA). So, both a GIF and an SPA can be controlled in the same way.

Getting hold of the SPA instance

As they can be loaded over the internet, the best way to know when your animation is available is via the spritestart event. It fires

Events

Name Event object type Purpose
spritestart PowerUI.SpriteEvent Occurs when an SPA or GIF goes on screen and has started playing.
spriteend PowerUI.SpriteEvent Occurs when an SPA or GIF goes off screen or when it is set to not loop and has finished.
spriteiteration PowerUI.SpriteEvent Occurs when an SPA or GIF loops.

Here's an example:

	
	// The element to add the event handlers to (typically an img, or whichever element has background-image on it):
	var nyanCat=document.getElementById("nyan");
	
	nyanCat.addEventListener("spritestart",delegate(SpriteEvent se){

		Debug.Log("Sprite start!");
		
		// Shortcut to stop it from looping (This will make it stop on the last frame, and spriteend is fired):
		// se.loop=false;
			
	});

	nyanCat.addEventListener("spriteend",delegate(SpriteEvent se){
		
		Debug.Log("Sprite end!");
		
	});
	
	nyanCat.addEventListener("spriteiteration",delegate(SpriteEvent se){
		
		Debug.Log("Sprite looped!");
			
	});