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

Question About Making The Platformer Game Side-Scrolling

Last post 11/28/2009 6:57 AM by Eckish. 10 replies.
  • 11/21/2009 9:55 PM

    Question About Making The Platformer Game Side-Scrolling

    This is my first post so please be kind. I have been working with the platformer that comes in Visual Studio and have been able to accomplish a few things so far:
    1.) Getting my sprite sheet working
    2.) Adding bullets that fire in 6 directions based on firing angle

    However, I have hit a road block. I cannot make this thing side scroll for anything. Is it possible using the tile system that the platformer comes with? I have looked at a few tutorials and have attempted to make a "camera", but all it does it move the image of the tiles. For example, I have the entire screen scrolling beautifully but I know it's only the textures because once I walk forward I hit an invisible block where the tile is. I am not sure how to progress being new at this. Do I need to do some file processing to update the text file that holds the tile information or is there a way to actually move the tile with the texture?

    Any help is much appreciated!
  • 11/21/2009 11:29 PM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    This is a very fundamental question. Tinkering is a great tool for experimenting with stuff you already understand the basics of, but if you're totally fresh you probably want to read some books or tutorials on XNA before diving right in.

    Chardish Games, wherein I blog about game design and my own projects.
  • 11/22/2009 12:50 AM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    Yes, I understand that I do need to do some research but I really need this question answered: Is it even possible to scroll using the platformer's tile system or would I need to make some sort of fundamental change to it? I need this question answered or else I would be wasting my time by just tinkering with the current system.
  • 11/22/2009 1:04 AM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    If you do not understand the sample project code you're using well enough to modify it, you probably don't understand it well enough to use it either.

    I'm not trying to be rude, but you would be much better off in the long run simply reading a book or searching for tutorials.
    Chardish Games, wherein I blog about game design and my own projects.
  • 11/23/2009 4:55 PM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    Ok, so I have been working rather extensively with the code now and have managed to get blocks that move across the screen. What I ended up doing was creating a new type of tiles called a block which has movement properties like an enemy. My intent is to make all "blocks" move when the players position reaches a certain X,Y. However, I am facing a new problem. Using this method I need to deal with collisions, but it seems that I can't use Collision.Impassable. So I have tried changing the players X position when they collide with a block and it is fairly effective, but it looks really bad with the Y movement. For example, if the player drops on a block they just float there still walking or keep getting pushed upwards. So my question is: Am I going about this the wrong way? Should the tiles not move like an enemy? Also is there a way use Collision.Impassable when I collide with a moving enemy using this tile system?
  • 11/23/2009 5:06 PM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    No, the tiles should not move.   For a few reasons.

    1. Performance - You are going to have to move every block in existence at the time when you want to shift the view, when instead you could just update the camera once.

    2. Game Mechanics - Like you have already encountered, when you move the blocks, things like collision detection get all screwy, because now the blocks are moving not just the player.  So, some odd edge cases can appear that previously wasn't an issue.

    3. Complexity - A lot of things get more complicated when you are trying to pretend that something isn't moveing, but the position values really are. 


    What you really want to do is to focus on the idea of a camera and moving that camera around as your player moves.  Even if you are having trouble understanding the examples, it will be of great benefit for you to figure out the concept.
  • 11/23/2009 6:44 PM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    Ok, so I have heard about the idea of camera and have attempted it in the past but I have never quite understood what it does. I think I could figure out how to do it if you or someone could explain what a camera does exactly. Basically: What is moving? The tiles, textures, or something? I need to understand this because I am not exactly sure what a camera is supposed to do.

    -I am glad to hear that I don't need to move each tile because I was thinking that it was a bad path to go. If it helps, I am trying to do something like the scrolling of the game "Being".
  • 11/23/2009 7:29 PM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    Answer
    Reply Quote
    To understand a camera, you need to start thinking in terms of spaces. 

    The beginning programmer tends to think of everything in a single space.  In other words, if the player is at position (5, 5), then he is checked for collision at (5, 5) and drawn at (5, 5) and rotated at (5, 5), etc.  But, in order to keep thinking that way and then change the view, you have to shift everything with the view or it all breaks.

    Thinking in spaces brings out terms like World Space, Camera Space, Screen Space, Model Space, etc.  A space, in this case, is a way of looking at something from a certain perspective. 

    Lets look at world space.  World space is how your game objects are positioned relative to a common origin.  If I have an object at position (5, 5), it is at position (5, 5).  If I move the view, the object is still at position (5, 5), because I haven't moved the object.  I've moved the view. When you do collision detection, you will always check the object against its world position of (5, 5).  Even if it moves off screen, it is still sitting at world position (5, 5).  It doesn't change world position, unless an action is taken to move it in the world space.  Like when your character decides to go for a walk.  Or when a block gets pushed around, etc.

    Screen space is how your objects position up to your viewable area on the screen.  When I change the view, it doesn't affect the world space.  If I pan to the left some, the objects are still where they were.  I'm just looking at them from a different position. 

    You really don't fully understand these spaces, until you know how to convert between each other.  In 3D, we tend to use a view matrix to define how the world maps to the camera and then a projection matrix to determine how the camera points map to the screen.  You don't have to fully understand the how's and why's to use them with XNA.  There are some really good helper methods that will take care of the hard work for you.  You can use these same things for a 2D sidescroller.  But, I think you cab make this much simpler for your purposes.

    The camera is there to help you determine how to draw a world space coordinate to the screen.  With a simple 2D side scroller, you might only be concerned with moving left and right.  When your camera is at (0,0), you see objects on the screen the same as their world space.  When you move the camera, the only thing that happens to your drawing is a translation.  So, there are two ways to go about this.

    First, we can think of it in simple terms of how to convert between the spaces.  If my object is at (5, 5) and I have a camera at (0, 0), then I draw my object at pixel (5, 5).  If I move my camera to the right 3 pixels, then that is the same as moving my object to the left 3 pixels.  So, when I draw my object, I draw at (2, 5).  We don't change the location of the object.  We never change the location of the object when drawing.  All we do is adjust it for drawing.  So, I might get the drawing coordinate with something like (objectX - cameraX, objectY).  Now, all you have to do is to adjust the camera, when you feel appropriate.  That might be as simple as making the camera's coordinates the same as your player's.

    Hopefully, the first method helps you see how exactly how the camera operates.  However, the implementation is not very ideal.  If you later decided that you would want the camera to also be able to move the view up and down, you would have to go through and add similar calculations to every draw call to adjust the y values the way you want them to be adjusted.  Not very effecient.  So, that brings us to the second method for implementing this.  SpriteBatch.Begin() includes an overloaded option to pass in a matrix.  As I understand it (I actually don't do much work with spritebatch and have never used this to be 100% certain), this matrix should be applied to all your draw call points.  So, to use this, you can use the Matrix.CreateTraslation() method to generate a translation based on your camera.  Then pass that into the Begin() method and it will automatically adjust all of your drawings.  Just remember that moving your camera to the right, means moving your objects to the left.  So, you will want to create the translation using the negative values for your camera. 


    I hope this helps you understand the concept a bit more.
  • 11/23/2009 7:51 PM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    Thanks, that really helped me in understanding what a camera exactly does. I think that now I will be able to understand code examples of a camera and be able to incorporate it into what I am trying to do. Your explanation was very thorough and I appreciate it a lot. 
  • 11/27/2009 10:41 PM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    Just as a follow up about this topic. I found this link which no one seemed to mention:
    http://msdn.microsoft.com/en-us/library/dd254919.aspx

    It is an official tutorial that transforms the platformer game into a side scroller by use of a camera.
  • 11/28/2009 6:57 AM In reply to

    Re: Question About Making The Platformer Game Side-Scrolling

    lol, sorry.  If I knew about it, I would of pointed you straight there =)
Page 1 of 1 (11 items) Previous Next