Add an XML layout file for a cocos2d-x project ported to the Android platform

Source: Internet
Author: User

Reprint please indicate source: http://blog.csdn.net/vistatns/article/details/51316462


(porting the Cocos2d-x project to Android please go to : http://blog.csdn.net/vistatns/article/details/51316103)


1. Add a layout file main.xml



<? XML version="1.0" encoding="Utf-8"?>

< Relativelayout xmlns:android="Http://schemas.android.com/apk/res/android"

android:layout_width="Match_parent"

android:layout_height="Match_parent"

android:orientation="vertical" >

< Relativelayout

android:id="@+id/gameviewlay"

android:layout_width="Fill_parent"

android:layout_height="fill_parent" />

</ Relativelayout >


2. Introduce the XML layout file into the java file and add the setcocosview , Introduction of XML initialization


@Override

Public void Setcocosview (Cocos2dxglsurfaceview Mglsurfaceview) {

Setcontentview (r.layout. Main);

Relativelayout framelayout = (relativelayout) Findviewbyid (r.id. Gameviewlay);

Framelayout.addview (Mglsurfaceview);

System. out. println ("txc:setcocosview--initialization");

}


3. This time may be error, because there is no such parent method to cover you


(1). Select the first item

Create setcocosview () in coco2dactivity


(2). Move the contents of init () to Setcocosview ()


(3). In Init (), Add the following :


Cocos2dxglsurfaceview

this. Mglsurfaceview =this. Oncreateview ();

//Switch to supported OpenGL (ARGB888) mode on emulator

//if (Isandroidemulator ())

//This.mGLSurfaceView.setEGLConfigChooser (8, 8, 8, 8, +, 0);

this. Mglsurfaceview. Setcocos2dxrenderer (new cocos2dxrenderer ());

Setcocosview (mglsurfaceview);

(4). and look at the original . Java file, no errors.



4. Run the test


It worked!

Add an XML layout file for a cocos2d-x project ported to the Android platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.