A Flash Developer Resource Site

+ Reply to Thread
Results 1 to 7 of 7

Thread: left and right

  1. #1
    Junior Member
    Join Date
    Sep 2006
    Posts
    7

    left and right

    i am making a game where the main charecter is in the middle of the screen and when he moves left or right the animation of him moving plays and the ground moves in the opposite direction


    but when you release one of the keys the animation of the charecter moving in that direction continues

    http://img295.imageshack.us/my.php?i...stratortb3.swf


    that is the game and i used this code to make it play an animation:

    onClipEvent(enterFrame){
    if(Key.isDown(Key.RIGHT)){
    gotoAndStop("right");

    }
    if(Key.isDown(Key.LEFT)){
    gotoAndStop("left");

    }
    }

    does anyone know a way of stopping this from happening

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,668
    if(!Key.isDown()){
    gotoAndStop("stopped");
    }
    this checks to see if no key is down the problem with this is you could have issues with the space bar.
    .

  3. #3
    Junior Member
    Join Date
    Sep 2006
    Posts
    7
    didn't work, just made the legs not move or the body turn round

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,668
    "stopped" needs to be the frame in which you want it to go to.
    .

  5. #5
    Junior Member
    Join Date
    Sep 2006
    Posts
    7
    did that

    it didn't work

    it worked with the flame

    but not the legs moving left and right

  6. #6
    Senior Member Orkahm52's Avatar
    Join Date
    Jan 2006
    Location
    Perth, Australia
    Posts
    335
    Code:
    onClipEvent(enterFrame){
    if(Key.isDown(Key.RIGHT)){
    gotoAndStop("right");
    
    } else if (Key.isDown(Key.LEFT)){
    gotoAndStop("left");
    } else {
    gotoAndStop("stopped");
    }
    That checks if right is down, then if left is down, and if neither is down, it goes to stopped.
    Last edited by Orkahm52; 10-15-2006 at 08:49 AM.

  7. #7
    Truimagz.com everfornever's Avatar
    Join Date
    Sep 2006
    Location
    St. Louis
    Posts
    1,306
    this is some code for attacking, moving and moving a game map, it's a zelda type engine.

    May come in handy through your moving and attacking troubles. I had a difficult time figuring out mine my first time as well.

    I will post this code here as a reference for you to look at while you work on your game. If you need any other code examples like this let me know and I will remove this one and put up the new one.

    I use this code to scroll the game in a zelda type way so I dont have to tile base and can have a more detailed game without worrying about TONS and TONS of lag while the screen moves.

    Code:
    //attack vars
    slice = false;
    stab = false;
    attack = false;
    //attack conditions
    function stabMethod() {
    	stab = attack=true;
    	game.player.gotoAndStop(4);
    }
    function sliceMethod() {
    	slice = attack=true;
    	game.player.gotoAndStop(3);
    }
    function ruptureMethod() {
                 rupture = attack=true;
    	game.player.gotoAndStop(6);
    	
    }
    function exMethod() {
    	ex = attack=true;
    	game.player.gotoAndStop(5);
    	
    }
    //attack timer
    at = 0;
    //player move speed
    speed = 17;
    //game map scroll
    gscr = 0;
    scrollgame = false;
    //game map wall border
    topwall = false;
    bottomwall = false;
    rightwall = false;
    leftwall = false;
    onEnterFrame = function (){
    if (!scrollgame) {
    		if (Key.isDown(Key.UP)) {
    			game.player._y -= speed;
    			game.player._rotation = 0;
    			if (!attack) {
    				game.player.gotoAndStop(2);
    			}
    			if (Key.isDown(Key.LEFT)) {
    				game.player._rotation = 315;
    				game.player._y += 4.25;
    				game.player._x -= 12.75;
    			}
    			if (Key.isDown(Key.RIGHT)) {
    				game.player._rotation = 45;
    				game.player._y += 4.25;
    				game.player._x += 12.75;
    			}
    		} else if (Key.isDown(Key.DOWN)) {
    			game.player._y += speed;
    			game.player._rotation = 180;
    			if (!attack) {
    				game.player.gotoAndStop(2);
    			}
    			if (Key.isDown(Key.LEFT)) {
    				game.player._rotation = 225;
    				game.player._y -= 4.25;
    				game.player._x -= 12.75;
    			}
    			if (Key.isDown(Key.RIGHT)) {
    				game.player._rotation = 135;
    				game.player._y -= 4.25;
    				game.player._x += 12.75;
    			}
    		} else if (Key.isDown(Key.LEFT)) {
    			game.player._x -= speed;
    			game.player._rotation = 270;
    			if (!attack) {
    				game.player.gotoAndStop(2);
    			}
    		} else if (Key.isDown(Key.RIGHT)) {
    			game.player._x += speed;
    			game.player._rotation = 90;
    			if (!attack) {
    				game.player.gotoAndStop(2);
    			}
    		} else {
    			if (!attack) {
    				game.player.gotoAndStop(1);
    			}
    		}
    		//player attacking     
    		if (!attack) {
    			buttons.stab_btn.onPress = stabMethod;
    			buttons.slice_btn.onPress = sliceMethod;
    			buttons.rupture_btn.onPress = ruptureMethod;
    			buttons.execute_btn.onPress = exMethod;
    		}
    	}
    	//attack timers                                                                                                                                                         
    	if (stab) {
    		at++;
    		if (at>6) {
    			at = 0;
    			stab = attack=false;
    			if (shadowgoo) {
    				shad++;
    			}
    		}
    	}
    	if (slice) {
    		at++;
    		if (at>13) {
    			at = 0;
    			slice = attack=false;
    			if (shadowgoo) {
    				shad++;
    			}
    		}
    	}
    	if (rupture) {
    		at++;
    		if (at>10) {
    			at = 0;
    			rupture = attack=false;
    			if (shadowgoo) {
    				shad++;
    			}
    		}
    	}
    	if (ex) {
    		at++;
    		if (at>11) {
    			at = 0;
    			ex = attack=false;
    			if (shadowgoo) {
    				shad++;
    			}
    		}
    	}
    	//stop player from leaving the map                                                                                                                                        
    	if (game.player.hitTest(game.floor.top_wall)) {
    		game.player._y += speed;
    	}
    	if (game.player.hitTest(game.floor.bottom_wall)) {
    		game.player._y -= speed;
    	}
    	if (game.player.hitTest(game.floor.left_wall)) {
    		game.player._x += speed;
    	}
    	if (game.player.hitTest(game.floor.right_wall)) {
    		game.player._x -= speed;
    	}
    	//moving game                                                                                                                                           
    	//top wall
    	if (!scrollgame) {
    		if (game.player.hitTest(top_wall)) {
    			scrollgame = topwall=true;
    		}
    	}
    	if (topwall) {
    		gscr += 40;
    		game._y += 40;
    		if (gscr>539) {
    			gscr = 0;
    			scrollgame = topwall=false;
    		}
    	}
    	//bottom wall                                                                                                                                          
    	if (!scrollgame) {
    		if (game.player.hitTest(bottom_wall)) {
    			scrollgame = bottomwall=true;
    		}
    	}
    	if (bottomwall) {
    		gscr += 40;
    		game._y -= 40;
    		if (gscr>539) {
    			gscr = 0;
    			scrollgame = bottomwall=false;
    		}
    	}
    	//right wall                                                                                                                                       
    	if (!scrollgame) {
    		if (game.player.hitTest(right_wall)) {
    			scrollgame = rightwall=true;
    		}
    	}
    	if (rightwall) {
    		gscr += 40;
    		game._x -= 40;
    		if (gscr>879) {
    			gscr = 0;
    			scrollgame = rightwall=false;
    		}
    	}
    	//left wall                                                                                                                                       
    	if (!scrollgame) {
    		if (game.player.hitTest(left_wall)) {
    			scrollgame = leftwall=true;
    		}
    	}
    	if (leftwall) {
    		gscr += 40;
    		game._x += 40;
    		if (gscr>879) {
    			gscr = 0;
    			scrollgame = leftwall=false;
    		}
    	}
    };
    Last edited by everfornever; 10-16-2006 at 12:45 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts




Click Here to Expand Forum to Full Width


HTML5 Development Center