1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- "use strict";
- cc._RF.push(module, '07851oW6XNKCbsYRb8sjfAA', 'pondLayer');
- // Script/pondLayer.js
- "use strict";
- // Learn cc.Class:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
- cc.Class({
- "extends": cc.Component,
- properties: {// foo: {
- // // ATTRIBUTES:
- // default: null, // The default value will be used only when the component attaching
- // // to a node for the first time
- // type: cc.SpriteFrame, // optional, default is typeof default
- // serializable: true, // optional, default is true
- // },
- // bar: {
- // get () {
- // return this._bar;
- // },
- // set (value) {
- // this._bar = value;
- // }
- // },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad: function onLoad() {
- this.index = 0;
- this.count = 0;
- this.flora = null;
- },
- /**
- * 加载精灵
- * @param {*} index
- */
- loadSprite: function loadSprite(index) {
- var node = cc.instantiate(this.flora);
- cc.log("------------index-----------: ", index);
- var self = this;
- var name = 'bg/bg' + index;
- cc.loader.loadRes(name, cc.SpriteFrame, function (err, spFrame) {
- // if (self.index == 3) {
- // self.index = 0;
- // ++index;
- // }
- if (self.count == 5) return;
- if (err) {
- cc.log(err.message || err);
- return;
- }
- var node = new cc.Node('newNode');
- var sprite = node.addComponent(cc.Sprite);
- sprite.spriteFrame = spFrame;
- node.anchorY = 0;
- node.anchorX = 0;
- node.x = 0;
- node.y = -self.node.getContentSize().height * self.count;
- self.node.addChild(node); // ++self.index;
- ++self.count;
- self.loadSprite(index);
- var flora = cc.instantiate(self.flora);
- flora.x = self.count % 2 == 0 ? 100 : 500;
- flora.y = 300;
- node.addChild(flora);
- });
- },
- start: function start() {} // update (dt) {},
- });
- cc._RF.pop();
|