Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 objects on the screen:


enter image description here


enter image description here

non-static object moves randomly over the screen.

How do I know that non-static Object cross the "+" (static).

Both objects I draw by using followed code:

private void updateScreenData(float screenWidth, float screenHeight){
    // takes screen Height and Width
    this.mScreenWidth = (screenWidth > 0) ? screenWidth : 1f;
    this.mScreenHeight = screenHeight;
    wRatio = 10f/mScreenWidth;
    hRatio = mScreenHeight/10f;     

protected void drawTarget(GL10 gl){
    try {           
        float transx =  shiftX + (wRatio * (x)); 
        float transy =  shiftY +(mScreenHeight*wRatio) - (wRatio * (y)) - 1/hRatio; 

        gl.glTranslatef(transx, transy, 0.0f);

        //###########  draw ##############

        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, floatBufferArray[mFrame]);


        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);


    } catch (NullPointerException e) {

public void loadTextures(GL10 gl) {
    Log.e(LOG_TAG, "loadTextures");  

    InputStream is;

    is = mContext.getResources().openRawResource(_SRC);

    Bitmap bitmap = BitmapFactory.decodeStream(is);

    try {
        is = null;
    } catch (IOException e) {

    gl.glGenTextures(TEXTURE_COUNT, textures, 0);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);



Any ideas?

What do I need to compare in both Objects?


I see my question is not so clear, so i'll try once more.

Since my cross image stays at the middle of screen (screenWidth/2 and screenWidth/2) I know the coordinates, it do not change. But second Object changes.

How can I fetch out coordinates (aka x,y) from dynamic object?

share|improve this question
You need to compare their positions. – Byte56 Jul 27 '13 at 14:00
What @Byte56 said, this has nothing to do with OpenGL ES, that's only there for drawing. Things like collision or intersection detection has nothing to do with it, so I don't see any relation from the code you posted to the problem you're trying to solve. – PeterT Jul 27 '13 at 14:02

One of the simplest and fastest ways is to compare the bounding boxes of the two, and see if they intersect/overlap. This is usually fairly trivial.

In your case, it seems like you have a "hit zone" in the middle of your crosshairs. I would alternatively check if the bounding box of that inner area overlaps the skulls, and if it does, that's a valid hit.

You can see this question's answers for some ways to calculate overlap/intersection..

share|improve this answer
Well, i know how to do that in canvas/bitmap. This logic worked for me, but when i moved to OpenGL ES, all stuff changed. My question is how can I extract current position from Object? – Maxim Shoustin Jul 27 '13 at 15:01
@MaximShoustin you yourself passed the position to OpenGL, so you should know where the Object is. You may have some differences like (0,0) being in the center for OpenGL and in the top-left corner for most software-based solutions. But it's not that difficult to subtract (width/2.0,height/2.0) – PeterT Jul 27 '13 at 15:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.