[Android] Cocos2dxActivity changes and using layout files with Cocos2dxGLSurfaceView


I posted the same comment in the relevant github commit here: https://github.com/cocos2d/cocos2d-x/commit/1f5a870149513c37c96fd3761b7ee0876a55a45d#commitcomment-1942469

Figured I would use the forum on this as well. I’m new to Android and cocos2d-x so bare with the noob questions. Thanks!

I have a question about this. In Cocos2dxActivity you made is so that it initializes it’s own Cocos2dxGLSurfaceView. This breaks the common pattern I’ve seen where you’d define a GLSurfaceView in your layout file and referencing to that in your Activity code. For example:

private Cocos2dxGLSurfaceView mGLView;

protected void onCreate(Bundle savedInstanceState){
mGLView = (Cocos2dxGLSurfaceView) findViewById(R.id.game_gl_surfaceview);
… etc.

I see how this makes it easier since it’d handle all the activity related events in the superclass, but it’s not obvious to me how I can define a variable sized GLSurfaceView in my activity. How can we still achieve this with the changes made here? The reason I’d like to do this is that I still want to layer Android UI elements around the GLSurfaceView for things like menu items that I don’t want to do in Cocos2d-x. Thanks!


Any news here? I have a similar problem.


Marcin Szulc wrote:

Any news here? I have a similar problem.

I ended up hacking it a bit. Make mGLSurfaceView public, and add a setter method for it that sets the rendere on it like so:

public void setmGLSurefaceView(Cocos2dxGLSurfaceView newSurfaceView) {
mGLSurefaceView = newSurfaceView;
mGLSurefaceView.setCocos2dxRenderer(new Cocos2dxRenderer());

so on your activity find the glSurfaceView and set it

Cocos2dxGLSurfaceView glSurfaceView = (Cocos2dxGLSurfaceView)this.findViewById(R.id.game_gl_surfaceview);