Original Post
Hi everyone
I''ve been studying some code which implements collision detection using boundary rectangles. All it consist of is a ball that bounces around the screen to illustrate some basic sprite properties. Heres some of the code:
// Check the bounds
// Wrap?
if (boundsAction == Sprite.BA_WRAP) {
if ((xPos + width) < xBounds)
xPos = xBounds + wBounds;
else if (xPos > (xBounds + wBounds))
xPos = xBounds - width;
if ((yPos + height) < yBounds)
yPos = yBounds + hBounds;
else if (yPos > (yBounds + hBounds))
yPos = yBounds - height;
}
xPos = x coord of the sprite
yPos = y coord of the sprite
width = the image width
heigth = the image heigth
xBounds, yBounds, hBounds, and wBounds are all boundary variable for the sprite.
This block of code causes the ball to wrap to the other side of the screen if the certain conditions are met. How does this work? For example what exactly does if((xPos + width)< xBounds)
check for?