포코팡류 게임을 만들다가 보석배치는 대충됬는데 터치이벤트를 어떻게 해야 할지 감이 안잡히네요;;
밑에는 소스코드입니다.
피드백좀 부탁드리겠습니다
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//setContentView(new ImageView(this));
ImageView mainView =new ImageView(this);
FrameLayout frame=(FrameLayout)findViewById(R.id.mainLayout);
frame.addView(mainView,0);
}
public class ImageView extends View {
private Thread mThread;
// private Bitmap coin01;
int max=7;
int max2=6;
Bitmap[][] imgs=new Bitmap[max][max2];
public ImageView(Context context){
super(context);
// int width=90;
// int height=80;
int random;
OnTouchListener mTouchListener=new OnTouchListener()
{
public boolean onTouch(View v,MotionEvent event)
{
return true;
}
};
Resources r=context.getResources();
// coin01=BitmapFactory.decodeResource(r,R.drawable.coin01);
//coin01=Bitmap.createScaledBitmap(coin01,(int)(coin01.getWidth()/1.5),(int)(coin01.getHeight()/1.5),true);
for(int i=0; i<max; i++)
{
for(int j=0; j<max2; j++) {
random = (int) (Math.random() * 4);
imgs[i][j] = BitmapFactory.decodeResource(r, R.drawable.coin01 + random);
imgs[i][j] = Bitmap.createScaledBitmap(imgs[i][j], (int)(imgs[i][j].getWidth()/2.5), (int)(imgs[i][j].getHeight()/2.5), true);
}
}
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
int x=canvas.getWidth()/2-345;
int y=canvas.getHeight()/2-10;
int dump=canvas.getHeight()/2-5;
for(int j=0; j<max2; j++) {
for(int i=0; i<max; i++) {
y = dump;
if (i % 2 == 1) {
y -= 45;
}
canvas.drawBitmap(imgs[i][j], x, y, null);
x += 96;
}
x=canvas.getWidth()/2-345;
dump+=100;
}
//canvas.drawBitmap(coin01,x,y,null);
}