배경으로 다른보기의 생성자 안에 bmp와 함께 약간의 스프라이트를 만들고 있습니다. 그러나 스프라이트를 클릭하면 onClickListener가 있는데, 클릭하는 뷰가 백그라운드 뷰입니다.onClick hierachy
일부 코드 :
내 생성자 :
public ToposGameView(Context context) {
super(context);
moles = new ArrayList<MoleSprite>();
setFocusable(true);
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(tag, "Click en GameView");
}
});
gameLoopThread = new GameLoopThread(this);
int id = 0;
for(int x = 0; x<3; x++){
for(int y = 0; y<4 ; y++){
MoleSprite mole = new MoleSprite(this, x*WIDTH/3, HEIGHT/6+y*HEIGHT/6, FRONT);
mole.setId(id);
id++;
moles.add(mole);
}
}
holder = getHolder();
holder.addCallback(new Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
boolean retry=true;
gameLoopThread.setRunning(false);
while(retry){
try{
gameLoopThread.join();
retry=false;
}catch(InterruptedException i){
}
}
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
gameLoopThread.setRunning(true);
gameLoopThread.start();
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
}
Sprite의 생성자 :
public MoleSprite(ToposGameView gameView, int x, int y, int direction) {
super(gameView.getContext()); //TODO
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bad1);
this.width = bmp.getWidth()/BMP_COLUMNS;
this.height = bmp.getHeight()/BMP_ROWS;
this.x=x;
this.y= y;
this.setClickable(true);
this.setFocusable(true);
this.setFocusableInTouchMode(true);
setOnClickListener(this);
setOnTouchListener(this);
//I don't know what else to do!
}
그것은 내 첫 번째 질문은 더 많은 정보를 원하시면 저에게 문의하시기 바랍니다.
EDIT1가 :
public class MoleSprite extends View implements OnClickListener, OnTouchListener{
public class ToposGameView extends SurfaceView{
MoleSprite의 기본 클래스는 무엇입니까? onClick에 대해 묻고 있는데, 이는 일반적으로 View 계층 구조를 가리 킵니다.하지만 뷰 계층 구조 외부의 렌더링을 나타내는 SurfaceViews를 사용하고 있습니다. 여기에는 몇 가지 연결이 끊어져 있지만 식별 하기엔 너무 적은 정보가 있습니다. – Anm
아이디어는 다시 그리기가 필요한 게임을 수행하는 것이지만 onClick으로 막혔습니다. 기본 클래스로 편집합니다. – Rafaesp