thejoeknows.com
June 26th, 2008, 02:56 PM
Could anyone give me some tips to do the port/conversion?
this is a simple as2 file which moves a car (rotates wheels, gas, etc.)
the 2 movieclips being used are car and wheel
//www.swfspot.com
//movement speed of the car
var speed=2;
//Compute pi/180. The value is used twice for each frame, so storing it as a variable saves CPU
var piOver180=Math.PI/180;
onEnterFrame=function(){
//If the left or right keys are down, rotate the wheels
if(Key.isDown(Key.LEFT)){
car.leftwheel._rotation=Math.min(24,Math.max(-24,car.leftwheel._rotation-5));
car.rightwheel._rotation=Math.min(24,Math.max(-24,car.rightwheel._rotation-5));
}
if(Key.isDown(Key.RIGHT)){
car.leftwheel._rotation=Math.min(24,Math.max(-24,car.leftwheel._rotation+4));
car.rightwheel._rotation=Math.min(24,Math.max(-24,car.rightwheel._rotation+4));
}
//check if the up or down keys are pressed
if(Key.isDown(Key.UP)||Key.isDown(Key.DOWN)){
//if the up key is down, the car moves forward
if(Key.isDown(Key.UP)){
carDirection=1;
//otherwise move the car backwards
}else{carDirection=-1;}
//default turning to false
turning=0;
//if the left or right keys are pressed, set turning to true and rotate the car
if(Key.isDown(Key.LEFT)){
turning=1;
car._rotation-=5*carDirection;
}
else if(Key.isDown(Key.RIGHT)){
turning=1;
car._rotation+=5*carDirection;
}
//if the car isn't turning, reset the rotation of the tires
if(!turning){
car.leftwheel._rotation=0;
car.rightwheel._rotation=0;
}
//move the car. The y coordinate plane is flipped in flash, so we use - instead of +
car._x+=Math.sin(car._rotation*piOver180)*speed*ca rDirection;
car._y-=Math.cos(car._rotation*piOver180)*(speed)*carDire ction;
}
}
how does rotation work in as3?
can math.pi still be used?
thank you
-joey
this is a simple as2 file which moves a car (rotates wheels, gas, etc.)
the 2 movieclips being used are car and wheel
//www.swfspot.com
//movement speed of the car
var speed=2;
//Compute pi/180. The value is used twice for each frame, so storing it as a variable saves CPU
var piOver180=Math.PI/180;
onEnterFrame=function(){
//If the left or right keys are down, rotate the wheels
if(Key.isDown(Key.LEFT)){
car.leftwheel._rotation=Math.min(24,Math.max(-24,car.leftwheel._rotation-5));
car.rightwheel._rotation=Math.min(24,Math.max(-24,car.rightwheel._rotation-5));
}
if(Key.isDown(Key.RIGHT)){
car.leftwheel._rotation=Math.min(24,Math.max(-24,car.leftwheel._rotation+4));
car.rightwheel._rotation=Math.min(24,Math.max(-24,car.rightwheel._rotation+4));
}
//check if the up or down keys are pressed
if(Key.isDown(Key.UP)||Key.isDown(Key.DOWN)){
//if the up key is down, the car moves forward
if(Key.isDown(Key.UP)){
carDirection=1;
//otherwise move the car backwards
}else{carDirection=-1;}
//default turning to false
turning=0;
//if the left or right keys are pressed, set turning to true and rotate the car
if(Key.isDown(Key.LEFT)){
turning=1;
car._rotation-=5*carDirection;
}
else if(Key.isDown(Key.RIGHT)){
turning=1;
car._rotation+=5*carDirection;
}
//if the car isn't turning, reset the rotation of the tires
if(!turning){
car.leftwheel._rotation=0;
car.rightwheel._rotation=0;
}
//move the car. The y coordinate plane is flipped in flash, so we use - instead of +
car._x+=Math.sin(car._rotation*piOver180)*speed*ca rDirection;
car._y-=Math.cos(car._rotation*piOver180)*(speed)*carDire ction;
}
}
how does rotation work in as3?
can math.pi still be used?
thank you
-joey