Util.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. Util = function(){};
  2. Util.randomN = function(n) {
  3. return Math.floor(Math.random()*n);
  4. }
  5. Util.randomInRange = function(min, max) {
  6. return min+(Math.random()*(max-min));
  7. }
  8. Util.fadeIn = function(object, duration) {
  9. LTweenLite.to(object, duration, {alpha:1, ease:LEasing.Sine.easeIn})
  10. }
  11. Util.fadeOut = function(object, duration, callback) {
  12. LTweenLite.to(object, duration, {alpha:0, ease:LEasing.Sine.easeOut, onComplete:callback});
  13. }
  14. Util.sFloat = function(object, duration) {
  15. originY = object.y;
  16. LTweenLite.to(object, duration, {y:originY-10, loop:true, ease:LEasing.None.easeIn})
  17. .to(object, duration, {y:originY+10, loop:true, ease:LEasing.None.easeIn});
  18. }
  19. Util.fadeInOut = function(object, duration, _loop, alpha) {
  20. LTweenLite.to(object, duration, {alpha:1, loop:_loop, ease:LEasing.None.easeIn})
  21. .to(object, duration, {alpha:alpha, loop:_loop, ease:LEasing.None.easeIn});
  22. }
  23. Util.correctInRange = function(v, min, max) {
  24. if(v < min) return min;
  25. else if(v > max) return max;
  26. else return v;
  27. }
  28. Util.shuffle = function(array){
  29. var randomCompare = function(){
  30. return (Math.random()>0.5)?(-1):1;
  31. }
  32. return array.sort(randomCompare);
  33. }
  34. Util.range = function(a,b,step){
  35. var result = [];
  36. if(arguments[2] == undefined) step = 1;
  37. for(var i = a; i < b; i+=step){
  38. result.push(i);
  39. }
  40. return result;
  41. }