Hi there I have an object that I can move on touch but I need it to only be able to move with in a set area so from :
x 0 to 320 and
y 0 to 200
player.center = [myTouch locationInView:self.view];
any ideas?
this is so that if the user trys to move it out of this area it just hangs on the outer edge.
The code here is actually pretty simple, you just want to detect whether it has exceeded the boundaries, and if it has, the correct it. Assuming
player.centeris something like anNSPoint, the code could be something like:If you want the edges to not pass the sides, then you could just do something like:
And the same for the other x bound and the y bounds.