A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Movement Question/Scroll not moving/

  1. #1
    Member
    Join Date
    Feb 2002
    Location
    Chicago, Atlanta
    Posts
    57

    Movement Question/Scroll not moving/

    Scrolling and Movement(NOT WORKING)

    I am trying to make a game that has scrolling background and my character is not moving when I tried to make scrolling background. But Jumping is working. Yeah.

    I first made the gravity with a function that is own a layer. Look at file. I made a movie clip called ground. And Here is the Action Script. It works.

    PHP Code:
    // Set our variables
    jumpAmount 15;
    gravity 1;
    onGround true;
    _root.onEnterFrame = function() {
        if (
    Key.isDown(key.SPACE)) {
            
    onGround false;
        }
        if (!
    onGround) {
            
    player._y -= jumpAmount;
            
    jumpAmount -= gravity;
        }
        if (
    player.hitTest(ground)) {
            
    onGround true;
        }
        if (
    onGround) {
            
    jumpAmount 15;
        }
    }; 
    Then when I tried to make the scrolling background. This is what I did. I first made a movie clip called bg(instances name the same). bg servers as ground. Then I went in to the movie clip and made a two walls called lhit and rhit. This is were my character will stop when he is walking.

    On my character I put this action script for the scrolling and movement and character development(alt=punch and apple key= punch).
    PHP Code:
    onClipEvent (load) {
        
    speed 5;
        
    grav 0;
    }
    onClipEvent (enterFrame) {
        
    // gravity
        
    if (!_root.ground.hitTest(_x_y+1true)) {
            
    grav += 1;
            
    _y += grav;
        } else {
            
    grav 0;
        }
        while (
    _root.ground.hitTest(_x_ytrue)) {
            
    _y -= 1;
        }
        
    // movement
        
    if (Key.isDown(key.RIGHT) && player._x<400) {
            
    player._x += xmov;
        } else if (
    Key.isDown(key.RIGHT) && player._x>399) {
            
    bg._x -= xmov;
            
    player._x += 0;
        }
        if (
    Key.isDown(key.LEFT) && player._x>150) {
            
    player._x -= xmov;
        } else if (
    Key.isDown(key.LEFT) && player._x<151) {
            
    bg._x += xmov;
            
    player._x += 0;
        }
        if (
    player.hitTest(bg.lhit)) {
            
    player._x += xmov;
        }
        if (
    player.hitTest(bg.rhit)) {
            
    player._x -= xmov;
        } else if (
    Key.isDown(Key.ALT)) {
            
    gotoAndStop(3);
            
    punch.play();
        } else if (
    Key.isDown(Key.CONTROL)) {
            
    gotoAndStop(4);
            
    punch2.play();
        }


    Also, when I punch he falls to the center of the ground. Is that because the resigtartion mark.

    I have included my FLA file. It is Flash MX form.
    Attached Files Attached Files

  2. #2
    Senior Member hum's Avatar
    Join Date
    Sep 2003
    Location
    CloudCuckooland
    Posts
    1,714
    Hi...
    I had a look for ya and fixed most of the problems....
    I'm a bit busy right now to go through it with you.....
    all you need now is to put the left and right wallhits back in ....
    maybe someone else reading this thread can help you with that part....Good luck!
    Last edited by hum; 12-02-2004 at 08:40 PM.

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