Control range of movement

TangoDownStudiosTangoDownStudios Member Posts: 46
edited November -1 in Working with GS (Mac)
I have an object that the user can pick up and move with the mouse. When the object is picked up I want to make it so they can only move the object around in a 480x100 sized box located at the top of a landscape iPhone screen.

How do I constrict position.x, position.y to that box? Do I need to use min() max()?

Comments

  • AsymptoteellAsymptoteell Member Posts: 1,362
    Yes. Use min and Max with constraints. If you don't know how, I can explain more.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    do you mean the object starts out in that box and you want to be able to touch it and move it but have it stay it the box?
  • AsymptoteellAsymptoteell Member Posts: 1,362
    Constrain x to min(maximum value, (max(self.position.x, minimum value))

    Y to the same but with self.position.y.
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Asymptoteell hit it right on the head! I didn't know how the syntax for min, max worked. Still don't actually, I'm working this into my code but could someone explain how these methods are laid out?
  • AsymptoteellAsymptoteell Member Posts: 1,362
    Min chooses the smallest of the two values, max picks the largest, so min(1,6) is 1 and max(1,6) is 6.
Sign In or Register to comment.