how to limit constrain?

guillefaceguilleface Member Posts: 1,014
edited April 2012 in Working with GS (Mac)
hi all, right now i have a actor that constrain x and y position to mouse position, but let say i don't want my actor to keep moving when x position is less than 50, this work when my actor reach x=50 so it won't keep moving left but i can't move right either.

Answers

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    edited April 2012


    When touch is pressed
    -constrain self.position.x to max((50+( self.Size.Width /2)), game.Mouse.Position.X )
  • guillefaceguilleface Member Posts: 1,014
    thanks so now is no longer moving left, but how about right? i try adding another rule with max at 100 and didn't work, or another with a min of 100 and don't work either.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    If you want both sides then have this in the constrain

    constrain attribute self.position.x to max((50+( self.Size.Height /2)),min((100-( self.Size.Width /2)), game.Mouse.Position.X ))

    replace the 100 with whatever you want
  • guillefaceguilleface Member Posts: 1,014
    ok is working great now :) , thanks a lot john
Sign In or Register to comment.