|
-
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
-
you're using the assignment ( = ) instead of the comparison ( == ) operator. Try:
PHP Code:
if(_left == true)
or better yet
-
Flash Intermediate
Hmmm. It stopped spamming the "Moving Left." thing in the output window, but now it is doing nothing.
as you can see I didnt do an add child or anything, the ship just started on the stage. Could that cause some sort of problem?
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
-
Flash Intermediate
AHA! I figured it out! It turns out that you were correct, I needed if (_left). but also, I wasn't calling the function anywhere. so there you have it. Pure stupidity.
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
-
We're all human :P Sometimes the code you wrote in your head isn't the same as the code your fingers wrote and its hard to see your own mistakes
-
Flash Intermediate
 Originally Posted by redjag
We're all human :P Sometimes the code you wrote in your head isn't the same as the code your fingers wrote and its hard to see your own mistakes 
Oh, it's so true!
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
|