Edge Detection on Screen
Posted
by
user2056745
on Game Development
See other posts from Game Development
or by user2056745
Published on 2013-07-03T08:41:40Z
Indexed on
2013/07/03
11:19 UTC
Read the original article
Hit count: 473
I have a edge collision problem with a simple game that i am developing. Its about throwing a coin across the screen. I am using the code below to detect edge collisions so i can make the coin bounce from the edges of the screen.
Everything works as i want except one case. When the coin hits left edge and goes to right edge the system doesnt detect the collision. The rest cases are working perfectly, like hitting the right edge first and then the left edge.
Can someone suggest a solution for it?
public void onMove(float dx, float dy) {
coinX += dx;
coinY += dy;
if (coinX > rightBorder) {
coinX = ((rightBorder - coinX) / 3) + rightBorder;
}
if (coinX < leftBorder) {
coinX = -(coinX) / 3;
}
if (coinY > bottomBorder) {
coinY = ((bottomBorder - coinY) / 3) + bottomBorder;
}
invalidate();
}
© Game Development or respective owner