var mainLayer = cc.Layer.extend({ ctor : function () { this._super(); cc.associateWithNative(this, cc.Layer);
// 中间背景 var mainBG1 = cc.Sprite.create(Res.Images.Main.main_bg); var scale = WIN_HEIGHT / mainBG1.getContentSize().height; mainBG1.setScale(scale); mainBG1.setAnchorPoint(cc.p(0.5, 0.5)); mainBG1.setPosition(cc.p(WIN_WIDTH / 2, WIN_HEIGHT / 2)); this.addChild(mainBG1); this.mainBG1 = mainBG1;
// 粒子 火焰 this.ParticleSnow = cc.ParticleSystem.create(Res.Plists.Splash.splash_plist); mainBG1.addChild(this.ParticleSnow); this.ParticleSnow.setPosition(cc.p(260, 120)); if (this.ParticleSnow.setShapeType) this.ParticleSnow.setShapeType(cc.PARTICLE_STAR_SHAPE);
// 粒子 雪花 this._emitter = cc.ParticleRain.create(); mainBG1.addChild(this._emitter); this._emitter.setPosition(cc.p(320, 960)); this._emitter.setLife(5); this._emitter.setLifeVar(1); this._emitter.setGravity(cc.p(0, -10)); this._emitter.setSpeed(10); this._emitter.setSpeedVar(200);
var startColor = this._emitter.getStartColor(); startColor.r = 0.9; startColor.g = 0.9; startColor.b = 0.9; this._emitter.setStartColor(startColor);
var startColorVar = this._emitter.getStartColorVar(); startColorVar.b = 0.1; this._emitter.setStartColorVar(startColorVar); this._emitter.setEmissionRate(this._emitter.getTotalParticles() / this._emitter.getLife()); this._emitter.setTexture(cc.TextureCache.getInstance().addImage(Res.Images.Main.menu_snow)); if (this._emitter.setShapeType) this._emitter.setShapeType(cc.PARTICLE_STAR_SHAPE);
// var mainBG2 = cc.Sprite.create(Res.Images.Main.main_bg); // mainBG2.setScale(scale); // mainBG2.setAnchorPoint(cc.p(0, 0)); // mainBG2.setPosition(cc.p(mainBG1.getContentSize().width, 0)); // this.addChild(mainBG2); // this.mainBG2 = mainBG2; // this.schedule(this.update);
// 上中下三层 this.topLayer = Global.topLayer = new topLayer(); this.addChild(this.topLayer, 1, 1);
this.botLayer = Global.botLayer = new botLayer(); this.addChild(this.botLayer, 1, 2);
this.midLayer = Global.midLayer = new midLayer(); this.midLayer.setScale(WIN_SCALE_WIDTH); this.addChild(this.midLayer, 0, 3); }, update : function () { //创建两个点对象..分别保存两张地图的位置 var map_1p = this.mainBG1.getPosition(); var map_2p = this.mainBG2.getPosition();
//每次调用这个函数的时候就设置两张地图的位置..这里的-3值越大也就越快. this.mainBG1.setPosition(cc.p(map_1p.x - 0.2, map_1p.y)); this.mainBG2.setPosition(cc.p(map_2p.x - 0.2, map_2p.y));
//分别判断地图.如果完全出场景了..马上调整位置接上 var scale = WIN_HEIGHT / this.mainBG1.getContentSize().height; if (map_1p.x < 0) { this.mainBG2.setPosition(cc.p(map_1p.x + this.mainBG1.getContentSize().width * scale - 2, map_1p.y)); }
if (map_2p.x < 0) { this.mainBG1.setPosition(cc.p(map_2p.x + this.mainBG2.getContentSize().width * scale - 2, map_2p.y)); } } });