-
[Problem]: 8 direction movement not working correctly?
Hey there everyone,
I am currently developing a game with AS 2
I have some code setup like this
PHP Code:
onClipEvent (enterFrame)
{
trace(this.topwall);
if(this._x <= 0){
this.leftwall = true;
}else{
this.leftwall = false;
}
if(this._x > Stage.width - this._width){
this.rightwall = true;
}else{
this.rightwall = false;
}
if(this._y <= 0){
this.topwall = true;
}else{
this.topwall = false;
}
if(this._y > Stage.height - this._height){
this.bottomwall = true;
}else{
this.bottomwall = false;
}
//////////////////////////////////////////////////////////////////////////
if(Key.isDown(Key.LEFT) && Key.isDown(Key.UP)){
if(this.leftwall == "0"){
this._x = this._x - _root.fatspeed;
}
if(this.topwall == "0"){
this._y = this._y - _root.fatspeed;
}
///////////////////////////////////////////////////////////////////////////
}else if(Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)){
this._x = this._x - _root.fatspeed;
this._y = this._y + _root.fatspeed;
}else if(Key.isDown(Key.LEFT)){
this._x = this._x - _root.fatspeed;
}
if(Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)){
this._x = this._x + _root.fatspeed;
this._y = this._y - _root.fatspeed;
}else if(Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)){
this._x = this._x + _root.fatspeed;
this._y = this._y + _root.fatspeed;
}else if(Key.isDown(Key.RIGHT)){
this._x = this._x + _root.fatspeed;
}
if(Key.isDown(Key.UP)){
this._y = this._y - _root.fatspeed;
}else if(Key.isDown(Key.DOWN)){
this._y = this._y + _root.fatspeed;
}
}
If you look at the code between the //////////
this is where the code goes wrong... When holding left and up the character DOES move left and up and DOES stop when it hits the left wall but DOSNT stop when it hits the top.
That is all my code at the moment on the player and I am going in steps no point me continuing to add the statments into my move code if I can't get the first one working...
Anyone have any ideas how to make this more efficient
WITHOUT making hittests to a "wall" type movie clip that needs to be on the stage?
Thanks,
Kriogenic.
-
Senior Member
You are detecting single UP key later that will always move the character:
if(Key.isDown(Key.UP)){
this._y = this._y - _root.fatspeed;
-
Ahhh so stupid of me lol... I SHOULD have gone ahead and continued... It would have fixed... Thanks for your help
-
Senior Member
You shouldn't move things inside the isDown() functions.
Just set right = true or up = true inside them and then move them later with their own function. Now things can get piled up.
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
|