A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Platform Game Problem..HEP!!

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

    Platform Game Problem..HEP!!

    Hi Guys,

    I'm in the process of making my first flash platform game and im having problems with the guy landing on the platforms (he falls though them half of the time, espeicially if you go to the top of the screen and casually fall off one of the upper platforms he will fall through all platforms and land on the very bottom one)

    here is the demo, use left right arrows and up arrow to jump): http://www.thekay.co.uk/platformtest.htm

    Here is the code which is all on the first frame of the movie (i dont have any code on any movie clip (the platform movieclip is called 'land' and the man movieclip is called 'guy')

    Basically i want the man to land accurately on all of the platforms without falling through them, can anybody point me in the right direction?


    init();

    function init(){
    guy.dx = 0;
    guy.dy = 0;
    guy.jumping = false;
    } // end init

    guy.stop();

    guy.onEnterFrame = function(){
    //check keys
    if(Key.isDown(Key.RIGHT)){
    guy._xscale=-100;
    guy._x +=6;
    guy.play();
    if (guy._x >550) {guy._x = 550;}
    } else {guy.stop();}

    if(Key.isDown(Key.LEFT)){
    guy._xscale=+100;
    guy._x -=6;
    guy.play();
    if (guy._x <40) {guy._x = 40;}

    } // end if// end if

    //jump
    if(Key.isDown(Key.UP)){
    if(guy.jumping == false){
    guy.jumping = true;
    guy._y -= 5;
    guy.dy = -5;
    } // end if jumping false

    } // end if keydown
    guy.dy += .5;

    //guy hits ground
    if (land.hitTest(guy._x, guy._y, true)){
    guy.jumping = false;
    } // end if land test = true

    guy.dy = 0;

    } // end if land hittest

    guy._y += guy.dy;

    } // end enterFrame

  2. #2
    Junior Member
    Join Date
    Dec 2006
    Posts
    7
    Im using Flash MX 2004 by the way.

  3. #3
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Just make the platforms thicker.
    http://www.birchlabs.co.uk/
    You know you want to.

  4. #4
    Junior Member
    Join Date
    Dec 2006
    Posts
    7
    Making the platforms thicker is not what im after, i want the man to land on the platforms, not 'in' them.

  5. #5
    Lurker at Heart EgoAnt's Avatar
    Join Date
    Apr 2004
    Location
    The basement
    Posts
    314
    Thicker platforms is one solution, could you post the code you currently use for platform detection?
    Speed up your development time with well documented and easy to implement Flash components.
    That's what I do, I save people.... Save them from work. I'm like a slacker superhero, standing for truth, justice, and the consumption of sugary pastries.

  6. #6
    Junior Member
    Join Date
    Dec 2006
    Posts
    7
    All code is in my first post but this is the bit i use for land detection:

    //guy hits ground
    if (land.hitTest(guy._x, guy._y, true)){
    guy.jumping = false;
    } // end if land test = true

    guy.dy = 0;

    } // end if land hittest

  7. #7
    Lurker at Heart EgoAnt's Avatar
    Join Date
    Apr 2004
    Location
    The basement
    Posts
    314
    Ah! So are the platforms all a part of the base land clip then? I misunderstood, I assumed they'd be individual items.
    Speed up your development time with well documented and easy to implement Flash components.
    That's what I do, I save people.... Save them from work. I'm like a slacker superhero, standing for truth, justice, and the consumption of sugary pastries.

  8. #8
    Junior Member
    Join Date
    Dec 2006
    Posts
    7
    yes, all platforms are part of the same 'land' movieclip.

  9. #9
    Lurker at Heart EgoAnt's Avatar
    Join Date
    Apr 2004
    Location
    The basement
    Posts
    314
    Okay, I'd suggest moving them out and then doing a check of each platform, one by one. However, if you just want to make a small adjustment to the code you are using, try something like this:

    Code:
    //guy hits ground
    for(yMod=0;yMod<=10;yMod++){
    if (land.hitTest(guy._x, guy._y - yMod, true)){
    guy.jumping = false;
    } // end if land test = true
    }
    guy.dy = 0;
    
    } // end if land hittest
    What that will do is broaden the hit zone by about 10 pixels.
    Speed up your development time with well documented and easy to implement Flash components.
    That's what I do, I save people.... Save them from work. I'm like a slacker superhero, standing for truth, justice, and the consumption of sugary pastries.

  10. #10
    Truimagz.com everfornever's Avatar
    Join Date
    Sep 2006
    Location
    St. Louis
    Posts
    1,306
    This is an old school art based platformer, I personally would do the coding alot differently and shorten it quite a bit, but it's a great start in showing you how to make art based platformers.

    http://truimagz.com/Hosting/Art%20B...0Platformer.fla

    here is the swf live

    http://truimagz.com/Hosting/OS_bobble_v1.swf

  11. #11
    Junior Member
    Join Date
    Dec 2006
    Posts
    7
    Hi Everfornever

    I try to download the .fla file you posted (right click - save target as) but it won't download (says site unavailable or cannot be found) Studying the bubble bobble game code could be just what i am after


    Thanks for your help too egoAnt, i gave it a try and it seems to work ok but ideally an accurate land on a platform would be better.

  12. #12
    Please, Call Me Bob trogdor458's Avatar
    Join Date
    Aug 2006
    Location
    Pensacola, FL
    Posts
    915
    well im sure you know the problem quite well, the platforms are too small and your _y position flies right past 'em, you may need a different approach to your collision testing

    an easy way to do this right is to use EgoAnt's idea, just make a platform mc and let your player cycle through all the hittests, here's an example:

    ytemp=_y;
    <movementactionshere>
    ytemp2=_y;
    for(i=0;i<_root.platformnum;i++){
    if(ytemp>=_root["platform"+i]._y){
    if(ytemp2<=_root["platform"+i]._y){
    _y=_root["platform"+i]._y;
    guy.jumping = false;
    break;
    }
    }
    }
    if the number of platforms is unknown:

    ytemp=_y;
    <movementactionshere>
    ytemp2=_y;
    for(i=0;i<_root.platformnum;i++){
    //this statement is used to find if the mc exists, there are many different ways to do it though
    //and you may want to use one of those if you plan on using alpha, i think there's even one more straightforward

    if(_root["platform"+i]._alpha!=100){
    break;
    }
    //...................
    if(ytemp>=_root["platform"+i]._y){
    if(ytemp2<=_root["platform"+i]._y){
    _y=_root["platform"+i]._y;
    guy.jumping = false;
    break;
    }
    }
    }
    if u have trouble understanding anything...just ask
    prettymuch this just checks to see if your mc has moved down through a platform, and sets your _y accordingly

  13. #13

  14. #14
    Junior Member
    Join Date
    Dec 2006
    Posts
    7
    That link works cheers everfornever.

    Cheers all for the info and help, between you all i've pretty much got my platform problems covered, you are all stars!! )

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