Background.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. function Background() {
  2. base(this,LSprite,[]);
  3. this.init();
  4. }
  5. Background.prototype.init = function() {
  6. var self = this;
  7. self.backgroundBitmapData = new LBitmapData(dataList["background"],0,0,640,960);
  8. self.backgroundBitmap = new LBitmap(self.backgroundBitmapData);
  9. self.backgroundBitmap.x = 0;
  10. self.backgroundBitmap.y = 0;
  11. self.addChild(self.backgroundBitmap);
  12. self.addShape(LShape.RECT, [0,LGlobal.height,LGlobal.width,1]);
  13. self.addShape(LShape.RECT, [-1,0,1,LGlobal.height]);
  14. self.addShape(LShape.RECT, [LGlobal.width,0,1,LGlobal.height]);
  15. self.bubbleBitmapData = new LBitmapData(dataList["bubble"],0,0,640,960);
  16. self.setBubbles(10);
  17. };
  18. Background.prototype.setBubbles = function(number) {
  19. var self = this;
  20. for(var i = 0; i < number; i++) {
  21. self.bubbleBitmap = new LBitmap(self.bubbleBitmapData);
  22. self.bubbleBitmap.x = Util.randomInRange(0, (620-20)/number)+20+i*(620-20)/number;
  23. self.bubbleBitmap.y = Util.randomInRange(600, 930);
  24. self.addChild(self.bubbleBitmap);
  25. self.bubbleBitmap.originalY = self.bubbleBitmap.y;
  26. self.bubbleBitmap.originalX = self.bubbleBitmap.x;
  27. self.bubbleBitmap.originalScale = Util.randomInRange(0.8, 1.2);
  28. self.bubbleBitmap.scaleX = self.bubbleBitmap.scaleY = self.bubbleBitmap.originalScale;
  29. (function() {
  30. var object = self.bubbleBitmap;
  31. object.alpha = 0;
  32. setTimeout(function() {
  33. object.alpha = 1;
  34. self.bubble1(object, Util.randomInRange(4, 10));
  35. }, Util.randomInRange(0, 4000));
  36. })();
  37. }
  38. }
  39. Background.prototype.bubble = function(object, direction) {
  40. var self = this;
  41. var target = {};
  42. target.y = object.y - 150;
  43. if(target.y < 160) target.y = 160;
  44. target.x = object.x+direction*50;
  45. target.scale = object.scaleX+0.1
  46. LTweenLite.to(object, 1, {y:target.y, x:target.x, scaleX:target.scale, scaleY:target.scale, ease:LEasing.None.easeOut, onComplete:function() {
  47. if(target.y<=160) {
  48. object.y = object.originalY;
  49. object.x = object.originalX;
  50. object.scaleX = object.scaleY = 1;
  51. }
  52. self.bubble(object, -direction);
  53. }});
  54. }
  55. Background.prototype.bubble1 = function(object, duration) {
  56. LTweenLite.to(object, duration, {y:Util.randomInRange(160, 200), scaleX:object.originalScale*1.6, scaleY:object.originalScale*1.6, alpha:0.7, loop:true, ease:LEasing.None.easeOut, onComplete:function() {
  57. object.y = object.originalY;
  58. object.scaleX = object.scaleY = object.originalScale;
  59. object.alpha = 1;
  60. }});
  61. }