3

私はcocos2dxを使用してAndroidライブ壁紙に取り組んでおり、ライブ壁紙を表示することに成功しましたが、タッチの問題に直面しています。Android では、ccTouchBegan、ccTouchMoved などのタッチ関連のメソッドが呼び出されません。win32 ではタッチ コールバックを取得していますが、Android では取得していません。誰かその解決策を教えてください。ライブ壁紙については、.java クラスにいくつかの変更を加えました。私はJavaクラスを添付しています。どんな助けでも大歓迎です。

    /****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package com.live.MyClass;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import org.cocos2dx.lib.Cocos2dxHelper;
import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
import org.cocos2dx.lib.Cocos2dxRenderer;
import android.view.MotionEvent;
import android.content.Context;
import android.opengl.GLSurfaceView.Renderer;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.View.OnTouchListener;

/*public class MyClass extends Cocos2dxActivity{

    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
    }

    static {
         System.loadLibrary("game");
    }
}*/

public class MyClass extends WallpaperService{
    static {
        System.loadLibrary("game");
    }
    @Override
    public Engine onCreateEngine()
    {
        Log.d("MyClass", "onCreateEngine");
        return new MyWallpaperEngine();
    }


    protected class MyWallpaperEngine extends Engine implements Cocos2dxHelperListener
    {
        public class MyGLSurfaceView extends Cocos2dxGLSurfaceView
        {


            MyGLSurfaceView(Context context)
            {
                super(context);
                Log.d("MyClass", "MyGLSurfaceView YYYY");
                this.setFocusableInTouchMode(true);

            }


            @Override
            public SurfaceHolder getHolder()
            {

                Log.d("MyClass", "getHolder &&&&&");
                return getSurfaceHolder();
            }

            public void onDestroy()
            {
                Log.d("MyClass", "MyGLSurfaceView onDestroy");
                super.onDetachedFromWindow();
            }




        }

        protected class MyGLRenderer extends Cocos2dxRenderer
        {
                //prevent the cocos2dxRenderer from calling nativeInit
                        @Override
                public void onSurfaceCreated(final GL10 pGL10, final EGLConfig pEGLConfig) {
                }

                @Override
                public void onSurfaceChanged(final GL10 pGL10, final int pWidth, final int pHeight) {
                    Log.d("MyClass", "MyGLRenderer onSurfaceChanged");
                        setScreenWidthAndHeight(pWidth, pHeight);
                        super.onSurfaceCreated(null, null);
                }

        }

        private MyGLSurfaceView mGLSurfaceView;
        //private Cocos2dxGLSurfaceView mGLSurfaceView;
        private boolean rendererHasBeenSet;            

        @Override
        public void onCreate(SurfaceHolder surfaceHolder)
        {
            super.onCreate(surfaceHolder);
            setTouchEventsEnabled(true);
            mGLSurfaceView = new MyGLSurfaceView(MyClass.this);
           // mGLSurfaceView = new Cocos2dxGLSurfaceView(MyClass.this);
            mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);


            //mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
            Log.d("MyClass", "MyGLRenderer onCreate");
            setRenderer(getNewRenderer());
            Cocos2dxHelper.init(MyClass.this, this);
        }

        @Override
        public void onVisibilityChanged(boolean visible)
        {
            super.onVisibilityChanged(visible);
            Log.d("MyClass", "onVisibilityChanged ::"+visible);
            if (visible)
            {

                Cocos2dxHelper.onResume();
                mGLSurfaceView.onResume();
            }
            else
            {
                Cocos2dxHelper.onPause();
                mGLSurfaceView.onPause();            
            }
        }

        @Override
        public void onDestroy()
        {
            super.onDestroy();

            Cocos2dxHelper.end();
            Log.d("MyClass", "onDestroy ");
            mGLSurfaceView.onDestroy();
        }

                protected void setRenderer(Renderer renderer) {
                    Log.d("MyClass", "setRenderer");
                        mGLSurfaceView.setCocos2dxRenderer((Cocos2dxRenderer) renderer);
                        rendererHasBeenSet = true;
                }

                Renderer getNewRenderer(){
                        Cocos2dxRenderer renderer = new MyGLRenderer();
                        return renderer;
                }

        @Override
        public void showDialog(String pTitle, String pMessage)
        {
        }

        @Override
        public void showEditTextDialog(String pTitle, String pMessage, int pInputMode, int pInputFlag, int pReturnType, int pMaxLength)
        {
        }

        @Override
        public void runOnGLThread(Runnable pRunnable)
        {
            mGLSurfaceView.queueEvent(pRunnable);
        }  
    }


}
4

1 に答える 1

0

クラスに関数を追加するだけです:

    @Override
    public void onTouchEvent(final MotionEvent pMotionEvent)
    {
        mGLSurfaceView.onTouchEvent(pMotionEvent);
    }

ところで、あなたのブール値は何のrendererHasBeenSetためですか?

于 2014-01-15T08:15:43.333 に答える