Hi i have a problem where the touch is not recognized at all, i don't know if the event is evening happening or not, or its an error with my display. My program as of now contains 4 classes
1 - the main activity class
2 - the draw class(simple draw everything)
3 - Character class, (problem is here)
4 - Sprite class, for simple animation
Everything is working fine including the animation, but for some reason the touch is not working, here my code please help me.
The set up and style of the class is really bad, but i amjust getting started and ran into this problem.
Thank You
1 - the main activity class
2 - the draw class(simple draw everything)
3 - Character class, (problem is here)
4 - Sprite class, for simple animation
Everything is working fine including the animation, but for some reason the touch is not working, here my code please help me.
Code:
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class Character implements OnTouchListener{
private Paint paint = new Paint();
private String name;
private float mx,my;
private float x = 300;
private float y = 300;
private float Bwidth =25;
private float BHeight = 25;
private Sprite sprite;
private ArrayList<Bitmap> pics = new ArrayList<Bitmap>();
private Bitmap bm;
public Character(String name,Context context){
this.name = name;
pics.add(bm = BitmapFactory.decodeResource(context.getResources(),R.drawable.test1));
pics.add(bm = BitmapFactory.decodeResource(context.getResources(),R.drawable.test2));
pics.add(bm = BitmapFactory.decodeResource(context.getResources(),R.drawable.test3));
pics.add(bm = BitmapFactory.decodeResource(context.getResources(),R.drawable.test4));
pics.add(bm = BitmapFactory.decodeResource(context.getResources(),R.drawable.test5));
pics.add(bm = BitmapFactory.decodeResource(context.getResources(),R.drawable.test6));
sprite = new Sprite(pics);
}
public boolean onTouchEvent(MotionEvent e)
{
if(e.getAction() == MotionEvent.ACTION_DOWN)
{
mx = e.getX();
my = e.getY();
}
return true;
}
@Override
public boolean onTouch(View arg0, MotionEvent event) {
this.mx = event.getRawX();
this.my = event.getRawY();
return false;
}
public void delay(int i){
try {
Thread.sleep(i);
} catch (InterruptedException e) { }
}
public void drawButtons(Canvas canvas){
paint.setColor(Color.YELLOW);
canvas.drawRect(45,295, 45 + Bwidth, 295 + BHeight, paint);//up
canvas.drawRect(10,330, 10 + Bwidth, 330 + BHeight, paint);//down
canvas.drawRect(45,365, 45 + Bwidth, 365 + BHeight, paint);//right
canvas.drawRect(80,330, 80 + Bwidth, 330 + BHeight, paint);//left
canvas.drawRect(750,30, 750 + Bwidth, 30 + BHeight, paint);
}
public void Draw(Canvas canvas){
this.drawButtons(canvas);
this.sprite.draw(canvas);
this.delay(300);
paint.setColor(Color.BLUE);
canvas.drawText("X: "+ (int)this.mx +" "+ "Y: "+ (int)this.my, 370, 30 ,paint);
this.sprite.update();
}
}
Thank You

