Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Rallentamento slideshow

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    8

    Rallentamento slideshow

    Ciao a tutti,
    per lavoro mi capita di realizzare delle presentazioni, cosa che ho sempre fatto con Adobe Flash + JS2.
    Ora sto usando Animate Animate + JS3, ma utilizzando Canvas HTML5.

    Premesso che se qualche anno fa ero abbastanza al passo con i tempi, oggi, ci capisco veramente poco.

    Io devo realizzare una semplice filmato, con 2 pulsanti 'avanti' e 'indietro' che appaiono in concomitanza con gli 'stop' nel filmato.

    Es. 9 fotogrammi totali:
    Fotogramma 1 - stop + tasto avanti
    Fotogramma 3 - stop + tasto avanti e tasto indietro
    Fotogramma 5 - stop + tasto avanti e tasto indietro
    Fotogramma 7 - stop + tasto avanti e tasto indietro
    Fotogramma 9 - stop + tasto indietro

    I fotogrammi 2/4/6/8, sono semplicemente di passaggio (mi occorrono per effetti di transizione).

    Usando gli Snippet di Animation, riesco a generare il codice, e funziona.
    Il problema è che questa animazione tende a rallentare, fino a bloccarsi.
    Ossia, con vari clic arrivo al fotogramma 9, clicco l'altro tasto varie volte e torno a 1, ma diventa sempre più lento. Ho provato con vari browser...

    Codice HTML:
    codice:
    <!DOCTYPE html><!--
    	NOTES:
    	1. All tokens are represented by '$' sign in the template.
    	2. You can write your code only wherever mentioned.
    	3. All occurrences of existing tokens will be replaced by their appropriate values.
    	4. Blank lines will be removed automatically.
    	5. Remove unnecessary comments before creating your template.
    -->
    <html>
    <head>
    <meta charset="UTF-8">
    <meta name="authoring-tool" content="Adobe_Animate_CC">
    <title>Senza nome-6</title>
    <!-- write your code here -->
    <style>
      #animation_container {
    	position:absolute;
    	margin:auto;
    	left:0;right:0;
    	top:0;bottom:0;
      }
    </style>
    <script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>
    <script src="Senza nome-6.js"></script>
    <script>
    var canvas, stage, exportRoot, anim_container, dom_overlay_container, fnStartAnimation;
    function init() {
    	canvas = document.getElementById("canvas");
    	anim_container = document.getElementById("animation_container");
    	dom_overlay_container = document.getElementById("dom_overlay_container");
    	var comp=AdobeAn.getComposition("419C0C039A827B4AB109A4D8D2A85761");
    	var lib=comp.getLibrary();
    	handleComplete({},comp);
    }
    function handleComplete(evt,comp) {
    	//This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
    	var lib=comp.getLibrary();
    	var ss=comp.getSpriteSheet();
    	exportRoot = new lib.Senzanome6();
    	stage = new lib.Stage(canvas);
    	stage.enableMouseOver();	
    	//Registers the "tick" event listener.
    	fnStartAnimation = function() {
    		stage.addChild(exportRoot);
    		createjs.Ticker.setFPS(lib.properties.fps);
    		createjs.Ticker.addEventListener("tick", stage);
    	}	    
    	//Code to support hidpi screens and responsive scaling.
    	function makeResponsive(isResp, respDim, isScale, scaleType) {		
    		var lastW, lastH, lastS=1;		
    		window.addEventListener('resize', resizeCanvas);		
    		resizeCanvas();		
    		function resizeCanvas() {			
    			var w = lib.properties.width, h = lib.properties.height;			
    			var iw = window.innerWidth, ih=window.innerHeight;			
    			var pRatio = window.devicePixelRatio || 1, xRatio=iw/w, yRatio=ih/h, sRatio=1;			
    			if(isResp) {                
    				if((respDim=='width'&&lastW==iw) || (respDim=='height'&&lastH==ih)) {                    
    					sRatio = lastS;                
    				}				
    				else if(!isScale) {					
    					if(iw<w || ih<h)						
    						sRatio = Math.min(xRatio, yRatio);				
    				}				
    				else if(scaleType==1) {					
    					sRatio = Math.min(xRatio, yRatio);				
    				}				
    				else if(scaleType==2) {					
    					sRatio = Math.max(xRatio, yRatio);				
    				}			
    			}			
    			canvas.width = w*pRatio*sRatio;			
    			canvas.height = h*pRatio*sRatio;
    			canvas.style.width = dom_overlay_container.style.width = anim_container.style.width =  w*sRatio+'px';				
    			canvas.style.height = anim_container.style.height = dom_overlay_container.style.height = h*sRatio+'px';
    			stage.scaleX = pRatio*sRatio;			
    			stage.scaleY = pRatio*sRatio;			
    			lastW = iw; lastH = ih; lastS = sRatio;            
    			stage.tickOnUpdate = false;            
    			stage.update();            
    			stage.tickOnUpdate = true;		
    		}
    	}
    	makeResponsive(false,'both',false,1);	
    	AdobeAn.compositionLoaded(lib.properties.id);
    	fnStartAnimation();
    }
    </script>
    <!-- write your code here -->
    </head>
    <body onload="init();" style="margin:0px;">
    	<div id="animation_container" style="background-color:rgba(255, 255, 255, 1.00); width:550px; height:400px">
    		<canvas id="canvas" width="550" height="400" style="position: absolute; display: block; background-color:rgba(255, 255, 255, 1.00);"></canvas>
    		<div id="dom_overlay_container" style="pointer-events:none; overflow:hidden; width:550px; height:400px; position: absolute; left: 0px; top: 0px; display: block;">
    		</div>
    	</div>
    </body>
    
    </html>


    Codice JS:
    codice:
    (function (cjs, an) {
    
    var p; // shortcut to reference prototypes
    var lib={};var ss={};var img={};
    lib.ssMetadata = [];
    
    
    
    
    // symbols:
    
    
    
    
    
    
    (lib.Simbolo1 = function(mode,startPosition,loop) {
    	this.initialize(mode,startPosition,loop,{});
    
    
    	// Livello_1
    	this.shape = new cjs.Shape();
    	this.shape.graphics.f("#333333").s().p("Ah/CAIAAj/ID/AAIAAD/g");
    
    
    	this.shape_1 = new cjs.Shape();
    	this.shape_1.graphics.f("#006699").s().p("Ah/CAIAAj/ID/AAIAAD/g");
    
    
    	this.shape_2 = new cjs.Shape();
    	this.shape_2.graphics.f("#00FFFF").s().p("Ah/CAIAAj/ID/AAIAAD/g");
    
    
    	this.timeline.addTween(cjs.Tween.get({}).to({state:[{t:this.shape}]}).to({state:[{t:this.shape_1}]},1).to({state:[{t:this.shape_2}]},1).to({state:[{t:this.shape_2}]},1).wait(1));
    
    
    }).prototype = p = new cjs.MovieClip();
    p.nominalBounds = new cjs.Rectangle(-12.8,-12.8,25.6,25.6);
    
    
    
    
    // stage content:
    (lib.Senzanome6 = function(mode,startPosition,loop) {
    	this.initialize(mode,startPosition,loop,{uno:0,due:2,tre:4,quattro:6,cinque:8});
    
    
    	// timeline functions:
    	this.frame_0 = function() {
    		this.stop();
    		
    		var _this = this;
    		_this.pulsanteavanti.on('click', function () {
    			_this.gotoAndStop('due');
    		
    		});
    	}
    	this.frame_2 = function() {
    		this.stop();
    		
    		var _this = this;
    		_this.pulsantearretre.on('click', function(){
    		_this.gotoAndStop('uno');
    		});
    		
    		var _this = this;
    		_this.pulsanteavanti.on('click', function(){
    		_this.gotoAndStop('tre');
    		});
    	}
    	this.frame_4 = function() {
    		this.stop();
    		
    		var _this = this;
    		_this.pulsantearretre.on('click', function(){
    		_this.gotoAndStop('due');
    		});
    		
    		var _this = this;
    		_this.pulsanteavanti.on('click', function(){
    		_this.gotoAndStop('quattro');
    		});
    	}
    	this.frame_6 = function() {
    		this.stop();
    		
    		var _this = this;
    		_this.pulsantearretre.on('click', function(){
    		_this.gotoAndStop('tre');
    		});
    		
    		var _this = this;
    		_this.pulsanteavanti.on('click', function(){
    		_this.gotoAndStop('cinque');
    		});
    	}
    	this.frame_8 = function() {
    		this.stop();
    		
    		var _this = this;
    		_this.pulsantearretre.on('click', function(){
    		_this.gotoAndStop('quattro');
    		});
    	}
    
    
    	// actions tween:
    	this.timeline.addTween(cjs.Tween.get(this).call(this.frame_0).wait(2).call(this.frame_2).wait(2).call(this.frame_4).wait(2).call(this.frame_6).wait(2).call(this.frame_8).wait(1));
    
    
    	// pulsanti
    	this.pulsanteavanti = new lib.Simbolo1();
    	this.pulsanteavanti.name = "pulsanteavanti";
    	this.pulsanteavanti.parent = this;
    	this.pulsanteavanti.setTransform(499.2,200.8);
    	new cjs.ButtonHelper(this.pulsanteavanti, 0, 1, 2, false, new lib.Simbolo1(), 3);
    
    
    	this.pulsantearretre = new lib.Simbolo1();
    	this.pulsantearretre.name = "pulsantearretre";
    	this.pulsantearretre.parent = this;
    	this.pulsantearretre.setTransform(43.6,200.8);
    	new cjs.ButtonHelper(this.pulsantearretre, 0, 1, 2, false, new lib.Simbolo1(), 3);
    
    
    	this.timeline.addTween(cjs.Tween.get({}).to({state:[{t:this.pulsanteavanti}]}).to({state:[{t:this.pulsanteavanti},{t:this.pulsantearretre}]},2).to({state:[{t:this.pulsanteavanti},{t:this.pulsantearretre}]},2).to({state:[{t:this.pulsanteavanti},{t:this.pulsantearretre}]},2).to({state:[{t:this.pulsantearretre}]},2).wait(1));
    
    
    	// Livello_2
    	this.shape = new cjs.Shape();
    	this.shape.graphics.f("#333333").s().p("AARCWQgGgGAAgIIAAjzIgcAMQgHADgGAAQgJAAgGgGQgFgFAAgJQAAgHACgFQAEgFAGgCIA+gWIAIgCQAIAAAGAGQAGAFgBAKIAAEOQAAAIgFAGQgGAGgJAAQgIAAgGgGg");
    	this.shape.setTransform(273.7,204.6);
    
    
    	this.shape_1 = new cjs.Shape();
    	this.shape_1.graphics.f("#333333").s().p("AhJCcQgJAAgGgGQgFgGgBgIQAAgJAGgGIBxiDQAZgdAAgVQAAgagOgQQgNgQgXAAQgOAAgMAIQgNAIgGANQgIANAAAQQABAIgHAGQgFAGgJAAQgIAAgHgGQgFgGgBgIQAAgbANgWQANgVAVgNQAVgMAaAAQAbAAAUALQAUAMALAVQALAWAAAdQAAARgKATQgKATgPARIhbBnIBvAAQAIAAAHAGQAFAHAAAIQAAAIgFAGQgHAGgIAAg");
    	this.shape_1.setTransform(275.8,205.1);
    
    
    	this.shape_2 = new cjs.Shape();
    	this.shape_2.graphics.f("#333333").s().p("AgxCQQgXgMgOgXQgNgVAAgbQAAgJAFgGQAGgGAIgBQAIABAFAGQAFAGAAAJQAAAQAIAOQAJANAOAJQAPAIARAAQAaAAAQgPQARgOAAgbQAAgQgIgOQgHgNgMgJQgNgHgPgBQgIAAgGgFQgGgGAAgIQAAgJAGgFQAGgHAIABQALAAAKgHQALgFAHgKQAGgKAAgMQAAgSgNgLQgMgNgUAAQgPAAgMAGQgNAHgHAJQgHAKAAAMQAAAKgGAGQgFAGgIABQgIAAgFgHQgFgFAAgJQAAgXAMgSQAMgTAVgKQAUgMAZAAQAXAAATALQATAKALASQALARAAAWQAAAVgNAQQgOAQgUAJQAeAKAPAVQAPAWAAAcQAAAagNAVQgOAVgWAMQgWALgaAAQgdAAgXgMg");
    	this.shape_2.setTransform(275.7,205.1);
    
    
    	this.shape_3 = new cjs.Shape();
    	this.shape_3.graphics.f("#333333").s().p("AApCWQgGgGAAgIIAAgyIiEAAQgJAAgGgHQgFgGgBgIQAAgGAEgFICYjIQAIgJAJAAQAJAAAFAGQAGAGgBAJIAAC3IAYAAQAKAAAFAEQAGAEgBAKQABAIgGAFQgGAGgJAAIgYAAIAAAyQAAAIgFAGQgGAGgJAAQgHAAgGgGgAhBAxIBkAAIAAiEg");
    	this.shape_3.setTransform(275.1,205.1);
    
    
    	this.shape_4 = new cjs.Shape();
    	this.shape_4.graphics.f("#333333").s().p("AgzCPQgXgOgNgXQgOgXAAgdQAAgIAGgGQAFgGAJAAQAJAAAGAGQAGAGAAAIQAAARAIAPQAIANAOAIQAOAIAQAAQARAAAOgIQAOgIAIgNQAIgPAAgRQAAgRgIgOQgIgOgOgIQgOgHgRAAIhCAAQgJAAgFgGQgGgGAAgIIAAhsQAAgJAGgGQAFgGAJAAICFAAQAIAAAGAGQAGAGAAAJQAAAIgGAGQgGAGgIAAIhwAAIAABDIAtAAQAcAAAYAOQAXANANAXQAOAXAAAcQAAAdgOAXQgNAXgXAOQgYANgcAAQgcAAgXgNg");
    	this.shape_4.setTransform(275.7,205.1);
    
    
    	this.timeline.addTween(cjs.Tween.get({}).to({state:[{t:this.shape}]}).to({state:[{t:this.shape_1}]},2).to({state:[{t:this.shape_2}]},2).to({state:[{t:this.shape_3}]},2).to({state:[{t:this.shape_4}]},2).wait(1));
    
    
    }).prototype = p = new cjs.MovieClip();
    p.nominalBounds = new cjs.Rectangle(540.1,366.8,247,66.4);
    // library properties:
    lib.properties = {
    	id: '419C0C039A827B4AB109A4D8D2A85761',
    	width: 550,
    	height: 400,
    	fps: 24,
    	color: "#FFFFFF",
    	opacity: 1.00,
    	manifest: [],
    	preloads: []
    };
    
    
    
    
    
    
    // bootstrap callback support:
    
    
    (lib.Stage = function(canvas) {
    	createjs.Stage.call(this, canvas);
    }).prototype = p = new createjs.Stage();
    
    
    p.setAutoPlay = function(autoPlay) {
    	this.tickEnabled = autoPlay;
    }
    p.play = function() { this.tickEnabled = true; this.getChildAt(0).gotoAndPlay(this.getTimelinePosition()) }
    p.stop = function(ms) { if(ms) this.seek(ms); this.tickEnabled = false; }
    p.seek = function(ms) { this.tickEnabled = true; this.getChildAt(0).gotoAndStop(lib.properties.fps * ms / 1000); }
    p.getDuration = function() { return this.getChildAt(0).totalFrames / lib.properties.fps * 1000; }
    
    
    p.getTimelinePosition = function() { return this.getChildAt(0).currentFrame / lib.properties.fps * 1000; }
    
    
    an.bootcompsLoaded = an.bootcompsLoaded || [];
    if(!an.bootstrapListeners) {
    	an.bootstrapListeners=[];
    }
    
    
    an.bootstrapCallback=function(fnCallback) {
    	an.bootstrapListeners.push(fnCallback);
    	if(an.bootcompsLoaded.length > 0) {
    		for(var i=0; i<an.bootcompsLoaded.length; ++i) {
    			fnCallback(an.bootcompsLoaded[i]);
    		}
    	}
    };
    
    
    an.compositions = an.compositions || {};
    an.compositions['419C0C039A827B4AB109A4D8D2A85761'] = {
    	getStage: function() { return exportRoot.getStage(); },
    	getLibrary: function() { return lib; },
    	getSpriteSheet: function() { return ss; },
    	getImages: function() { return img; }
    };
    
    
    an.compositionLoaded = function(id) {
    	an.bootcompsLoaded.push(id);
    	for(var j=0; j<an.bootstrapListeners.length; j++) {
    		an.bootstrapListeners[j](id);
    	}
    }
    
    
    an.getComposition = function(id) {
    	return an.compositions[id];
    }
    
    
    
    
    
    
    })(createjs = createjs||{}, AdobeAn = AdobeAn||{});
    
    var createjs, AdobeAn;


  2. #2
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    8
    Potreste aiutarmi??
    GRAZIE!

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    8
    Mi spiace insistere... ma non riesco a risolvere! Grazie!

  4. #4
    Considerato il largo uso di js ti sposto
    “Che le cose siano cosi, non vuol dire che debbano andare così. Solo che quando si tratta di rimboccarsi le maniche e incominciare a cambiare, vi è un prezzo da pagare. Ed è allora che la stragrande maggioranza preferisce lamentarsi più che fare”.

    Giovanni Falcone

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    8
    Probabilmente era l'ABC, ma nessuno ha voluto dirmelo.

    Comunque ho trovato una soluzione, la posto, magari a qualcun'altro potrebbe essere utile.

    In ogni fotogramma con i pulsanti (e quindi le azioni), aggiungere le due righe di codice "removeAllEventListeners":

    codice:
    this.stop();
    
    this.pulsanteindietro.removeAllEventListeners("click");
    this.pulsanteavanti.removeAllEventListeners("click");
    
    
    var _this = this;
    _this.pulsanteindietro.on('click', function(){
    _this.gotoAndStop(numero_nome_fotogramma);
    });
    
    
    var _this = this;
    _this.pulsanteavanti.on('click', function(){
    _this.gotoAndPlay(numero_nome_fotogramma);
    });
    Io così ho risolto.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.