A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: How to do y scrolling in a platformer

  1. #1
    Senior Member
    Join Date
    Nov 2007
    Location
    California
    Posts
    118

    Unhappy How to do y scrolling in a platformer

    Im sick of doing shotty y scrolling by myself and im pretty sure theres an ezer way to do it that magically will solve all my problems and before you call me a lazy nub i've been working it at it for days my hygiene is reflecting my work can someone please show me some way to do it in ACTIONSCRIPT TWO format, preferably in ClipEvent or frame mode, none of that complicated as3 stuff it makes my butt hurt thanks i am forever in your debt james mcloud i will make you part of my cornerian army

  2. #2
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    Ok well, what's the problem? What are you trying to do? How are you trying to do it now? This forum isn't a "magical" solution; give us a proper post and we'll give you a proper response.
    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
    Senior Member
    Join Date
    Nov 2007
    Location
    California
    Posts
    118
    PHP Code:
    onClipEvent (load) {
        
    gravity 1;
        
    yvel 0;
        
    airrotationvar 0;
        
    speed 0;
        
    power 2;
        
    friction .93;
        
    rotationvar 0;
        
    gravity true;
    }
    onClipEvent (enterFrame) {
        
    _root.square._y += yvel;
        
    _root.leftsquare._y += yvel;
        
    _root.rightsquare._y += yvel;
        
    _root.limitbar._y += yvel;
        
    _root.bg._x += speed;
        
    airrotationvar *= .95;
        if (
    _root.bg.hitTest(_root.square._x_root.square._y-2true)) {
            
    speed *= friction;
        }
        if (!
    _root.bg.hitTest(_root.square._x_root.square._y-2true)) {
            
    speed *= .98;
        }
        
    _root.square._rotation += rotationvar;
        
    _root.square._rotation += airrotationvar;
        
    _root.leftsquare._y -= rotationvar/2.25;
        
    _root.rightsquare._y += rotationvar/2.25;
        if (
    Key.isDown(Key.LEFT)) {
            if (
    speed<=12) {
                
    speed += (power/1.5);
            }
        }
        if (
    Key.isDown(Key.RIGHT)) {
            if (
    speed>=-12) {
                
    speed -= (power/2);
            }
        }
        if (!
    _root.bg.hitTest(_root.square._x_root.square._y-3true)) {
            
    gravity true;
            if (
    Key.isDown(Key.LEFT)) {
                if (
    airrotationvar>=-10) {
                    
    airrotationvar -= (power/2);
                }
            }
            if (
    Key.isDown(Key.RIGHT)) {
                if (
    airrotationvar<=10) {
                    
    airrotationvar += (power/2);
                }
            }
            if (
    yvel<=15) {
                
    yvel += (gravity*2);
            }
            
    // 
            
    rotationvar 0;
            
    _root.leftsquare._y _root.square._y;
            
    _root.rightsquare._y _root.square._y;
            
    _root.limitbar._y _root.square._y-30;
        } else {

            while (
    _root.bg.hitTest(_root.square._x_root.square._y-2true)) {
                if (
    gravity == true) {
                    
    airrotationvar 0;
                    
    _root.square._rotation 0;
                    
    gravity false;
                }
                if (
    Key.isDown(Key.SPACE)) {
                    
    yvel = -26;
                }
                if (!
    _root.bg.hitTest(_root.leftsquare._x_root.leftsquare._y-6.3true) and (_root.bg.hitTest(_root.rightsquare._x_root.rightsquare._y-6.3true))) {
                    
    rotationvar = -2;
                }
                if (
    _root.bg.hitTest(_root.leftsquare._x_root.leftsquare._y-6.3true) and (_root.bg.hitTest(_root.rightsquare._x_root.rightsquare._y-6.3true))) {
                    
    rotationvar null;
                }
                if (!
    _root.bg.hitTest(_root.rightsquare._x_root.rightsquare._y-6.3true) and (_root.bg.hitTest(_root.leftsquare._x_root.leftsquare._y-6.3true))) {
                    
    rotationvar 2;
                }
                if (
    _root.square._rotation<=0) {
                    
    _root.bg._x += (_root.square._rotation/-50);
                }
                if (
    _root.square._rotation>=0) {
                    
    _root.bg._x += (_root.square._rotation/-50);
                }
                if (
    _root.limitbar.hitTest(_root.leftsquare._x_root.leftsquare._y-6.5true)) {
                    
    _root.square._rotation 0;
                    
    rotationvar 0;
                    
    _root.leftsquare._y _root.square._y;
                    
    _root.rightsquare._y _root.square._y;
                    
    _root.limitbar._y _root.square._y-30;
                }
                if (
    _root.limitbar.hitTest(_root.rightsquare._x_root.rightsquare._y-6.5true)) {
                    
    _root.square._rotation 0;
                    
    rotationvar 0;
                    
    _root.leftsquare._y _root.square._y;
                    
    _root.rightsquare._y _root.square._y;
                    
    _root.limitbar._y _root.square._y-30;
                }
                
    _root.square._y -= 2;
                
    _root.leftsquare._y -= 2;
                
    _root.rightsquare._y -= 2;
                
    _root.limitbar._y -= 2;
            }
        }

    This is the normal coding for just regular left and right scrolling where the leftsquare and rightsquare manage the rotation of the square mc. I would try replacing the _root.square._y -= yvel (yvelocity) with _root.bg._y += yvel, and the thing would just explode. Yes I am sorry if I came off as rude or inconsiderate relying only on the shoulders of people who code for a living. Im sure there has to be some moderation between the scrolling of the square and the background itself but its too difficult to do or when i try its not the result I want. Please help

  4. #4
    Senior Member
    Join Date
    Nov 2007
    Location
    California
    Posts
    118
    http://megaswf.com/view/502bab9e6962...02cd9f492.html Here is my progress of just normal scrolling and such.
    http://megaswf.com/view/18ba7ff5d42a...33c82600c.html Heres as far as I can get with the crappy scrolling :/

  5. #5
    Junior Member
    Join Date
    Jan 2010
    Posts
    5
    I would suggest putting all your game elements inside of a "level" movieclip. That way you can just change the x and y position of the entire level to make it scroll. So as the level moves in one direction, the hero MC or what have you inside of the level moves in the other direction, so the hero remains in the same place relative to the edge of the stage. My platformer engine for AS3 has a class called GameCamera that does the camera part for you, you're welcome to adapt it to AS2 if you'd like.

  6. #6
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    http://bryanheisey.com/blog/?p=1


    That's probably the best way to handle screen movement in a platformer, just make the camera's y and or x equal to the player's x and y.

    Cheers.
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

  7. #7
    Senior Member
    Join Date
    Nov 2007
    Location
    California
    Posts
    118
    YAY FOR VCAM woot it works here it is it lags like a mofo but w/e
    http://megaswf.com/view/fd2621eca562...108560ab4.html

  8. #8
    Flash Intermediate XenElement's Avatar
    Join Date
    Sep 2008
    Location
    At my computer
    Posts
    196
    Glad it helped =D That's probably the simplest way, and that way, you have other functionality, since it's self contained.
    In the process of designing a quirky little game engine called gulp. Check out it's progress below: @ my blog.

    ---

    Check out my blog at XenElement.com

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