Hi, does anyone know how to define an area for which a object is constrained to? e.g a car can only move within a 400x400px box cheers, G
is there code that directs the car to move? if so, during every execution of code that moves the car, the car's position can be checked to see it's within your constaints and if not to take appropriate action.
yes, you would use an if-statement. for example: on(press){ car._x += 3; if(car._x>400){ // checks to see if car is about to be moved past constraint car._x=400; if so, car is restrained. } }
Hi, many thanks for you help one more question: so that checks one the car moves over 400px on the x
This button moves the car right. So, it only needs to constrain one side. But, here are the three other examples to make a complete set ;): //LEFT BUTTON on(press){ car._x -= 3; if(car._x<0){ // checks to see if car is about to be moved past constraint car._x=0; // if so, car is restrained. } } //UP BUTTON on(press){ car._y -= 3; if(car._y<0){ // checks to see if car is about to be moved past constraint car._y=0; // if so, car is restrained. } } //DOWN BUTTON on(press){ car._y += 3; if(car._y>400){ // checks to see if car is about to be moved past constraint car._y=400; // if so, car is restrained. } }
Don't see what you're looking for? Try a search.
|