I am getting an error about 'Source Not Found' for Instrumental.class when '(new Thread(new AnimationLoop())).start();' is executed.
Any ideas?



Danuubz wrote:I've got a litte code sample for 2D animating on a simple UI extending View (wich is a little bit different from the SurfaceView approach, more like J2SE).
Red box is moving from one edge to the other. You can stop (and restart) him by pressing DPAD_CENTER.Using java Syntax Highlighting
// author: Robert Kanzamar package de.testing; import android.app.Activity; import android.os.Bundle; import android.view.*; import android.graphics.*; import android.content.*; public class Testing extends Activity { public static final int DIRECTION_RIGHT = 0, DIRECTION_LEFT = 1; private Panel main; private Bitmap scratch; private Canvas offscreen; public boolean start = true; private volatile boolean running = true; private int direction = DIRECTION_RIGHT; private int box = 10; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setOffscreenBitmap(); main = new Panel(this); setContentView(main,new ViewGroup.LayoutParams(320,480)); (new Thread(new AnimationLoop())).start(); } private void setOffscreenBitmap() { scratch = Bitmap.createBitmap(30,30,Bitmap.Config.ARGB_8888); offscreen = new Canvas(); offscreen.setBitmap(scratch); offscreen.drawColor(Color.RED); } private synchronized void updatePhysics() { if(box < 10) { direction = DIRECTION_RIGHT; } else if(box > 250) { direction = DIRECTION_LEFT; } if(direction == DIRECTION_RIGHT) { box += 10; } else { box -= 10; } } private synchronized void doDraw(Canvas canvas, Paint paint) { if(start) { canvas.drawColor(Color.BLACK); canvas.drawBitmap(scratch,10,10,paint); start = false; } else { canvas.save(); canvas.clipRect(box,8,box+32,40); canvas.drawColor(Color.RED); // canvas.drawBitmap(scratch,box,10,paint); canvas.restore(); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { if(running) { running = false; } else { running = true; } } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { finish(); } return true; } class Panel extends View { Paint paint; public Panel(Context context) { super(context); paint = new Paint(); } @Override protected void onDraw(Canvas canvas) { doDraw(canvas,paint); } } class AnimationLoop implements Runnable { public void run() { while(true) { while(running) { try { Thread.sleep(30); } catch(InterruptedException ex) {} updatePhysics(); main.postInvalidate(); } } } } }Parsed in 0.041 seconds, using GeSHi 1.0.8.4


public class GridAlpha extends Activity{
int BOARD=8;
String[]rep = new String[50];
String[]def = new String[64];
String LETTERS = "abcdefghijklmnopqrstuvwxyz";
String[][]square = new String[8][8];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
KamusDbAdapter x = new KamusDbAdapter(getApplicationContext());
x.open();
rep = x.playWord();
x.close();
Random round = new Random();int[]rec=new int[10];int m=0;
for(int i=0; i<50; i++){
//algorithm section, used to place the words inside the grid per char
}
//additional logic, used to store the char in string that will be use in gridview
//Log.v("CC",String.valueOf(cc));
ArrayAdapter<String> ad = new ArrayAdapter<String>(this,R.layout.form,def);
GridView grid=(GridView)findViewById(R.id.grid);
grid.setAdapter(ad);
grid.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String test = (ad.getItem(arg2)).toString();
Log.v("CAPTURE",test);
}
});
ListView wordlist = (ListView)findViewById(R.id.wordlist);
ArrayAdapter<String> showWord = new ArrayAdapter<String>(this,R.layout.form2,store);
wordlist.setAdapter(showWord);
}
}




/**
* Pauses the physics update & animation.
*/
public void pause() {
try{
synchronized (mSurfaceHolder) {
setState(STATE_PAUSE);
}
}catch(Exception e){
Log.d("error pausing" , "error: " +e.toString());
}
}
public void pause() {
try{
synchronized (mSurfaceHolder) {
setState(STATE_PAUSE);
}
}catch(Exception e){
Log.d("error pausing" , "error: " +e.toString());
}
}
Return to Android 2D/3D Graphics - OpenGL Tutorials
Users browsing this forum: No registered users and 6 guests