我真的很喜欢动作脚本,而且我正在为我正在上学的项目遇到问题。使我的角色移动的代码(右,左,上,下)都工作正常但后来我在项目开始时添加了一个新的关键帧并创建了一个场景来选择一个角色。我的设置与我老师给我们的设置完全一样,但是现在新的关键帧就在那里,我点击了角色,然后进入游戏,但角色无法移动。任何帮助将非常感谢。
以下是第一个关键帧的代码:
stop ();
mc_fox.visible = false;
import flash.events.Event;
import flash.events.MouseEvent;
btn_fox.addEventListener(MouseEvent.CLICK,btn_foxHandler);
function btn_foxHandler(event:MouseEvent):void
{
gotoAndStop(2);
}
第2帧的代码:
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
mc_fox.stop ();
var move:uint = 0;
stage.addEventListener (KeyboardEvent.KEY_DOWN, keydownHandler);
stage.addEventListener (KeyboardEvent.KEY_UP, keyupHandler);
function keyupHandler (event:KeyboardEvent) :void {
if (event.keyCode == Keyboard.RIGHT){
move = 0
mc_fox.gotoAndStop (1);
}
else if (event.keyCode == Keyboard.LEFT){
move = 0
mc_fox.gotoAndStop (15);
}
else if (event.keyCode == Keyboard.UP){
move = 0
mc_fox.gotoAndStop (30);
}
else if (event.keyCode == Keyboard.DOWN){
move = 0
mc_fox.gotoAndStop (45);
}
}
function keydownHandler (event:KeyboardEvent) :void {
if(event.keyCode == Keyboard.RIGHT && mc_fox.x < 889) {
if (move ==0){
mc_fox.gotoAndPlay (1);
move = 1
}
else {
mc_fox.x = mc_fox.x + 5;
mc_fox.play ();
}
}
else if(event.keyCode == Keyboard.LEFT && mc_fox.x > 111) {
if (move ==0){
mc_fox.gotoAndPlay (15);
move = 1
}
else {mc_fox.x = mc_fox.x - 5;
mc_fox.play ();
}
}
else if (event.keyCode == Keyboard.UP && mc_fox.y > 270) {
if (move ==0){
mc_fox.gotoAndPlay (30);
move = 1
}
else{mc_fox.y = mc_fox.y - 5;
mc_fox.width = mc_fox.width - .9;
mc_fox.height = mc_fox.height - .9;
mc_fox.play();
}
}
else if (event.keyCode == Keyboard.DOWN) {
if (move ==0){
mc_fox.gotoAndPlay (45);
move = 1
}
else{mc_fox.y = mc_fox.y + 5;
mc_fox.width = mc_fox.width + .9;
mc_fox.height = mc_fox.height + .9;
mc_fox.play();
}
}
}