I am doing a game mainly for Android, but I do not discard porting to other platforms. Developing for min SDK version 8, testing with a Samsung Galaxy S i9003 with Android 3.2. Using cocos2d-x version 2.
My game is using accelerometer in some moments. The problem is that if the player doesn’t touch the screen while playing with the accelerometer, the system goes to sleep and enter background mode. My question is that if cocos2dx provides any mechanism to prevent android go to sleep while using accelerometer.
Another solution is to avoid the entire app entering sleep mode, but I prefer do not avoid it in entire app, I prefer only do it whilst using accelerometer.
But this lock prevents the application enters sleep mode even in background. How can I activate/deactivate wake lock depending on cocos2dx- scene?? any suggestion??
public Cocos2dxGLSurfaceView onCreateView() {
// Init handler
// FrameLayout
ViewGroup.LayoutParams framelayout_params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
FrameLayout framelayout = new FrameLayout(this);
framelayout.setLayoutParams(framelayout_params);
// Cocos2dxGLSurfaceView
Cocos2dxGLSurfaceView gLSurfaceView = new Cocos2dxGLSurfaceView(this);
// ...add to FrameLayout
framelayout.addView(gLSurfaceView);
gLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
// Set framelayout as the content view
setContentView(framelayout);
// set the keep screen on flag
gLSurfaceView.setKeepScreenOn(true);
return gLSurfaceView;
}