Hi Guys,
Before, I used to detect collisions between Rectangle objects with the "overlaps" method, it used to work well :
But today I can't use the "overlaps" method anymore, because I moved these objects to a separate new class Rocket.java like this:
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 :
But I just have no idea how to proceed...Could someone please help me implementing the "overlaps" method to the Rocket.java class ?
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 ?