[XNA 4.0][Series] Content, Input, Draw & Movement

Discussion in 'Game Development' started by GoldBl4d3, Dec 15, 2012 with 15 replies and 1,651 views.

  1. GoldBl4d3

    GoldBl4d3 VIP VIP Retired

    Messages:
    3,778
    Ratings:
    1,345
    Content, Input, Draw & Movement

    In this tutorial we will cover the basics of loading content, retrieving input, and applying that in to movement. This tutorial is for absolute beginners. However, experienced programmers may comment and help others.
    Skill Level: Easy
    Time to Complete: 20 Minutes

    Art Assets Used:
    [​IMG]
    #2.1 Adding Content to Our Project
    Ensure you have followed part 1 of this series. Now on the right side is your Solution Explorer. Under the content project, right click Add->Existing Item. Select your rocket ship asset provided above. You will now see your asset in the content project. Name it RocketShip.​
    [​IMG]
    #2.2 Loading our Rocket Ship
    In our solution explorer, add a new Class to our game project. Name it Ship.cs. Now lets establish some basic principles. Please note to add the using declarations.​
    Texture2D - Is a flat surface grid of texels.
    Vector2 - A vector with two components (X, Y).
    Single - A floating point number. Also known as a float.
    [​IMG]
    Go back to our main game class. Here we declare our new ship class and load its content in to memory.​
    Viewport - Portion of the render target to receive draw calls.
    [​IMG]
    #2.3 Drawing our Rocket Ship
    Now, under the Draw method in our main game class. We are going to draw our sprite. First we begin the call, call it, and end the call.​
    Parameters: (Texture, Position, SourceRectangle, Tint, Rotation, Origin, Scale, Effects, LayerDepth)​
    SourceRectangle - The portion of the sprite to draw. Use null to draw the entire portion.
    Tint - The color overlay. White is full color.
    Origin - The location relevant to the sprite that will be used to rotate and position the sprite.
    Effects - Determines if the sprite is flipped or not.
    LayerDepth - The drawing order. Not used in this circumstances.
    [​IMG]
    Now debug your project. You can do this by clicking the green play arrow in your tool bars. Or go to Debug -> Start Debugging in the menu bar. Or hit F5 on your keyboard.​
    Your results should be just like this.​
    [​IMG]
    #2.4 Retrieving Input & Moving our RocketShip
    In the Update method. The most basic way to retrieve input from our keyboard is to get the state of our keyboard once per update call. Per frame, check to see if a button is down. If so, in this example we move the sprite by increasing or decreasing its position. We apply these same principles to rotate the sprite.​
    [​IMG]
    Now debug and move the rocket with your keyboard arrows and use the Q and W keys to rotate it.​
    Thank you for reading and following along. If you have any questions please post below. Please watch out for the next parts in the series. Next we will be talking about how to shoot projectiles from our rocket ship and apply velocity's.

     
    • Like Like x 10
  2. Visual Studio

    Visual Studio The Original Shiba Inu

    Messages:
    2,769
    Ratings:
    1,343
    Very nice tutorial I am happy that you are doing this, I am waiting til after the holidays to write my own.
     
    • Like Like x 2
  3. OP
    GoldBl4d3

    GoldBl4d3 VIP VIP Retired

    Messages:
    3,778
    Ratings:
    1,345
    Thanks, I cant wait until others start making tutorials. Lets try to get some game development talk on here.
     
  4. coolbunnymodz

    coolbunnymodz The Original Bunny

    Messages:
    4,384
    Ratings:
    1,263
    So I've been following this up thru 2.3, and I've gotten an error that won't allow me to debug the script.

    Here's the pastebin of what I have

    http://pastebin.com/gL5u3eji
     
  5. Zerker24

    Zerker24 Enthusiast

    Messages:
    865
    Ratings:
    197
    I can write a file system tutorial if you would like? I just made a good one for a project of mine.
     
    • Like Like x 1
  6. Xeren

    Xeren ♦♦♦ God Complex ♦♦♦

    Messages:
    5,678
    Ratings:
    1,889
    The tutorial looks good, hope you continue it.
     
    • Like Like x 1
  7. OP
    GoldBl4d3

    GoldBl4d3 VIP VIP Retired

    Messages:
    3,778
    Ratings:
    1,345
    Explain what the error is and on what line. Also did you follow the tutorial series from #1.0 ?
     
  8. coolbunnymodz

    coolbunnymodz The Original Bunny

    Messages:
    4,384
    Ratings:
    1,263
    This error here, and yes I followed the first tutorial.

    [​IMG]
     
  9. Xeren

    Xeren ♦♦♦ God Complex ♦♦♦

    Messages:
    5,678
    Ratings:
    1,889
    Try using this:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework;
    namespace Xbox360Game1
    {
        public class Ship
        {
            public Texture2D ShipTexture;
            public Vector2 Position;
            public Single Rotation;
        }
    }
     
  10. coolbunnymodz

    coolbunnymodz The Original Bunny

    Messages:
    4,384
    Ratings:
    1,263
    Unfortunately I still get the same error, I'm not a complete noob to this I understand sharp decently well I've never had this error
     
  11. Xeren

    Xeren ♦♦♦ God Complex ♦♦♦

    Messages:
    5,678
    Ratings:
    1,889
    You could try making it "public static class Ship", and if that doesn't work, then just get rid of "public" in "public Ship ship;". If you need to access it from another class, pass it as a reference.
     
  12. coolbunnymodz

    coolbunnymodz The Original Bunny

    Messages:
    4,384
    Ratings:
    1,263
    I don't think you can make it a static class, it'll return an instance error. I'll try the Ship ship however.

    I managed to fix it, changed it from public to private and for some reason it ran lol
     
  13. OP
    GoldBl4d3

    GoldBl4d3 VIP VIP Retired

    Messages:
    3,778
    Ratings:
    1,345
    Never go with a temporary fix like that, it will further cause problem in later tutorials. You must have the ship class defined twice in separate classes or something. If you have AIM I can assist you there. You told me what the error is, but not what the actual line of code its pointing to. Tell me that and I can figure it out. But come talk to me on aim and I will team viewer you. Or upload your source and I will send you the corrected version.
     
    • Like Like x 1
  14. Ressko

    Ressko Getting There

    Messages:
    2,014
    Ratings:
    476
    Hey man, I know youre probably not as active on here as you used to be, but I think you should carry on making these tuts. Im planing on making a small game in xna and these tuts are really helpful. Either way, well done on making these.
     
    • Like Like x 1
  15. OP
    GoldBl4d3

    GoldBl4d3 VIP VIP Retired

    Messages:
    3,778
    Ratings:
    1,345
    Thanks for the kind words, but I will not be continuing.
     
  16. Ressko

    Ressko Getting There

    Messages:
    2,014
    Ratings:
    476
    That sucks. :frown:
     

Share This Page