1

画面上で異なるビットマップが実行されるゲーム(SurfaceView)を開発しています。速度が異なるため、2 つの文字が重なり合うことがあります。OnTouch 関数を使用して、プレイヤーがキャラクターに触れた瞬間をキャッチしました。ただし、2人のキャラクターが重なっている場合は、常に後ろにある方に「触れ」、前にある方には決して触れません。なんで?この動作を変更するにはどうすればよいですか? 前の方に触ってるから、後ろの方にずっと触ってるのがめんどくさい。問題が明確になることを願っています。

ありがとう!

編集:これは私の OnTouchEvent 関数です:

@Override
public boolean onTouchEvent(MotionEvent event){
    synchronized (getHolder()) {

        boolean chibi_toccato = false;

        if (!blocco_tocco){

// ここに、表示するチビを含む構造体 (ベクター) があります

        for (int i = (mChibiVector.size() - 1); i >= 0; i--) {
            Chibi chibi = mChibiVector.elementAt(i);


        if (event.getAction() == MotionEvent.ACTION_DOWN) {                    

            if (!chibi_toccato){    

// touched は、ちびが以前に触れられたかどうかを示すフラグです

                if (chibi.touched) {

// ボートのビットマップ (画面上のどこか) をタッチすると、チビは安全になります

                    int navexend = posiz_nave_x + thread.mNave.getWidth();
                    int naveyend = posiz_nave_y + thread.mNave.getHeight();
                    if ((int) event.getX() >= posiz_nave_x && 
                            (int) event.getX() <= navexend &&
                            (int) event.getY() >= posiz_nave_y && 
                            (int) event.getY() <= naveyend){
                        chibi.chibisalvo = true;


                        thread.calcola_vel_x(chibi);
                        thread.calcola_vel_y(chibi);
                        } else {
                            chibi.touched = false;

                            int temp_chibi_y = chibi.getCoordinate().getY();

                            chibi.getCoordinate().setY(
                                    temp_chibi_y +
                                    chibi.getBitmapDimensions()[1]);

                        }
                    chibi_toccato = true;
                } else {
                // Here I check if a chibi is touched:  

                    chibi = thread.checkTouched(chibi, (int) event.getX(),
                            (int) event.getY());

                    if (chibi.touched){
// If the chibi is touched, I save the X-Y info:

                        chibi.getCoordinate().setTouchedX((int) event.getX());
                        chibi.getCoordinate().setTouchedY((int) event.getY());


                        int temp_chibi_y = chibi.getCoordinate().getY();

                        chibi.getCoordinate().setY(
                                temp_chibi_y -
                                chibi.getBitmapDimensions()[1]);

                        chibi_toccato = true;
                        }                       
                    } 
                }
            } else if (event.getAction() == MotionEvent.ACTION_UP) {

                if (chibi.touched){

                    chibi_toccato = false;

                int navexend = posiz_nave_x + thread.mNave.getWidth();
                int naveyend = posiz_nave_y + thread.mNave.getHeight();
                if ((int) event.getX() >= posiz_nave_x && 
                        (int) event.getX() <= navexend &&
                        (int) event.getY() >= posiz_nave_y && 
                        (int) event.getY() <= naveyend){
                    chibi.chibisalvo = true;

                    thread.calcola_vel_x(chibi);
                    thread.calcola_vel_y(chibi);
                    } 
                }
            }
        }
        }       
    }       
    return true;
}
4

1 に答える 1

1

さて、しばらくして、ようやく問題が発生しました。問題は for サイクルにありました:

for (int i = (mChibiVector.size() - 1); i >= 0; i--)

ベクターの最後からフレームを選択し始めたので、最初のタッチは常に他のイメージの背後にありました。なぜかまだ疑問に思っていますが、最終的に for サイクルを最初のベクターアイテムから最後に変更したところ、うまくいきました。

他の人に役立つことを願っています。

于 2011-04-12T15:53:19.437 に答える