我正处于Cocos2d-Android游戏的最后阶段,遇到一个我无法解决的问题.
当我锁定平板电脑(Nexus 7)或按下主屏幕按钮退出游戏时,它将重新启动.它会立即回到启动屏幕,就像游戏重新开始一样.供您参考,这是我的主要活动和AndroID清单:
public class MainActivity extends Activity {//To get a static reference to context for shared preferencesprivate static Context context;protected CCGLSurfaceVIEw _glSurfaceVIEw;@OverrIDepublic voID onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); //To get a static reference to context for shared preferences MainActivity.context = getApplicationContext(); requestwindowFeature(Window.FEATURE_NO_Title); getwindow().setFlags(WindowManager.LayoutParams.FLAG_FulLSCREEN, WindowManager.LayoutParams.FLAG_FulLSCREEN); getwindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); _glSurfaceVIEw = new CCGLSurfaceVIEw(this); setContentVIEw(_glSurfaceVIEw);}//To get a static reference to context for shared preferencespublic static Context getAppContext(){ return MainActivity.context;}@OverrIDepublic voID onStart(){ super.onStart(); CCDirector.sharedDirector().attachInVIEw(_glSurfaceVIEw); CCDirector.sharedDirector().setDeviceOrIEntation(CCDirector.kCCDeviceOrIEntationPortrait); CCDirector.sharedDirector().setdisplayFPS(true); CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f); CCScene scene = Splash.scene(); CCDirector.sharedDirector().runWithScene(scene);}@OverrIDepublic voID onPause(){ super.onPause(); CCDirector.sharedDirector().pause(); SoundEngine.sharedEngine().pauseSound();}@OverrIDepublic voID onResume(){ super.onResume(); CCDirector.sharedDirector().resume(); SoundEngine.sharedEngine().resumeSound();}@OverrIDepublic voID onStop(){ super.onStop(); SoundEngine.sharedEngine().pauseSound();}
和
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"package="bigfiresoftware.Alphadefender"androID:versionCode="1"androID:versionname="1.0" ><uses-sdk androID:minSdkVersion="8" androID:targetSdkVersion="16" /><application androID:allowBackup="true" androID:icon="@drawable/adicon" androID:label="@string/app_name" androID:theme="@style/Apptheme"> <activity androID:name="bigfiresoftware.Alphadefender.MainActivity" androID:screenorIEntation="portrait" androID:label="@string/app_name" androID:harDWareAccelerated="false"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>androID:configChanges="keyboard|keyboardHIDden|orIEntation" </manifest>
任何/所有帮助非常感谢.谢谢.
解决方法:
将清单文件中的以下行添加到活动中.
androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenLayout|uiMode|screenSize|smallestScreenSize"
当您锁定屏幕时,屏幕的方向会发生变化.因此,您的活动将被破坏并再次创建.
总结以上是内存溢出为你收集整理的Cocos2d Android锁定屏幕或离开游戏强制重启全部内容,希望文章能够帮你解决Cocos2d Android锁定屏幕或离开游戏强制重启所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)