简体   繁体   English

Android API模拟器与设备

[英]Android api emulator vs. device

I am developing a game My code works fine in the 4.0 Emulator but not on my Samsung galaxy W with 2.3.6 I did't use code that isn't suitable with the device version but how ever on my device nothing moves but there isn't even an error in logcat or sth. 我正在开发游戏我的代码在4.0模拟器中可以正常工作,但在2.3.6的三星银河W上却无法正常工作,我没有使用不适合该设备版本的代码,但是我的设备上什么也没动,但是却没有甚至没有logcat或其他错误。

MainActivity : 主要活动 :

public class ControlsActivity extends Activity implements OnTouchListener{

    Button up;
    Button down;
    Button left;
    Button right;

    String view;

    static boolean touch=false;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);

        up = (Button) findViewById(R.id.up);
        up.setOnTouchListener(this);

        down = (Button) findViewById(R.id.down);
        down.setOnTouchListener(this);

        left = (Button) findViewById(R.id.left);
        left.setOnTouchListener(this);

       right = (Button) findViewById(R.id.right);
        right.setOnTouchListener(this);



    }


    @Override
    public boolean onTouch(View v, MotionEvent event) {
        /*
        view = v.toString();
        if (ControlsActivity.view == "up" && ControlsActivity.touch == true)
        {
            ph--;
        }
        if (ControlsActivity.view == "down" && ControlsActivity.touch == true)
        {
            ph++;
        }
        if (ControlsActivity.view == "left" && ControlsActivity.touch == true)
        {
            pw--;
        }
        if (ControlsActivity.view == "right" && ControlsActivity.touch == true)
        {
            pw++;
        }
        */
        if(event.toString().contains("action=ACTION_UP"))
        {
            touch = false; 
        }

        if(event.toString().contains("action=ACTION_DOWN"))
        {

            touch = true;
        }


        return touch;

    }



}

Canvas : 画布:

public class draw extends View {
    //Canvas ca;
    View v;
    Paint paint;

    int width;
    int height;

    static final int MAX_GAME_SPEED=25;
    static int fps; 



    static int speed=3;
    static int pw=0;
    static int ph=0;





    public draw(Context context, AttributeSet attr){
           super(context, attr);
           Thread myThread = new Thread(new UpdateThread());
           myThread.start();
    }


   /* public draw(Context context) {
            super(context);
            Thread myThread = new Thread(new UpdateThread());
            myThread.start();
        }  */

            @Override
        protected void onDraw(Canvas c){
        super.onDraw(c);
        paint = new Paint(); //Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);


        //get screen size
        WindowManager wm = (WindowManager) this.getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();


        width = display.getWidth();  // deprecated
        height = display.getHeight();  // deprecated







            // make the entire canvas white
            paint.setColor(Color.WHITE);
            c.drawPaint(paint);


            //ca = c;
            paint.setColor(Color.BLACK);
            c.drawRect(Math.round(width/3),Math.round(height/3),Math.round((width/3)*2),Math.round((height/3)*2), paint); //position width, position height,width,height




            paint.setColor(Color.GREEN);
            c.drawRect(pw,ph, pw+50,ph+50, paint);

            //pw++;
            //ph++;

            /*if(pw >= width)
            {
                pw = 0;
            }
            if(ph >= height)
            {
                ph = 0;
            }
            if(pw <= 0)
            {
                pw = width;
            }
            if(ph <= 0)
            {
                ph = height;
            }*/

            if(ControlsActivity.touch == true)
            {
                pw=pw+speed;
                ph=ph+speed;
            }
            else
            {

            }


    }

            public Handler updateHandler = new Handler(){
                /** Gets called on every message that is received */
                // @Override
                public void handleMessage(Message msg) {

                  invalidate();
                    super.handleMessage(msg);
                }
            };



            public class UpdateThread implements Runnable {

                @Override
                public void run() {
                    while(true){ //Game Loop

                        long startTime = System.currentTimeMillis();
                        draw.this.updateHandler.sendEmptyMessage(0); //veranlassen, dass paint() erneut aufgerufen werden soll 
                        //for (int i=0; i<999999; i++); //Bremse

                        Thread.yield();                 
                        long executionTime = System.currentTimeMillis()-startTime;

                        if (executionTime<MAX_GAME_SPEED){
                            try {
                                Thread.sleep(MAX_GAME_SPEED-(int)executionTime);
                            } catch (InterruptedException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            fps=1000/MAX_GAME_SPEED;
                        } else fps=(int) (1000/executionTime);

                    }

                }

            }

    }

Did you check the 你检查了吗

<uses-sdk android:minSdkVersion="10" />

in your Manifest-File? 在清单文件中?

http://developer.android.com/guide/appendix/api-levels.html http://developer.android.com/guide/appendix/api-levels.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM