A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: Help with cloud like platforms

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

    Help with cloud like platforms

    Hi, I am desperately trying to figure out how to make cloud like platforms where you jump up through them but don't actually land on them until you start falling again.

    Could anyone help - I can post code if you would like and also I don't want it to be tile based either.

    Thank you for any help in advance.

  2. #2
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    If your jump speed is negative (sending you up) and you collide with the platform, do nothing.

    If your jump speed is positive (sending you down) AND your 'feet' are above the platform, land on it, otherwise, do nothing.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  3. #3
    Robot Master the--flash's Avatar
    Join Date
    Jul 2005
    Location
    The year 20XX...
    Posts
    132
    Dunno whether your game is tile-based, but tonypa did a whole series of tutorials on tile based games, and one of the sections is about clouds.

    http://www.tonypa.pri.ee/tbw/

    ImprisonedPride's method works, though.

  4. #4
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    Sorry, I don't want any tile based and i've already seen Tonypa's and it wouldn't work with my engine.

    I've tried the other suggestion and it works fine - however, when you reach the arc of your jump and just happen to be touching the top of the platform; it automatically snaps onto the platform and looks quite crude. I want it to be smoother if possible.

  5. #5
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    You mean the frame where the sign of the fall speed changes from negative to positive? I suppose you could add a check to see if "adding" the amount of change in fall speed from the previous frame changes the sign back to what it was, and if so, you could ignore the hitTest on the platform.

    Alternately you could also check to see if fall speeds NEXT frame will be crossing the top of the platform and react accordingly.

    Finally, you could not check the top of the platform, but maybe a few pixels higher than that (like adding a 5px buffer above to check the "top" of the platform) which might reduce the snapping issue when the fall speed is near zero.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  6. #6
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    Here is my .fla if it helps. Would you be so kind as to have a look at it for me please. If not then that's fine

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

  7. #7
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    http://soap.com.au/chris/attachments...CHARACTER9.zip

    - changed it to the position of the player is defined by a number, not screen position. I'm pretty sure the accuracy of using the _x and _y of objects is much less than a Number object.
    - added a checkCollision function to all objects instead of giving them their own enterFrame. This way you can control the execution of your code. Process player first (get updated positions) then process collisions, then render player to correct position.
    - put all collision objects into an array.
    - the cloud collision function uses a rectangle to define the collision boundaries, you then check the old position of the player and new position and see if the object passed through. If so, set the players position to the top of the platform.
    Last edited by mr_malee; 08-24-2008 at 10:43 PM.
    lather yourself up with soap - soap arcade

  8. #8
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    Quote Originally Posted by mr_malee
    http://soap.com.au/chris/attachments...CHARACTER9.zip

    - changed it to the position of the player is defined by a number, not screen position. I'm pretty sure the accuracy of using the _x and _y of objects is much less than a Number object.
    - added a checkCollision function to all objects instead of giving them their own enterFrame. This way you can control the execution of your code. Process player first (get updated positions) then process collisions, then render player to correct position.
    - put all collision objects into an array.
    - the cloud collision function uses a rectangle to define the collision boundaries, you then check the old position of the player and new position and see if the object passed through. If so, set the players position to the top of the platform.
    Wow thats overwhelming compared to what i have done - i only have one problem with it though - I wasnt really planning on having an array for the collision objects - I wanted all of the code contained within the movie clip so I could just drag and drop it on the stage and it will function correctly. I am trying to edit your code to accomplish this but gotta learn what a lot of it does first lol

  9. #9
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Turn the array of objects into an empty one arrayName = []; and then give all on screen objects a variable called objectType. For platforms, on their code frame you'd have objectType = "platform";. Then call this function once right at the start of the level:

    Code:
    function findCollisions() {
         for (i in _root) {
              if (     (typeof(i) == "movieclip")     && i.objectType == "platform") {
                   arrayNameMaleeUsed.push(i);
              }
         }
    }
    It's not tested so I think it works, but it may require some adjusting. Replace the reference to _root with the name of clip that contains all your platforms, walls, etc. Basically this will allow you to use Malee's code and still be able to drag and drop platforms and walls onto the stage. Remember to only call it once, because calling it every frame will probably kill the player with a lot of obstacles on stage.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  10. #10
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    Quote Originally Posted by GingaNinja
    Wow thats overwhelming compared to what i have done - i only have one problem with it though - I wasnt really planning on having an array for the collision objects - I wanted all of the code contained within the movie clip so I could just drag and drop it on the stage and it will function correctly. I am trying to edit your code to accomplish this but gotta learn what a lot of it does first lol
    I can say right now, that is not the best approach to creating a platform game, you will soon find yourself in trouble (performance wise and management wise)

    IP has a good solution, maybe you could also add a "addCollisionObject" function to the root and then within the movieclips they call that function and pass themselves to it.

    so your movie would have 3 frames:

    1 - initialize base objects, arrays, variables
    2 - movieclips on stage are added to arrays
    3 - onEnterFrame starts and game runs.
    lather yourself up with soap - soap arcade

  11. #11
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    Quote Originally Posted by ImprisonedPride
    Turn the array of objects into an empty one arrayName = []; and then give all on screen objects a variable called objectType. For platforms, on their code frame you'd have objectType = "platform";. Then call this function once right at the start of the level:

    Code:
    function findCollisions() {
         for (i in _root) {
              if (     (typeof(i) == "movieclip")     && i.objectType == "platform") {
                   arrayNameMaleeUsed.push(i);
              }
         }
    }

    It's not tested so I think it works, but it may require some adjusting. Replace the reference to _root with the name of clip that contains all your platforms, walls, etc. Basically this will allow you to use Malee's code and still be able to drag and drop platforms and walls onto the stage. Remember to only call it once, because calling it every frame will probably kill the player with a lot of obstacles on stage.
    I can see what you are tying to do but it doesnt seem to be working -I just fall straight through!

    Sorry if Im being too much of a n00b - I ain't used flash for time and a lot of this is quite new to me

    EDIT:
    And Mr Malee - im making a fighting game so i wouldn't really have to worry about performance and maintenance because the levels are only really small.

  12. #12
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Make sure you are correctly referencing both the array malee used AND the mc containing the platforms.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  13. #13
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    Quote Originally Posted by ImprisonedPride
    Make sure you are correctly referencing both the array malee used AND the mc containing the platforms.
    Well i've changed the array name that malee used and all my platforms are on the _root so that shouldn't need to change right?

    Ive also put objectType = "platform"; in the code for the platforms.



    Like I said I can see what you are trying to do but it just isn't adding the platforms to the array - it is not recognizing the typeof bit as far as I can see

  14. #14
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    it needs to be:
    Code:
    for (i in _root) {
    
    	var ob = _root[i];
    
    	if (ob.objectType == "platform") {
    		platforms.push(ob);
    	}
    }
    no need to check typeof.
    lather yourself up with soap - soap arcade

  15. #15
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Quote Originally Posted by mr_malee
    it needs to be:
    Code:
    for (i in _root) {
    
    	var ob = _root[i];
    
    	if (ob.objectType == "platform") {
    		platforms.push(ob);
    	}
    }
    no need to check typeof.

    potatoe potatoh
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  16. #16
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    Quote Originally Posted by mr_malee
    it needs to be:
    Code:
    for (i in _root) {
    
    	var ob = _root[i];
    
    	if (ob.objectType == "platform") {
    		platforms.push(ob);
    	}
    }
    no need to check typeof.
    Okay it seems to work when I put findCollisions(); in the onEnterFrame functoin but as mentioned - this causes it to mess up and it runs really slowly. However if I put that function call elsewhere then it doesn't work at all.

  17. #17
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Quote Originally Posted by GingaNinja
    Okay it seems to work when I put findCollisions(); in the onEnterFrame functoin but as mentioned - this causes it to mess up and it runs really slowly. However if I put that function call elsewhere then it doesn't work at all.
    Quote Originally Posted by ImprisonedPride
    Remember to only call it once, because calling it every frame will probably kill the player with a lot of obstacles on stage.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  18. #18
    x2i GingaNinja's Avatar
    Join Date
    Feb 2004
    Location
    England
    Posts
    217
    That's what I did and it never worked - it only worked when I did what you told me not to do but after a while it lagged terribly.

    Where should I be putting it?

  19. #19
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    like I said, you need 3 frames. Whats happening is the objects don't have the objectProperty when that loop is called. Their properties are set after the root code has executed. So, they must exist and be put into memory before the root code executes.

    http://soap.com.au/chris/attachments...CHARACTER9.zip
    lather yourself up with soap - soap arcade

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