07851a16-e973-4a09-bb18-45bf2c8df000.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. cc._RF.push(module, '07851oW6XNKCbsYRb8sjfAA', 'pondLayer');
  3. // Script/pondLayer.js
  4. "use strict";
  5. // Learn cc.Class:
  6. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  7. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  8. // Learn Attribute:
  9. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  10. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  11. // Learn life-cycle callbacks:
  12. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  13. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  14. cc.Class({
  15. "extends": cc.Component,
  16. properties: {// foo: {
  17. // // ATTRIBUTES:
  18. // default: null, // The default value will be used only when the component attaching
  19. // // to a node for the first time
  20. // type: cc.SpriteFrame, // optional, default is typeof default
  21. // serializable: true, // optional, default is true
  22. // },
  23. // bar: {
  24. // get () {
  25. // return this._bar;
  26. // },
  27. // set (value) {
  28. // this._bar = value;
  29. // }
  30. // },
  31. },
  32. // LIFE-CYCLE CALLBACKS:
  33. onLoad: function onLoad() {
  34. this.index = 0;
  35. this.count = 0;
  36. this.flora = null;
  37. },
  38. /**
  39. * 加载精灵
  40. * @param {*} index
  41. */
  42. loadSprite: function loadSprite(index) {
  43. var node = cc.instantiate(this.flora);
  44. cc.log("------------index-----------: ", index);
  45. var self = this;
  46. var name = 'bg/bg' + index;
  47. cc.loader.loadRes(name, cc.SpriteFrame, function (err, spFrame) {
  48. // if (self.index == 3) {
  49. // self.index = 0;
  50. // ++index;
  51. // }
  52. if (self.count == 5) return;
  53. if (err) {
  54. cc.log(err.message || err);
  55. return;
  56. }
  57. var node = new cc.Node('newNode');
  58. var sprite = node.addComponent(cc.Sprite);
  59. sprite.spriteFrame = spFrame;
  60. node.anchorY = 0;
  61. node.anchorX = 0;
  62. node.x = 0;
  63. node.y = -self.node.getContentSize().height * self.count;
  64. self.node.addChild(node); // ++self.index;
  65. ++self.count;
  66. self.loadSprite(index);
  67. var flora = cc.instantiate(self.flora);
  68. flora.x = self.count % 2 == 0 ? 100 : 500;
  69. flora.y = 300;
  70. node.addChild(flora);
  71. });
  72. },
  73. start: function start() {} // update (dt) {},
  74. });
  75. cc._RF.pop();