Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid api emulator vs. device
    text
    copied!<p>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.</p> <p>MainActivity :</p> <pre><code>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" &amp;&amp; ControlsActivity.touch == true) { ph--; } if (ControlsActivity.view == "down" &amp;&amp; ControlsActivity.touch == true) { ph++; } if (ControlsActivity.view == "left" &amp;&amp; ControlsActivity.touch == true) { pw--; } if (ControlsActivity.view == "right" &amp;&amp; ControlsActivity.touch == true) { pw++; } */ if(event.toString().contains("action=ACTION_UP")) { touch = false; } if(event.toString().contains("action=ACTION_DOWN")) { touch = true; } return touch; } } </code></pre> <p>Canvas :</p> <pre><code>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 &gt;= width) { pw = 0; } if(ph &gt;= height) { ph = 0; } if(pw &lt;= 0) { pw = width; } if(ph &lt;= 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&lt;999999; i++); //Bremse Thread.yield(); long executionTime = System.currentTimeMillis()-startTime; if (executionTime&lt;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); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload