We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I saw this example on constrain()
void draw()
{
background(204);
float mx = constrain(mouseX, 30, 70);
rect(mx-10, 40, 20, 20);
}
And I was trying to use it in my program that has WASD movement, but the experiment was unsuccessful. I was wandering how I would use it to stop my Ball when it hits the edge of the screen. Thank you!
Answers
Your question is a bit unclear. What do you mean with "unsuccessful"? Do you have any code to show and what do you expect?
I'm mainly wandering how I would replace mouseX with WASD movement, sorry or not being clear.
This online example shows constrain() used to keep some Player from exiting the canvas' boundaries: B-)
http://studio.processingtogether.com/sp/pad/export/ro.91tcpPtI9LrXp/latest