Difference between revisions of "Controlling Gifs and SPA's"

From PowerUI
Jump to: navigation, search
(Events)
(Events)
Line 30: Line 30:
 
<syntaxhighlight lang="csharp">
 
<syntaxhighlight lang="csharp">
 
 
// The element to add the event handlers to (typically an img, or whichever element has background-image on it):
+
// The element to add the event handlers to (typically an img, or whichever element has background-image on it):
var nyanCat=document.getElementById("nyan");
+
var nyanCat=document.getElementById("nyan");
 +
 
 +
nyanCat.addEventListener("spritestart",delegate(SpriteEvent se){
 +
 
 +
Debug.Log("Sprite start!");
 
 
nyanCat.addEventListener("spritestart",delegate(SpriteEvent se){
+
// Shortcut to stop it from looping (This will make it stop on the last frame, and spriteend is fired):
 
+
// se.loop=false;
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){
+
nyanCat.addEventListener("spriteend",delegate(SpriteEvent se){
 
 
Debug.Log("Sprite end!");
+
Debug.Log("Sprite end!");
+
});
+
});
 +
 +
nyanCat.addEventListener("spriteiteration",delegate(SpriteEvent se){
 
 
nyanCat.addEventListener("spriteiteration",delegate(SpriteEvent se){
+
Debug.Log("Sprite looped!");
 
 
Debug.Log("Sprite looped!");
+
});
 
});
 
  
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 18:18, 24 February 2017

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!");
		
});