Skip to main content
removed blacklisted tag
Source Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54

I had been hard coding a collision detection system which was buggy. Then I came across using rectangles for collsioncollision detection. So I put it all in and it does not work, I put a log in and it never logged.

Note to Java programmers who are not Android programers: Android uses the word Rect instead of Rectangle.

Code for Block.java:

public Rect getBounds(){
    return new Rect (this.x, this.y, 10, 20);
}

Code for Sprite.java:

public Rect getBounds(){
    return new Rect (this.x, this.y, 20, 20);
}

Code for MainGame.java:

for(Block block : BLOCKS) {
    block.draw(canvas);
    block.rigidbody();
            
    Rect spriter = sprite.getBounds();
    Rect blockr = block.getBounds();
            
    if(spriter.intersect(blockr)){
        showgameover = 1;
        Log.d(TAG, "Game Over");
    }
        
}

Is anyone able to help?

I had been hard coding a collision detection system which was buggy. Then I came across using rectangles for collsion detection. So I put it all in and it does not work, I put a log in and it never logged.

Note to Java programmers who are not Android programers: Android uses the word Rect instead of Rectangle.

Code for Block.java:

public Rect getBounds(){
    return new Rect (this.x, this.y, 10, 20);
}

Code for Sprite.java:

public Rect getBounds(){
    return new Rect (this.x, this.y, 20, 20);
}

Code for MainGame.java:

for(Block block : BLOCKS) {
    block.draw(canvas);
    block.rigidbody();
            
    Rect spriter = sprite.getBounds();
    Rect blockr = block.getBounds();
            
    if(spriter.intersect(blockr)){
        showgameover = 1;
        Log.d(TAG, "Game Over");
    }
        
}

Is anyone able to help?

I had been hard coding a collision detection system which was buggy. Then I came across using rectangles for collision detection. So I put it all in and it does not work, I put a log in and it never logged.

Note to Java programmers who are not Android programers: Android uses the word Rect instead of Rectangle.

Code for Block.java:

public Rect getBounds(){
    return new Rect (this.x, this.y, 10, 20);
}

Code for Sprite.java:

public Rect getBounds(){
    return new Rect (this.x, this.y, 20, 20);
}

Code for MainGame.java:

for(Block block : BLOCKS) {
    block.draw(canvas);
    block.rigidbody();
            
    Rect spriter = sprite.getBounds();
    Rect blockr = block.getBounds();
            
    if(spriter.intersect(blockr)){
        showgameover = 1;
        Log.d(TAG, "Game Over");
    }
        
}

Is anyone able to help?

added 59 characters in body; edited tags; edited title
Source Link
House
  • 73.5k
  • 17
  • 188
  • 276

Android Java Rectangle Collision Detectionrectangle collision detection not Workingworking

i haveI had been harcodinghard coding a collision detection system which was buggy then i. Then I came accrossacross using Rectangles asrectangles for collsion detection. So iI put it all in and it does not work, I put a Loglog in and it never logged.

Note to Java programmers who are not androidAndroid programers: android UsesAndroid uses the word RectRect instead of RectangleRectangle.

Code for Block.java:

    public Rect getBounds(){
    return new Rect (this.x, this.y, 10, 20);
}

Code for Sprite.java:

    public Rect getBounds(){
    return new Rect (this.x, this.y, 20, 20);
}

Code for MainGame.java: for(Block block : BLOCKS) {

    for(Block block : BLOCKS) {
    block.draw(canvas);
            block.rigidbody();
            
            Rect spriter = sprite.getBounds();
            Rect blockr = block.getBounds();
            
            if(spriter.intersect(blockr)){
                showgameover = 1;
                Log.d(TAG, "Game Over");
            }
        
        }

Is anyone able to help?

Android Java Rectangle Collision Detection not Working

i have been harcoding a collision detection system which was buggy then i came accross using Rectangles as collsion detection. So i put it all in and it does not work, I put a Log in and it never logged.

Note to Java programmers who are not android programers: android Uses the word Rect instead of Rectangle.

Code for Block.java:

    public Rect getBounds(){
    return new Rect (this.x, this.y, 10, 20);
}

Code for Sprite.java:

    public Rect getBounds(){
    return new Rect (this.x, this.y, 20, 20);
}

Code for MainGame.java: for(Block block : BLOCKS) {

            block.draw(canvas);
            block.rigidbody();
            
            Rect spriter = sprite.getBounds();
            Rect blockr = block.getBounds();
            
            if(spriter.intersect(blockr)){
                showgameover = 1;
                Log.d(TAG, "Game Over");
            }
        
        }

Is anyone able to help?

Android Java rectangle collision detection not working

I had been hard coding a collision detection system which was buggy. Then I came across using rectangles for collsion detection. So I put it all in and it does not work, I put a log in and it never logged.

Note to Java programmers who are not Android programers: Android uses the word Rect instead of Rectangle.

Code for Block.java:

public Rect getBounds(){
    return new Rect (this.x, this.y, 10, 20);
}

Code for Sprite.java:

public Rect getBounds(){
    return new Rect (this.x, this.y, 20, 20);
}

Code for MainGame.java:

for(Block block : BLOCKS) {
    block.draw(canvas);
    block.rigidbody();
            
    Rect spriter = sprite.getBounds();
    Rect blockr = block.getBounds();
            
    if(spriter.intersect(blockr)){
        showgameover = 1;
        Log.d(TAG, "Game Over");
    }
        
}

Is anyone able to help?

Source Link

Android Java Rectangle Collision Detection not Working

i have been harcoding a collision detection system which was buggy then i came accross using Rectangles as collsion detection. So i put it all in and it does not work, I put a Log in and it never logged.

Note to Java programmers who are not android programers: android Uses the word Rect instead of Rectangle.

Code for Block.java:

    public Rect getBounds(){
    return new Rect (this.x, this.y, 10, 20);
}

Code for Sprite.java:

    public Rect getBounds(){
    return new Rect (this.x, this.y, 20, 20);
}

Code for MainGame.java: for(Block block : BLOCKS) {

            block.draw(canvas);
            block.rigidbody();
            
            Rect spriter = sprite.getBounds();
            Rect blockr = block.getBounds();
            
            if(spriter.intersect(blockr)){
                showgameover = 1;
                Log.d(TAG, "Game Over");
            }
        
        }

Is anyone able to help?