Groups | Blog | Home
all groups > flash actionscript > november 2004 >

flash actionscript : game area


g5604
11/26/2004 7:53:37 PM
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

kglad
11/26/2004 8:15:34 PM
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.
g5604
11/26/2004 8:20:21 PM
hi,

yep this is.

g5604
11/26/2004 8:20:47 PM
hi,

yep there is.

kglad
11/26/2004 8:32:51 PM
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.
}
}
g5604
11/26/2004 8:36:34 PM
Hi,

many thanks for you help one more question:

so that checks one the car moves over 400px on the x

NSurveyor
11/27/2004 3:03:24 AM
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.
}
}
AddThis Social Bookmark Button