I have been creating a simple little racing game for my computer
science coursework and well its broken whenever I run it in the
emulator it force closes, could you please check my code to see whats
wrong with it??
heres the code if you want the entire project I put it on
http://www.anddev.org/my_racing_game_wont_work-t12492.html thanks;
public class Draw extends Activity {
public int dx;
public int dy;
public double Angle;
private float mcarWidth;
private float mcarHeight;
public int mcarx;
public int mcary;
public int mx;
public int my;
public int[][] TrackCords;
public boolean cord;
public int i;
Bitmap mCar;
Bitmap mTrack1;
Bitmap mTrack2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mCar = BitmapFactory.decodeResource(getResources(),
R.drawable.car);
mTrack1 = BitmapFactory.decodeResource(getResources(),
R.drawable.track1);
mTrack2 = BitmapFactory.decodeResource(getResources(),
R.drawable.track2);
mcarWidth = mCar.getWidth();
mcarHeight = mCar.getHeight();
mx = 0;
my = 0;
setContentView(new Panel(this));
}
class Panel extends SurfaceView implements SurfaceHolder.Callback{
private TilterThread mthread;
public Panel(Context context) {
super(context);
getHolder().addCallback(this);
mthread = new TilterThread(getHolder(), this);
}
@Override
public void onMeasure(int widthMeasureSpec, int
heightMeasureSpec){
dy = measureHeight(heightMeasureSpec);
dx = measureWidth(widthMeasureSpec);
mcarx = (int) (dx/2-mcarWidth/2);
mcary = (int) (dy - mcarHeight);
Angle =0;
setMeasuredDimension(dx,dy);
}
private int measureHeight(int Measure) {
int specSize = MeasureSpec.getSize(Measure);
return specSize;
}
private int measureWidth(int Measure) {
int specSize = MeasureSpec.getSize(Measure);
return specSize;
}
public void TrackPosFinder(int mx, int my){
cord = false;
if (my >= 0)
{
do
{
my -=100;
if (my >0){
cord=true;
}
}
while (cord = false);
}
TrackCords[1][0]=mx;
TrackCords[1][1]=my;
cord = false;
i = 1;
do{
my +=100;
TrackCords[i][0]=mx;
TrackCords[i][1]=my;
}
while(cord = false);
}
@Override
public void onDraw(Canvas canvas) {
my += 1;
TrackPosFinder(mx , my);
for( i=0; i<TrackCords.length; i+=2)
{
canvas.drawBitmap(mTrack1,
TrackCords[i][0],TrackCords[i]
[1],null);
canvas.drawBitmap(mTrack2,
TrackCords[i+1][0],TracCords[i+1]
[1],null);
}
canvas.rotate((float) Angle, (float) dy,(float) dx);
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(mCar, mcarx, mcary, null);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mthread.setRunning(true);
mthread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
mthread.setRunning(false);
while (retry) {
try {
mthread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent msg) {
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
Angle += -10;
}
if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
Angle += 10;
}
return (true);
}
}
class TilterThread extends Thread {
private SurfaceHolder msurfaceHolder;
private Panel mpanel;
private boolean mrun = false;
public TilterThread(SurfaceHolder surfaceHolder, Panel panel)
{
msurfaceHolder = surfaceHolder;
mpanel = panel;
}
public void setRunning(boolean run) {
mrun = run;
}
@Override
public void run() {
Canvas c;
while (mrun) {
c = null;
try {
c = msurfaceHolder.lockCanvas(null);
synchronized (msurfaceHolder) {
mpanel.onDraw(c);
}
} finally {
if (c != null) {
msurfaceHolder.unlockCanvasAndPost(c);
}
catch (InterruptedException e) {
}
}
}
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
To unsubscribe, reply using "remove me" as the subject.