Merge branch 'inflateViews' of https://github.com/Macarse/cocos2d-x into Macarse-inflateViews

This commit is contained in:
minggo 2011-04-12 15:12:48 +08:00
commit 8e85f56f97
4 changed files with 75 additions and 35 deletions

View File

@ -1,16 +1,22 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package org.cocos2dx.tests;
public final class R {
public static final class attr {
}
public static final class string {
public static final int app_name=0x7f020000;
}
}
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package org.cocos2dx.tests;
public final class R {
public static final class attr {
}
public static final class id {
public static final int test_demo_gl_surfaceview=0x7f040000;
}
public static final class layout {
public static final int test_demo=0x7f020000;
}
public static final class string {
public static final int app_name=0x7f030000;
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cocos2d-x"/>
<org.cocos2dx.lib.Cocos2dxGLSurfaceView
android:id="@+id/test_demo_gl_surfaceview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

View File

@ -2,11 +2,12 @@ package org.cocos2dx.lib;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
public class Cocos2dxGLSurfaceView extends GLSurfaceView{
public class Cocos2dxGLSurfaceView extends GLSurfaceView {
private static final String TAG = Cocos2dxGLSurfaceView.class
.getCanonicalName();
private Cocos2dxRenderer mRenderer;
@ -14,6 +15,15 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView{
public Cocos2dxGLSurfaceView(Context context) {
super(context);
initView();
}
public Cocos2dxGLSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
initView();
}
private void initView() {
mRenderer = new Cocos2dxRenderer();
setFocusableInTouchMode(true);
setRenderer(mRenderer);
@ -29,12 +39,12 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView{
for (int i = 0; i < pointerNumber; i++) {
ids[i] = event.getPointerId(i);
xs[i] = event.getX(i);
ys[i] = event.getY(i);
ys[i] = event.getY(i);
}
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_DOWN:
final int idPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
case MotionEvent.ACTION_POINTER_DOWN:
final int idPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
final float xPointerDown = event.getX(idPointerDown);
final float yPointerDown = event.getY(idPointerDown);
@ -46,9 +56,9 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView{
});
break;
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_DOWN:
// there are only one finger on the screen
final int idDown = event.getPointerId(0);
final int idDown = event.getPointerId(0);
final float xDown = event.getX(idDown);
final float yDown = event.getY(idDown);
@ -60,7 +70,7 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView{
});
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_MOVE:
queueEvent(new Runnable() {
@Override
public void run() {
@ -69,8 +79,8 @@ public class Cocos2dxGLSurfaceView extends GLSurfaceView{
});
break;
case MotionEvent.ACTION_POINTER_UP:
final int idPointerUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
case MotionEvent.ACTION_POINTER_UP:
final int idPointerUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
final float xPointerUp = event.getX(idPointerUp);
final float yPointerUp = event.getY(idPointerUp);

View File

@ -3,22 +3,32 @@ package org.cocos2dx.tests;
import org.cocos2dx.lib.Cocos2dxActivity;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
public class TestsDemo extends Cocos2dxActivity{
protected void onCreate(Bundle savedInstanceState){
private Cocos2dxGLSurfaceView mGLView;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
// get the packageName,it's used to set the resource path
String packageName = getApplication().getPackageName();
super.setPackgeName(packageName);
mGLView = new Cocos2dxGLSurfaceView(this);
setContentView(mGLView);
}
setContentView(R.layout.test_demo);
mGLView = (Cocos2dxGLSurfaceView) findViewById(R.id.test_demo_gl_surfaceview);
// Get the size of the mGLView after the layout happens
mGLView.post(new Runnable() {
@Override
public void run() {
Cocos2dxActivity.screenHeight = mGLView.getHeight();
Cocos2dxActivity.screenWidth = mGLView.getWidth();
}
});
}
@Override
protected void onPause() {
super.onPause();
@ -35,9 +45,7 @@ public class TestsDemo extends Cocos2dxActivity{
android.os.Process.killProcess(android.os.Process.myPid());
}
private GLSurfaceView mGLView;
static {
System.loadLibrary("cocosdenshion");
System.loadLibrary("chipmunk");