Cocos2d-JS切换场景与切换特效
var HelloWorldLayer = cc.Layer.extend({ sprite:null, ctor:function () { ////////////////////////////// // 1. super init first this._super(); var size=cc.winSize; //旧场景 var background=new cc.Sprite(res.CloseNormal_png); background.setPosition(size.width/2,size.height/2); this.addChild(background); this.scheduleOnce(function(f){ //创建新场景 var newScene=new cc.Scene(); var newBackground=new cc.Sprite(res.HelloWorld_png); newBackground.setPosition(size.width/2,size.height/2); newScene.addChild(newBackground); //替换场景 cc.director.runScene(newScene); },3); return true; } }); var HelloWorldScene = cc.Scene.extend({ onEnter:function () { this._super(); var layer = new HelloWorldLayer(); this.addChild(layer); } });
场景切换特效:
//渐变替换 var transition=new cc.TransitionCrossFade(1,newScene); cc.director.runScene(transition);
//翻页替换 var transition=new cc.TransitionPageTurn(1,newScene,false); cc.director.runScene(transition);
....
注意:
coocs2d-js 3.x 之后场景切换用的是 cc.director.runScene , cc.director.replaceScene在浏览器测试会失效
2024还活着,挺好的,向着星辰与深渊,加油,博客园不要倒下啊!