问题描述 游戏开发中会有多个场景,有时会有这样的需求,我们需要保证场景跳转但是需要保持某个游戏对象不被销毁,比如:音乐 实现思路 unity中提供了DontDestroyOnLoad(),这个API 使用这个指令一般写在跳转场景之前,写在跳转场景的触发事件中,把背景音乐绑定的对象做成预制体,上面绑定了播放音乐的代码 实现代码 using System.Collections; using System.Collections.Generic; using UnityEngine; using U
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.wid