Trouble understanding Fisica's contactStarted()
in
Contributed Library Questions
•
6 months ago
Hi,
I'm making a simple game, not a million miles away from the Remove on Collision example provided with the Fisica library but I'm having trouble setting up detection for different collisions.
Basically, I have a slider at the bottom of the screen (myFBox) and I want it to put the score up when it catches a falling ball (myFCircle), which has gone fine but I also wanted to use another ball (myFCircle2) that, when caught, puts the score down. How do I differentiate between the two types of object that the FBox might collide with?
I tried something like this but it didn't work.
void contactStarted(FContact c){
FBody ball = null;
if((c.getBody1() == myFBox) && (c.getBody2() != myFCircle))
ball = c.getBody2();
}else if((c.getBody2() == myFBox) && (c.getBody1 != myFCircle))
ball = c.getBody1();
}
if(ball == null){
score = score+1;
}
FBody ball2 = null;
if((c.getBody1() == myFBox) && (c.getBody2() != myFCircle2))
ball2 = c.getBody2(); ........etc etc
I've also tried to figure out how to use group indexes to differentiate between the two groups but have no idea about the syntax and can't find any examples outside of the fisica reference... which I don't understand.
void contactStarted(FContact c) {
FBody ball = null;
if((c.getBody1() == myFBox) && (getGroupIndex(c.getBody2()) == -3)){
ball = c.getBody2();
}else if ((c.getBody2() == myFBox) && (getGroupIndex(c.getBody1()) == -3)){
ball = c.getBody1();
}
if(ball == null){
score = score+1;
}
So, that doesn't work either (won't compile at all) - any suggestions / suggested reading to figure this out would be much appreciated, thanks!
1