Hi,
My problem is that I must remove an object if another touches it. The object to remove is a bloc, and the object that attacks is a ball.
When the ball hit the bloc, I want it to be removed. Thus I crated a function :
The width of my bloc is 100 and the height is 50. I also use two function named contactObjet and destroy :
And destroy
My problem is that if the ball comes from under the bloc orfrom the left, no problem, the bloc is destroyed when the ball hits the LIMIT of the bloc. But from the right or the top, ball must hit the middle of the bloc, and it shouldnt.
I tryied to put another condition like
or something more like
I'm actually running out of idea, even if i'm sure it's shouldn't be so hard to fix^^
Thanks a lot,
Welleid
public void destroyBloc() { int bordBlocX = 50; int bordBlocY = 25; if(contactObjet(Bloc.class, bordBlocX, -bordBlocY)) { destroy(Bloc.class, bordBlocX, -bordBlocY); setRotation(360 - getRotation()); } }
public boolean contactObjet(Class clss, int bordObjetX, int bordObjetY) { Actor actor = getOneObjectAtOffset(bordObjetX, bordObjetY, clss); return actor != null; }
public void destroy(Class clss, int bordObjetX, int bordObjetY) { Actor actor = getOneObjectAtOffset(bordObjetX, bordObjetY, clss); if(actor != null) { getWorld().removeObject(actor); } }
if(contactObjet(Bloc.class, bordBlocX, -bordBlocY) || contactObjet(Bloc.class, - (bordBlocX), -(bordBlocY)) )
if(contactObjet(Bloc.class, bordBlocX, -bordBlocY) ) { destroy(Bloc.class, bordBlocX, -bordBlocY); setRotation(360 - getRotation()); } if(contactObjet(Bloc.class, -bordBlocX, bordBlocY) ) { destroy(Bloc.class, -bordBlocX, bordBlocY); setRotation(360 - getRotation()); }