0
私はゲームのチックタックを作ります。私はそのボックスに触れるとボックスに入れたい画像を持っています。その問題は、画面に触れるとキャンバスに画像が表示されることですしかし、私は別の箱に再び触れたときに、最初の画像が消えていると、そのボックスとpervoiusの新しいショーはキャンバス上の画像
public class caanvas extends View {
public Canvas canvas1=new Canvas();
public float x_axis,y_axis;
int height,width;
Bitmap mFinalbitmap= BitmapFactory.decodeResource(getResources(), R.drawable.cross);
public float firstcord=0f,secndcord=0f,thirdcord=0f,forthcord=0f,fifthcord=0f,sixcord=0f,sevencord=0f,eightcord=0f;
public float widthborder=0f;
public float h = getContext().getResources().getDisplayMetrics().heightPixels;
public float w = getContext().getResources().getDisplayMetrics().widthPixels;
public caanvas(Context context) {
super(context);
widthborder=w/72f;
firstcord=w/2.88f;
secndcord=w/1.5f;
thirdcord=w/18f;
forthcord=w/1.035f;
fifthcord=h/4.2f;
sixcord=h/2.46f;
sevencord=h/1.63f;
eightcord=h/1.28f;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas1=canvas;
canvas.save();
Paint paint = new Paint();
paint.setColor(Color.LTGRAY);
paint.setStrokeWidth(widthborder);
canvas.drawLine(firstcord, fifthcord, firstcord, eightcord, paint);
canvas.drawLine(secndcord, fifthcord, secndcord, eightcord, paint);
canvas.drawLine(thirdcord, sixcord, forthcord, sixcord, paint);
canvas.drawLine(thirdcord, sevencord, forthcord, sevencord, paint);
if(thirdcord<x_axis&&x_axis<firstcord&&fifthcord<y_axis&&y_axis<sixcord)//For A11 Box
{
width=(int)(firstcord-thirdcord);
height=(int)(sixcord-fifthcord);
Showimage();
}
else if(firstcord<x_axis&&x_axis<secndcord&&fifthcord<y_axis&&y_axis<sixcord)
Showimage2();
//else if(secndcord<x_axis&&x_axis<forthcord&&fifthcord<y_axis&&y_axis<sixcord)
// Showimage();
// else if(thirdcord<x_axis&&x_axis<firstcord&&sixcord<y_axis&&y_axis<sevencord)
// Showimage();
//else if(firstcord<x_axis&&x_axis<secndcord&&sixcord<y_axis&&y_axis<sevencord)
// Showimage();
// else if (secndcord<x_axis&&x_axis<forthcord&&sixcord<y_axis&&y_axis<sevencord)
//Showimage();
//else if (thirdcord<x_axis&&x_axis<firstcord&&sevencord<y_axis&&y_axis<eightcord)
// Showimage();
//else if (firstcord<x_axis&&x_axis<secndcord&&sevencord<y_axis&&y_axis<eightcord)
//Showimage();
// else if(secndcord<x_axis&&x_axis<forthcord&&sevencord<y_axis&&y_axis<eightcord)
// Showimage();
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
x_axis = ev.getX();
y_axis = ev.getY();
Log.i("Tag","Rana asad");
switch (ev.getAction())
{
case MotionEvent.ACTION_DOWN://avc
;
invalidate();
break;
}
return true;
}
public void Showimage()
{
mFinalbitmap = Bitmap.createScaledBitmap(mFinalbitmap, width, height, false);
canvas1.drawBitmap(mFinalbitmap, thirdcord, fifthcord, null);
}
public void Showimage2()
{
mFinalbitmap = Bitmap.createScaledBitmap(mFinalbitmap, width, height, false);
canvas1.drawBitmap(mFinalbitmap, firstcord, fifthcord, null);
}
}