A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Platform & Key Pressing Help

  1. #1
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217

    Platform & Key Pressing Help

    Hey, Ive run into a bit of a problem with my platforming games. Im using a while loop embedded in the platforms frame to determine whether or not my player is touching the platform, and if so stop him from falling through. Heres the codes I used in moderation:

    Code:
    //Code for 'player1'
    onClipEvent(load) {
      gravity = 1;
    }
    onClipEvent(enterFrame) {
      _y += gravity;
      gravity++;
      //...code for jumping etc
    }
    Code:
    //Code for ground
    onEnterFrame = function() {
      while(hitTest(_root.player1)) {
        _root.player1._y--;
        _root.player1.gravity = 0;
      }
    };


    Basically my aim is to allow my characters to jump up through the platforms from below but the platform should only prevent the player from falling through on his/her way down. Can anyone provide an example using my type of method?


    Also is there a way to test if a key has been tapped twice using Key.isDown()?

    Thanks for any help you can give.

  2. #2
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,471
    Platformer Tutorial
    there are all the aspects needed to make a basic platformer in there. If you make the player jump the way suggested:
    Code:
    if (player.hits>0) {
    		if (Key.isDown(Key.UP)) {
    			player.gravity = -10;
    		} else {
    			player.gravity = 0;
    		}
    	} else {
    		player.gravity++;
    	}
    then you can stop snapping by adding this:

    Code:
    if (player.hitTest(_root['ground'+i]) && player.gravity>=0) {
    The tutorial fully explains how to make platforms, just navigate to the right sections.
    "I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."

  3. #3
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    Thankyou for that but I'd really like to keep my current method due to how far I am with my game. I can do platforming games well its just I cant find a solid method to achieve this effect and its annoying me.

    Any other offers?

  4. #4
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,471
    If when you jump you set the gravity to a negative number (you still haven't replied with your method) you can just add:
    && gravity > 0){
    to the end of your hitTest.
    "I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."

  5. #5
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    Ive tried that method before and yes, it does work - however if you refer to the flash file I have included at the bottom, you will notice that when you sit under the left platform and jump - he still snaps up to the platform.

    http://www.sendspace.com/file/u0t3qk

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