Search code examples
actionscript-3actionscript

How to set a max/limit on how much a movieclip can be moved by x and y?


I'm making a Create-a-Character.One of the features is being able to adjust a facial feature’s placement.E.g. can move the nose up or down (Through arrow buttons, example: 1 click on up button, move nose up by a little bit.)

But obviously I don't want the eyes or nose or lips floating outside the face or a nose ending up on a forehead that would be strange lol.

So how do I code so that the user can only move a movieclip a set amount of times in the chosen direction?


Solution

  • If you use just arrow buttons to move objects, it is very easy. Once a button is clicked, check object's position and move it if needed. Basic example:

    // if arrow up clicked
    if (nose.y > 100)
    {nose.y -= 2}
    
    // if down arrow clicked
    if (nose.y < 140)
    {nose.y += 2}
    

    It's same for x axis and obviously, numbers 100 and 140 can be anything you want. It means, move objects just between these points.