|
-
Flash Intermediate
Help with character movement
Some of you may have seen my previous post, but basically I have an arcade machine skin that looks like a ghost is moving it as you play. One button, and one joystick.
Here's my problem:
var _left:Boolean;
var _right:Boolean;
var _up:Boolean;
var _down:Boolean;
var _fire:Boolean;
var shipspeed:Number = 5
function stagecontrol() {
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDownList);
stage.addEventListener(KeyboardEvent.KEY_UP, KeyUpList);
}
function KeyDownList(joyEventGo:KeyboardEvent):void {
if (joyEventGo.keyCode==Keyboard.LEFT) {
joystick.gotoAndStop("left");
_left = true;
}
if (joyEventGo.keyCode==Keyboard.RIGHT) {
joystick.gotoAndStop("right");
_right = true;
}
if (joyEventGo.keyCode==Keyboard.UP) {
joystick.gotoAndStop("up");
_up = true;
}
if (joyEventGo.keyCode==Keyboard.DOWN) {
joystick.gotoAndStop("down");
_down = true;
}
if (joyEventGo.keyCode==Keyboard.SPACE) {
fire_button.gotoAndStop("down");
_fire = true;
}
}
function KeyUpList(joyEventStop:KeyboardEvent):void {
if (joyEventStop.keyCode==Keyboard.LEFT) {
joystick.gotoAndStop("middle");
_left = false;
}
if (joyEventStop.keyCode==Keyboard.RIGHT) {
joystick.gotoAndStop("middle");
_right = false;
}
if (joyEventStop.keyCode==Keyboard.UP) {
joystick.gotoAndStop("middle");
_up = false;
}
if (joyEventStop.keyCode==Keyboard.DOWN) {
joystick.gotoAndStop("middle");
_down = false;
}
if (joyEventStop.keyCode==Keyboard.SPACE) {
fire_button.gotoAndStop("up");
_fire = false;
}
}
function moveLeft() {
if (_left = true) {
spaceship.x -= shipspeed
trace("Moving Left.");
}
}
function moveRight() {
}
function moveUp() {
}
function moveDown() {
}
stagecontrol()
see the part in red txt? It somehow starts as true automatically, and even when I do
var _left:Boolean = false
it still comes out with "Moving Left." in the output window. Event if I havent pushed left! Any help is appreciated, thank you.
In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.
---
Check out my blog at XenElement.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|