A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Help Centring

  1. #1
    Member
    Join Date
    May 2009
    Posts
    30

    Question Help Centring

    Hey cn u plz help mei am making a game and i cnt seen to centre the guy so he wont go off the screen and is allways in the middle heres the code:
    PHP Code:
    yspeed 0;
    xspeed 0;
    gravity 0.2;
    rotationspeed 0;
    power 1.1;
    friction 0.9;
    fly.onEnterFrame = function() {
        while (
    ground.hitTest(fly._xfly._ytrue)) {
            
    fly._y--;
        }
        while (
    ground.hitTest(fly._x-25fly._y-25true)) {
            
    fly._x++;
            
    xspeed 0;
        }
        while (
    ground.hitTest(fly._x+25fly._y-25true)) {
            
    fly._x--;
            
    xspeed 0;
        }
        while (
    ground.hitTest(fly._xfly._y-fly._widthtrue)) {
            
    fly._y++;
            
    yspeed 0;
        }
        if ((
    _root.ground.hitTest(fly._xfly._y+1true))) {
            
    yspeed 0;
        }
        
    xspeed *= friction;
        
    this._x += xspeed;
        
    rotationspeed *= friction;
        
    this._rotation 0+rotationspeed/2;
        
    this._y += yspeed;

        if (
    Key.isDown(37)) {
            
    xspeed -= power;
            
    rotationspeed += power*xspeed/2;
        } else if (
    Key.isDown(39)) {
            
    xspeed += power;
            
    rotationspeed += power*xspeed/2;
        }
        if (
    Key.isDown(38)) {
            
    yspeed -= power;
            
    fly._y -= 0.2;
        }
        if (
    yspeed<0) {
            
    yspeed *= friction;
        }
        
    yspeed += gravity;
    }; 
    Note: The in things name is "fly" and the level platforms are called
    "platform" Help will be gratly appreciated

    Cheers, Corey

  2. #2
    Developer dVyper's Avatar
    Join Date
    Oct 2008
    Location
    UK
    Posts
    168
    Why have you made a new thread for this?

    But anyway I think all you need to do is make the stage move in the opposite way to the player - this way the player will stay in the same position on the screen. That should help

  3. #3
    Member
    Join Date
    May 2009
    Posts
    30

    So How Do I Do That

    Um sorry but im new to flash actionscripting so cldu plz help me

    Cheers, Corey

  4. #4
    my x booty it is that BIG
    Join Date
    Jun 2004
    Location
    New York
    Posts
    696
    Quote Originally Posted by dVyper View Post
    Why have you made a new thread for this?

    But anyway I think all you need to do is make the stage move in the opposite way to the player - this way the player will stay in the same position on the screen. That should help
    going off on what he said have you tried
    Code:
    yspeed = 0; 
    xspeed = 0; 
    gravity = 0.2; 
    rotationspeed = 0; 
    power = 1.1; 
    friction = 0.9; 
    fly.onEnterFrame = function() { 
        while (ground.hitTest(fly._x, fly._y, true)) { 
            fly._y--;
            ground._y++;
        } 
        while (ground.hitTest(fly._x-25, fly._y-25, true)) { 
            fly._x++;
    ground._x--;
            xspeed = 0; 
        } 
        while (ground.hitTest(fly._x+25, fly._y-25, true)) { 
            fly._x--; 
    ground._x++;
            xspeed = 0; 
        } 
        while (ground.hitTest(fly._x, fly._y-fly._width, true)) { 
            fly._y++; 
    ground._y--;
            yspeed = 0; 
        } 
        if ((_root.ground.hitTest(fly._x, fly._y+1, true))) { 
            yspeed = 0; 
        } 
        xspeed *= friction; 
        this._x += xspeed; 
        rotationspeed *= friction; 
        this._rotation = 0+rotationspeed/2; 
        this._y += yspeed; 
    
        if (Key.isDown(37)) { 
            xspeed -= power; 
            rotationspeed += power*xspeed/2; 
        } else if (Key.isDown(39)) { 
            xspeed += power; 
            rotationspeed += power*xspeed/2; 
        } 
        if (Key.isDown(38)) { 
            yspeed -= power; 
            fly._y -= 0.2; 
        } 
        if (yspeed<0) { 
            yspeed *= friction; 
        } 
        yspeed += gravity; 
    };
    Project||[GAME]-on hold for now
    ------------------
    [Hero]-80%
    [Enemies]-1%
    [Weapons]-90%
    [Items]-0%
    [Levels]-10%

  5. #5
    Now tell me whos watchin...... samvillian's Avatar
    Join Date
    Feb 2007
    Location
    Where do you live?
    Posts
    539
    hes gonna ask what ground._x does....
    If the only tool you have is a hammer, you tend to see every problem as a nail.

    Xbox 360 Modding Controller PS3 Mod Paint Spray LED Case

  6. #6
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    Quote Originally Posted by samvillian View Post
    hes gonna ask what ground._x does....
    Random flaming is one thing Sam, but if you haven't got anything constructive to add to the thread, consider resisting to post flames.


    OP, have you thought about trying VCam2?
    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

  7. #7
    Member
    Join Date
    May 2009
    Posts
    30

    Question So What Do I Do

    So What Exactly Do I Do To Do The Cetre Thing?

  8. #8
    Senior Member
    Join Date
    Aug 2007
    Posts
    228
    dont give the MC you want "centered" any speed, it is not going to have a
    ._y or ._x speed, everything else has the opposite added or subtracted to their speed.
    if you want him to move around a little bit but not go off screen,
    put this in the move function so he will only move within a given set of perameters.

    if (mc._x<=#){
    mc._x += myspeed
    }


    myspeed would be whatever variable you have for speed. and do that for all directions so he will move in an invisible square in the screen and when he hits the edge, then everything will move in the opposite direction savvy?

  9. #9
    Member
    Join Date
    May 2009
    Posts
    30
    K so do i delete all the other code?

  10. #10
    Senior Member
    Join Date
    Aug 2007
    Posts
    228
    I decided to stay TF away from scrolling games until I made a few games, but thats just me.

    just delete the part of the code that actually moves the MC

  11. #11
    Member
    Join Date
    May 2009
    Posts
    30

    Question So I Put The oving Code On The Bg?

    Ok so i move the code tomove from the guy to the bg?

  12. #12
    Senior Member
    Join Date
    Aug 2007
    Posts
    228
    yes your not actually moving the guy, your moving everything else in the opposite direction.

  13. #13
    Member
    Join Date
    May 2009
    Posts
    30
    k ill try that

  14. #14
    Member
    Join Date
    May 2009
    Posts
    30
    Ive tried it but now when the guyhits the walls he goes ight through them any ideas anyway heres the code:
    PHP Code:
    yspeed 0;
    xspeed 0;
    gravity 0.2;
    rotationspeed 0;
    power 1.1;
    friction 0.9;
    ground.onEnterFrame = function() {
        while (
    fly.hitTest(ground._xground._ytrue)) {
            
    fly._y--;
        }
        while (
    fly.hitTest(ground._x-25ground._y-25true)) {
            
    ground._x++;
            
    xspeed 0;
        }
        while (
    fly.hitTest(ground._x+25ground._y-25true)) {
            
    ground._x--;
            
    xspeed 0;
        }
        while (
    fly.hitTest(ground._xground._y-ground._widthtrue)) {
            
    ground._y++;
            
    yspeed 0;
        }
        if ((
    _root.fly.hitTest(ground._xground._y+1true))) {
            
    yspeed 0;
        }
        
    xspeed *= friction;
        
    this._x += xspeed;
        
    rotationspeed *= friction;
        
    this._rotation 0+rotationspeed/2;
        
    this._y += yspeed;

        if (
    Key.isDown(37)) {
            
    xspeed -= power;
            
    rotationspeed += power*xspeed/2;
        } else if (
    Key.isDown(39)) {
            
    xspeed += power;
            
    rotationspeed += power*xspeed/2;
        }
        if (
    Key.isDown(38)) {
            
    yspeed -= power;
            
    ground._y -= 0.2;
        }
        if (
    yspeed<0) {
            
    yspeed *= friction;
        }
        
    yspeed += gravity;
    }; 
    Sue It Scrolls But The Guy Gos Straight Through The Walls.

  15. #15
    the cheesy child bounceboy's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    323
    yea he showed me, doesn't work right...
    but hey, Corey, you should try to solve the prob with what he gave u.

    anyway try everything the opposite way because basically whats happening is the gravity is making u go up, not down. so switch the moving parts around!

  16. #16
    Senior Member
    Join Date
    Aug 2007
    Posts
    228
    I still havent figured out walls yet! LOL the only way I can do wills
    is if I make 1 wall for each direction and put them togeather to make 1 wall.

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