0
我已經從互聯網上下載了該代碼。我需要將.swf文件導入到Director 8.5,因此需要使用帶有ActionScript 2支持的Flash Player 5發佈Flash文件。無法在Flash播放器5中發佈
動畫在測試時運行平穩,但是一旦我嘗試將其發佈到Flash播放器5中時,它會給出一些錯誤,我嘗試了很長時間後仍然無法糾正。
的代碼:
var speed:Number = 0;
var speedMax:Number = 5;
var speedMaxReverse:Number = -2;
var speedAcceleration:Number = .15;
var speedDeceleration:Number = .90;
var groundFriction:Number = .95;
var startingRotation:Number = 180;
var steering:Number = 0;
var steeringMax:Number = 8;
var steeringAcceleration:Number = .10;
var steeringFriction:Number = .98;
var velocityX:Number = 0;
var velocityY:Number = 0;
/**
* Main game loop
*/
function runGame():Void
{
// UP Arrow or W (accelerate)
if (Key.isDown(Key.UP) || Key.isDown(87))
{
//check if below speedMax
if (speed < speedMax){
//speed up
speed += speedAcceleration;
//check if above speedMax
if (speed > speedMax){
//reset to speedMax
speed = speedMax;
}
}
}
// DOWN Arrow or S (reverse)
if (Key.isDown(Key.DOWN) || Key.isDown(83))
{
//check if below speedMaxReverse
if (speed > speedMaxReverse){
//speed up (in reverse)
speed -= speedAcceleration;
//check if above speedMaxReverse
if (speed < speedMaxReverse){
//reset to speedMaxReverse
speed = speedMaxReverse;
}
}
}
// LEFT Arrow or A (turn left)
if (Key.isDown(Key.LEFT) || Key.isDown(65))
{
//turn left
steering -= steeringAcceleration;
//check if above steeringMax
if (steering > steeringMax){
//reset to steeringMax
steering = steeringMax;
}
}
// RIGHT Arrow or D (turn right)
if (Key.isDown(Key.RIGHT) || Key.isDown(68))
{
//turn right
steering += steeringAcceleration;
//check if above steeringMax
if (steering < -steeringMax){
//reset to steeringMax
steering = -steeringMax;
}
}
// SPACE (brake)
if (Key.isDown (Key.SPACE))
{
speed = speed * speedDeceleration;
}
// friction
speed *= groundFriction;
// prevent drift
if(speed > 0 && speed < 0.05)
{
speed = 0
}
// calculate velocity based on speed
velocityX = Math.sin (player_mc._rotation * Math.PI/180) * speed;
velocityY = Math.cos (player_mc._rotation * Math.PI/180) * -speed;
// update position
player_mc._x += velocityX;
player_mc._y += velocityY;
// prevent steering drift (right)
if(steering > 0)
{
// check if steering value is really low, set to 0
if(steering < 0.05)
{
steering = 0;
}
}
// prevent steering drift (left)
else if(steering < 0)
{
// check if steering value is really low, set to 0
if(steering > -0.05)
{
steering = 0;
}
}
// apply steering friction
steering = steering * steeringFriction;
// make car go straight after driver stops turning
steering -= (steering * 0.1);
// rotate
player_mc._rotation += steering * speed;
}
/**
* onEnterFrame function to repeat runGame() over and over
*/
player_mc.onEnterFrame = function()
{
runGame()
}
錯誤
場景=場景1,層= AS,幀= 1:第21行: '{' 預期 功能runGame():空
我覺得語法錯誤,「runGame();」 – Careen