Created
October 8, 2014 22:23
-
-
Save jouderianjr/9860ccf5280b2c5f3ac3 to your computer and use it in GitHub Desktop.
Infinite animation in titanium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
px2dpi = function(px) { | |
return Math.ceil(px / (Titanium.Platform.displayCaps.dpi / 160)); | |
}; | |
var widthSquare = px2dpi(Ti.Platform.displayCaps.platformWidth); | |
$.square1.left = 0; | |
$.square2.left = widthSquare; | |
$.square1.width = widthSquare; | |
$.square2.width = widthSquare; | |
function startAnim(){ | |
var anim = Ti.UI.createAnimation({ | |
left: -widthSquare, | |
duration: 2500, | |
}); | |
var anim2 = Ti.UI.createAnimation({ | |
duration: 5000, | |
left: -widthSquare | |
}); | |
anim.addEventListener('complete', function(evt){ | |
console.log("FINALIZOU O ANIM 1"); | |
$.square1.left = widthSquare; | |
anim.duration = 5000; | |
console.log("anim = "+JSON.stringify(anim)); | |
console.log("SQUARE! = "+JSON.stringify($.square1)); | |
$.square1.animate(anim); | |
}); | |
anim2.addEventListener('complete', function(evt){ | |
console.log("FINALIZOU O ANIM 2"); | |
console.log("anim = "+JSON.stringify(anim2)); | |
$.square2.left = widthSquare; | |
console.log("SQUARE! = "+JSON.stringify($.square2)); | |
$.square2.animate(anim2); | |
}); | |
$.square1.animate(anim); | |
$.square2.animate(anim2); | |
} | |
$.index.open(); | |
$.index.addEventListener('open', function(evt){ | |
startAnim(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment