演示:
http://www.evzg.com/lab/race/
汽车在加速后转弯时车轮转动不正常,朋友帮忙想个解决办法~!
下面是汽车零部件的类文件.
油门(powerController.as):
package myclass.cars.parts
{
import flash.display.Sprite;
import flash.events.Event;
import myclass.cars.car0;
public class powerController extends Sprite
{
private var car:car0;
private var speed:Number = 0;
private var maxSpeed:Number = 100;
private var stat:String = "release";
public function powerController(targetCar:car0)
{
car = targetCar;
init();
}
private function init():void
{
this.addEventListener(Event.ENTER_FRAME,EnterFrame);
}
private function EnterFrame(e:Event):void
{
car.carModel.getChildByName("wheel4").rotationY-=speed;
car.carModel.getChildByName("wheel3").rotationY-=speed;
car.carModel.getChildByName("wheel2").rotationY-=speed*0.85;
car.carModel.getChildByName("wheel1").rotationY-=speed*0.85;
//car.carModel.getChildByName("wheel1").rotationZ=car.carModel.getChildByName("wheel2").rotationZ=
if(stat=="release"){
if(speed>0){
speed-=2;
}
if(speed<0){
speed+=2;
}
}
}
public function powerUp():void
{
if(speed<=maxSpeed-2){
speed+=2;
}
stat="up";
}
public function powerDown():void
{
if(speed>=-maxSpeed+2){
speed-=2;
}
stat="down";
}
public function powerRelease():void
{
stat="release";
}
}
}
方向盘(actionController.as):
package myclass.cars.parts
{
import myclass.cars.car0;
public class actionController
{
private var car:car0;
private var dg:Number=0;
public function actionController(targetCar:car0)
{
car = targetCar;
}
public function turnLeft():void
{
if(dg<45){
dg+=2;
car.carModel.getChildByName("wheel1").rotationX+=2;
car.carModel.getChildByName("wheel2").rotationX+=2;
}
}
public function turnRight():void
{
if(dg>-45){
dg-=2;
car.carModel.getChildByName("wheel1").rotationX-=2;
car.carModel.getChildByName("wheel2").rotationX-=2;
}
}
}
}