Cocos2d-x 3.2 onEnter与onEnterTransitionDidFinish的区别

前端之家收集整理的这篇文章主要介绍了Cocos2d-x 3.2 onEnter与onEnterTransitionDidFinish的区别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
CCLayer类里的虚函数

onEnter()--------Layer界面只要显示一点就会调用

onEnterTransitionDidFinish()--------Layer界面完全显示完全时候调用

onExit()
比如需要播放背景音乐,背景音乐可以在一开始进入场景 onEnter() 时候进行预加载,然后在完全进入场景onEnterTransitionDidFinish() 的时候开始播放音乐。
  1. <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>
  2. //在完全进入这个场景后开始执行的事件
  3. voidMenuScene::onEnterTransitionDidFinish()
  4. {
  5. //完全进入场景后开始播放音乐
  6. <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");
  7. }
原文链接:https://www.f2er.com/cocos2dx/344189.html

猜你在找的Cocos2d-x相关文章