我已从互联网上下载此代码。我需要将.swf文件导入到Director 8.5,因此需要使用支持ActionScript 2的Flash Player 5发布Flash文件。
动画在测试时运行顺畅但是一旦我尝试在flash player 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行:&#39; {&#39;预期 function runGame():Void
答案 0 :(得分:0)
Flash Player 5是Actionscript 1.它不支持AS2。这意味着没有数据输入。我甚至不确定是否有触发功能。在AS1上很难找到资源,但我记得使用它并使用影片剪辑时间轴结构来实现分支逻辑。祝你好运!