Display Random Objects In Corona Without Overlapping On The Other Objects On Screen
Solution 1:
You aren't checking if the balls overlap, you are just checking if their centers are at the same position and if so you are shifting them. You need to take into consideration the overall area of the ball (thus its radius). To make this perfect, you would have to use some algebra/geometry (as the radius can be looked at at different angles like a right triangle, where the xPos would be the base length and yPos would be the side height).
Something simple (not perfect) would be like:
while((xPos>=(ballX + ballRadius) || xPos<=(ballX - ballRadius)) ||
(yPos>=(ballY + ballRadius) || yPos<=(ballY - ballRadius))){
xPos = xPos + 150;
yPos = yPos + 150;
}
objplace.x = xPos;
objplace.y = yPos;
Again this is VERY poorly done, there is little on the end of error checking and there are far more parameters that should be taken into account to make things perfect. If you really need me to crunch through it I can, but this would likely be a good project to hone your logical reasoning skills :)
Post a Comment for "Display Random Objects In Corona Without Overlapping On The Other Objects On Screen"