XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

2D Sidescroller design

Last post 04-23-2008 5:47 PM by Warren. 7 replies.
  • 04-21-2008 3:28 AM

    2D Sidescroller design

    Hi, I was wondering if I could get some feedback on how to attack the engine of a 2D environment (sideview).

    I currently have a character in a single room (one level) that can move around and jump. The way I use the jump method is by initializing a Y position when the jump key is pressed and another when the character reaches the peak of his jump (ex: vf = vi + at2... all of those happy kinematic formulas). Everything works perfectly. At least it looks good... (thats all that matters, right?)

    Anyways, I was wondering if that was a decent way to go about things when making a sidescrolling environment. I was also wondering if anybody had any ideas on movements on an incline (ex: stairs/hills). I was thinking about doing something like:

    Collision (person a, floor b)
    {
    if (b.size.top == a.size.bottom + 1)
    {
    a.position.y += 1;
    return true;
    }
    else
    {
    return true;
    }
    }


    So basically, I would be seeing if the floor the character would be running into would be 1 pixel greater than where he is, and if it is, it will move him up 1 pixel.

    I'm still learning, so if anybody has an even better logical method or something.. that would be much appretiated ^^




    ------------------------------
    their != there != they're
    ------------------------------
  • 04-21-2008 6:09 AM In reply to

    Re: 2D Sidescroller design

    There are two basic techniques that most people use, depending on how you do your maps.

    You can either have a char based map and set a flag, say "solid" that prevents the character moving into that char.

    If it's not solid you take the x coord and work out what y coord works. You use the change in Y as a tool to decide if the character then goes into a special state, say falling or climbing a step.

    The second way is used mainly for deformable maps, like worms.

    You take the X coord and work out the Y coord that represents, delta y then defines everything. Solidity, falling, etc.

    either way delta y is the key factor, it defines everything.

     

     

     

    Information is not knowledge, knowledge is not wisdom, wisdom is not truth, truth is not beauty, beauty is not love, love is not music, music is the best! Wisdom is the domain of the Wis (which is extinct).
  • 04-22-2008 12:04 PM In reply to

    Re: 2D Sidescroller design

    Ok. That's pretty much what I was thinking. I pretty much have this huge if/else if statement that gets every direction and animates depending on the direction and if the character is in air.. etc. I guess that's the way to go. I guess I was hoping for a way to make it more simple and clean because that logic I have is pretty ugly looking (from my POV). Thanks for the feedback though!
    ------------------------------
    their != there != they're
    ------------------------------
  • 04-22-2008 12:31 PM In reply to

    Re: 2D Sidescroller design

    If you go with a tile-based level, you could easily simplify this down. For example I did a series of videos on making a tile engine. I then took that and applied some gravity to a sprite and instantly had a sidescroller: http://nick.gravelyn.com/2008/04/20/castle/.

    The code I use for collisions checks the 8 tiles surrounding the player's sprite to see if they have any special characteristics. By this I mean that the engine allows me to not only flag tiles as "solid", but also flag them with any other value. For instance I can flag them with '2' and then say that any tile with a collision value of '2' means my character moves at half speed. The system works pretty well and is a bit more simple and a bit more CPU efficient than a bunch of if-statements.

    Just throwing it out there for you to think about. Good luck any way you go.

    Nick Gravelyn -- Microsoft XNA MVP
    Blog | The Best Game. Ever. | Next-Gen
  • 04-23-2008 3:19 AM In reply to

    Re: 2D Sidescroller design

    Ah, OK! Thanks for the links. I'm downloading the videos as we ( I ) speak. Hopefully I'm not too dumb and can understand it :)

    ------------------------------
    their != there != they're
    ------------------------------
  • 04-23-2008 10:59 AM In reply to

    Re: 2D Sidescroller design

    Nick Gravelyn:
    The code I use for collisions checks the 8 tiles surrounding the player's sprite to see if they have any special characteristics. By this I mean that the engine allows me to not only flag tiles as "solid", but also flag them with any other value. For instance I can flag them with '2' and then say that any tile with a collision value of '2' means my character moves at half speed. The system works pretty well and is a bit more simple and a bit more CPU efficient than a bunch of if-statements.


    This is a lot like how I'm doing it except I'm just getting the values for the tiles that each corner of the player touches.  Mind you this only works if the players is the size of or smaller than one tile.  This way I only need to do 4 checks.  It's made doing things like slopes and ice and things pretty easy.  I even have a flag to do a per-pixel collision check, though I only use this on the tiles that kill you.  This is what I have so far.
    http://www.youtube.com/watch?v=UcoeJ_4nPhg
  • 04-23-2008 12:47 PM In reply to

    Re: 2D Sidescroller design

    I was thinking about this, too. I had the same ideas a Nick did with using a tile engine, except I was thinking more along the lines of:

    ===

    if Y+half-of-character-height<the next multiple of the Y size of the tiles and Y+gravity+half-of-character-height>the perviously mentioned multiple,

    then

    Gravity will be 0

    and

    Y=the multiple-half of character height.

    ===

    And it would check for the tiles that way.

  • 04-23-2008 5:47 PM In reply to

    Re: 2D Sidescroller design

    CheezCB:


    Ha, looks cool so far!
    ------------------------------
    their != there != they're
    ------------------------------
Page 1 of 1 (8 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG