不幸的是,我不是一个程序员,只是一个艺术家,但我必须做一个小游戏示例作为我的大学作业。
所以,我为我的名为Hero的movieclip做了一个课程,我在Hero.as中制作了控制系统(来自教程)。它运作良好,但英雄正在旋转,因为我还没有设置它。这是Hero.as的一部分:
package AS {
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.events.Event;
public class Hero extends MovieClip {
private var moveUp: Boolean;
private var moveLeft: Boolean;
private var moveDown: Boolean;
private var moveRight: Boolean;
private var moveSpeed: uint;
public function Hero() {
init();
}
protected function init() {
moveUp = false;
moveLeft = false;
moveDown = false;
moveRight = false;
moveSpeed = 5;
Constants.stageRef.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedListener);
Constants.stageRef.addEventListener(KeyboardEvent.KEY_UP, keyReleasedListener);
Constants.stageRef.addEventListener(Event.ENTER_FRAME, frameListener);
}
//when you press down a key
private function keyPressedListener(e: KeyboardEvent) {
var key: uint = e.keyCode;
if (key == 87 || key == 38) { //go to up with W or UP
moveUp = true;
} else if (key == 65 || key == 37) { //go to left with A or LEFT
moveLeft = true;
} else if (key == 83 || key == 40) { //go to down with S or DOWN
moveDown = true;
} else if (key == 68 || key == 39) { //go to right with D or RIGHT
moveRight = true;
}
}
//Blablabla
Game.fla中的this is how the Hero movieclip looks like。问题是我不知道如何在Hero.as中使用gotoAndStop()。首先,我必须阻止英雄的旋转 - gotoAndStop(“StandFront”) - 然后我必须在每个部分(在keyPressedListener中)设置英雄应该走的正确方向。 这就是我用错误的代码思考它的方式,也许是在错误的地方:
protected function init() {
gotoAndStop("StandFront"); //------------Stop the character's spinning
moveUp = false;
moveLeft = false;
moveDown = false;
moveRight = false;
moveSpeed = 5;
//Blablabla...
//when you press down a key
private function keyPressedListener(e: KeyboardEvent) {
var key: uint = e.keyCode;
if (key == 87 || key == 38) { //go to up with W or UP
moveUp = true;
gotoAndStop("WalkFront"); //--------------- Play the animation where the
//character's moving up while the player's
//pressing the key W or UP.
}
//Blablablabla...
我不认为它是否有用,但这里是Main.as我作为一个类附加到Game.fla文档:
package AS {
import flash.display.MovieClip;
public class Main extends MovieClip {
private var hero:Hero;
public function Main() {
init();
}
public function init(){
Constants.stageRef=stage;
hero=new Hero();
hero.x=300; //512;
hero.y=300; //418.9;
stage.addChild(hero);
}
}
}
非常感谢您的帮助!