onExit()
比如需要播放背景音乐,背景音乐可以在一开始进入场景 onEnter() 时候进行预加载,然后在完全进入场景onEnterTransitionDidFinish() 的时候开始播放音乐。
- <pclass="p1"><spanclass="s1">void</span><spanclass="s2"></span><spanclass="s3">MenuScene</span><spanclass="s2">::onEnter()</span></p><pclass="s4"style="font-family:Arial;"></span><spanclass="s5"style="font-family:Arial;">//</span><spanclass="s2"style="font-family:Arial;">在刚进入界面的时候预加载背景音乐,在</span><spanclass="s5"style="font-family:Arial;">MenuScene</span><spanclass="s2"style="font-family:Arial;">场景开始播放音乐</span></p><pclass="p1"><spanstyle="font-family:Arial;">{</span></p><pclass="p3"><spanclass="s6"></span><spanclass="s3">SimpleAudioEngine</span><spanclass="s6">::</span><spanclass="s2">getInstance</span><spanclass="s6">()-></span><spanclass="s2">preloadBackgroundMusic</span><spanclass="s6">(</span><spanclass="s7">"Background/Background1.mp3"</span><spanclass="s6">);</span></p><pclass="p1"><spanclass="s2">}</span></p>
- //在完全进入这个场景后开始执行的事件
- voidMenuScene::onEnterTransitionDidFinish()
- {
- //完全进入场景后开始播放音乐
- <spanclass="s3"style="color:rgb(51,51);font-family:monospace;font-size:14px;line-height:26px;white-space:pre;background-color:rgb(240,240,240);">SimpleAudioEngine</span><spanclass="s6"style="color:rgb(51,240);">::</span><spanclass="s2"style="color:rgb(51,240);">getInstance</span><span>()-></span>playBackgroundMusic("Background/Background1.mp3");
- }