• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

[libgdx] The method overlaps(Rectangle) is undefined for the type Rocket

androgaga

Newbie
Apr 8, 2013
14
0
Hi Guys,

Before, I used to detect collisions between Rectangle objects with the "overlaps" method, it used to work well :
Code:
Iterator<Rectangle> iter = raindrops.iterator();
		
while(iter.hasNext()) {
			
	Rectangle rocket = iter.next();
	rocket.y -= 200 * Gdx.graphics.getDeltaTime();
			
	if(rocket.y + tileH < 0) iter.remove();
			
	if(rocket.overlaps(bucket)) {   <=== HERE IT WORKS FINE
				
		xploseSound.play();
		iter.remove();
				
	}
}

But today I can't use the "overlaps" method anymore, because I moved these objects to a separate new class Rocket.java like this:
Code:
import com.badlogic.gdx.math.Rectangle;
public class Rocket {	
    public Rectangle aabb;
    public int energy;
    public int x;
    public int y;    
    public Rocket() {
        aabb = new Rectangle();
    }
    public Rocket(int x, int y, int w, int h, int energy) {
        this.energy = energy;
        this.x = x;
        this.y = y;
    }
}

Why did I move this from a Rectangle to a separate class ? because I need it in order to have extra parameters for my object. Rectangle only allows "width", "height, "x" and "y", not "energy" or other params.

Now I have to adapt the collision detection code here :
Code:
Iterator<Rocket> iter3 = rockets.iterator();
	      
while(iter3.hasNext()) {
    	  
	Rocket Rocket= iter3.next();
	Rocket.y += rocketSpeed * Gdx.graphics.getDeltaTime();
        if(Rocket.y > 512 ) iter3.remove();

	if(Rocket.overlaps(bucket)) { <=== ERROR --- THIS LINE WON'T COMPILE
	    xploseSound.play();
	    iter3.remove();		
        }

}

But I just have no idea how to proceed...Could someone please help me implementing the "overlaps" method to the Rocket.java class ?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones