i just started developing in xna and c#, and it would have been a whole heck of a lot easier on me if somebody just pointed out the basics
it would have saved a lot of frustration, but would have gotten rid of the 'fool's gate' of getting the process started, so some experienced users are bound to find this post offensive
anyway, there was no really simple thing on how to get started totally from scratch
all i had was a new pc with vista home whatever installed on it
so here's a quick breakdown of the basics the way i do it - some will hate this and puke
old school style;
i am an 'old school' programmer, hence i like small, light and fast rather than big and heavy
this style isn't for playing around and trying things out, this is for getting out a working product fast and furious
this style focuses on producing content for the xbox 360 by first developing a working version on windows then creating a copy for xbox 360 and rebuilding and deploying via creators club
xna and c# suit me and my style of small, light and fast
some people really hate the way i program
i code in straight xna and c#, using other tools only to help me along the way, doing multiple passes of the tools to get all i need
i hate toolchains but so far i don't mind using them individually if they produce something i need out of a file they make
i use torque x builder for layout, then steal the positions and other info from the xml level file and hardcode them into the c# code
i hate the c# compiler's folder system, but its not worth the time to fix it, so i just run with it
i hate programming rules, but i love best practices and try to follow the windows ones, and if you don't follow best practices on the 360 it will hang up or crash
i hardly ever comment my code - the code is comment enough of you understand it properly, which you should begin to remember and understand after a few programming sessions
i prefer one big code file rather than a bunch of little ones
i sometimes write my code in notepad or wordpad rather than the ide, and then start up the ide to compile it, feels like the old days compiling and linkimg masm
i follow the path of the snake climbing the tree and i duplicate my code ruthlessly to do what i want, not make reusable code, and if i need something from old code i cut and paste
a one space indent is just fine by me
scary, ain't it!
bare bones installation vista home whatever:
all of these are free downloads, and be sure to register them so they don't time out
m$ visual studio 2005 c# express (not 2008 - not supported by xna game studio version 2 as far as i can tell, maybe xna 3.0 is for 2008, but 2005 works just fine)
xna game studio express version 2
working, networked xbox 360 with a hard drive
working developers wired 360 controller
xbl gold membership
xna creator's club membership
on the xbox 360 download the launcher and connector from the game store, genres, other, creators club and successfully start them once
exorcise the system
start the ide and choose new project from the file menu
single-click only on the windows project
change the name to windowsbase
change the folder to the desktop
it will create the project folder on the desktop when you hit ok
close the ide and open the folder, double-click on the sln file
you may have to get fista to start m$ vs c# ide when you double-click on it by using browse
go through every menu in the ide, familirize yourself with what they do,and be sure all folder settings are pointing to this folder we are woking in, especially build and import stuff
use the project configuration menu to set your base info like copyright and author
test project build and fix any errors or weirdness
hit play to run it on the computer - it should be a blank blue screen and quits when the back button is pressed on the controller and that's it
i call it the 'select' button, but they call it 'back' and that is what it actually says on the 360 controller if you look close
open and view the game1.cs file in the ide code window from the solution explorer
add a image file to contents from the solution explorer by right clicking on contents and add exiting - choose some small image file to load
make sure the image file appears and it copies it to the contents folder ok - use right click on it and remove it
this is your base program, so be sure all is correct - it needs to be running right with no crashes, error or even warnings
'save all' the project
close the ide and make a copy of the folder - name it something 360base
open the ide with the 360base folder's .sln file
create a copy of the solution for xbox360 under project
delete the windows part - make this one for 360 only
set up the xbox device connection and make sure the 360 can connect to the computer and it gets the program
build, deploy and test the xbox version
fix any weirdness and make this .sln your 360base
copy both base projects somewhere safe as backups
choose a project name or working title
don't sweat it and get bogged down on this step
you can rename the final project later with some cool name
just choose a one word name and run with it
use the ide to create a windows project folder with the project name on the desktop
right in front of your eyes and foremost your mind
create a txt file in the folder somewhere - this is the pre-production project breakdown file
name it [the project name].txt and start editing it before doing anything else
pre-production project breakdown file
since we are developing a 360 product, we have to define what the product actually is
to quickly do this i use a pre-production breakdown text file to flesh out the product before even writing the first line of code or drawing the first sprite
the biggest game is just another computer program, with a basic flow from start to end, some variables and control structures to modify the flow based on stuff happening
the 360 is just a computer with a fancy graphics card that runs a program from start to end and shows sprites and controls them via what we tell it to do
the idea is to lay out your ideas in the txt file and see what's what and determine what you really want and can actually do
proper code is not important here, but if you have the code already or are pulling it from here and there, just drop it in the breakdown file
think like a composer writing a song on the back of a napkin - only you need to know what stuff means
develop the program, not from inside the language, but from outside and the overview
don't think about the whole program but think what you want on the screen and build up your whole sprites list
if there are multiple screens or multiple levels, start small with just one screen and detail them each separately, duplicating whatever is needed to do them
finally break down the program into the structure that xna uses: startup, levels, sprites, setup, load, show, contol, unload and end
if you just use load content struff, you don't have to worry about unloading it, the content manager does it for you
if you load anything into the program without using the content manager, like arrays or something, wipe it using unload before ending or you will pile up junk in memory
just do the setup that xna needs and don't worry about it for now, focus on what you want the program to look like
the best tool is a piece of paper and a pen - draw out the screenshots you want to be able to do later, then figure out what you need to have in the program to make them happen
the sprites list is all the sprites that are ever going to be on the screen throughout the whole entire program
you'll need to determine where they will be placed on the screen, then load them all at the start oif they are not too huge
this is setup, then load - if you do it all at the beginning, say during a splash screen, it won't bog down the user experience later
starting with a single level, detail out each section
as you work with xna and the xna structure, you can find what you need on the internet - best i have found so far is:http://msdn.microsoft.com/en-us/library/bb194908.aspx
materials (artwork)
after working the breakdown file for awhile, you'll start to get a fairly good idea about the artwork (textures) you need for the sprites
2dsprites are just flat one-sided 3dsprites, and they have just one texture that needs to be loaded for each sprite unless you are going to use the textures on multiple sprites
so far i just create basic shapes in paint then use gimp to flesh them out and finally save them as transparent png's or jpg's
my first program
i chose to do a buttons program for my first one, so i could get the hang of user input and what words xna uses - xna is different than everybody else, but simpler in the end
it is very easy to get bogged down in the xna object model and overcomplicate things - keep it simple stupid (kiss) rule applies here
i want just a dumbo program to show a xbox 360 controller picture on the screen and flash the buttons when they are clicked
in this case there should be a good controller pic somewhere on the internet that's not copyrighted that shows all the buttons, the sticks and the triggers
to use the picture, i loaded it into paint and cut out the buttons, the triggers and the sticks, lighting them up and saving each as separate image file
create the jpg's for each sprite and one for the controller with nothing highlighted - these will be the images that you will add into content and load into the sprite textures
using buttons.txt;
game overview
show the pic of a 360 controller with buttons that highlight, driven by the buttons and sticks on the controller
template
windowsbase
materials
texture jpg images
if your artwork is named differently its no problem, just fix when you load it in the load
controller sprite - an image of a 360 controller
Controller.jpg
button and stick sprite texture jpg's - individual sprites for each of the controller buttons and the sticks
X
B
A
Select.
L1.
L2.
L3.
R1.
R2.
R3.
Start.
do buttons
draw the sprites over the controller buttons when they are clicked
setup
think: define the sprites
Texture2D ControllerTexture;
button and stick sprites - individual sprites for each of the controller buttons and the sticks
Texture2D YTexture;
Texture2D XTexture;
Texture2D BTexture;
Texture2D ATexture;
Texture2D SelectTexture;
Texture2D L1Texture;
Texture2D L2Texture;
Texture2D L3Texture;
Texture2D R1Texture;
Texture2D R2Texture;
Texture2D R3Texture;
Texture2D StartTexture;
etc...
load
think: you've define the sprites, now load the textures for them
ControllerTexture = Content.Load<Texture2D>("controller");
ATexture = Content.Load<Texture2D>("a");
YTexture = Content.Load<Texture2D>("y");
etc...
sprite positions
xna uses a Vector2 which is x and y in one go
if the sprite needs to be moved, you do that in update
this is in screen coords in pixels from top,left to bottom right of the 800 * 600 screen
think: define the sprite, load the texture for it, set where it will be on the screen
Vector2 ControllerPosition = new Vector2(200f,200f);
Vector2 APosition = new Vector2(488f,342f);
update (runs every few milliseconds - don't bog it down with a lot of long code)
draw (runs every few milliseconds - don't bog it down with a lot of long code)
if the buttons are pressed, draw the button's sprite at the button's position
the color is the alphablend or transparent mask - leave white unless you need to change it
sprites are drawn in batches, signified with a batch start and batch end statement - all your draws must be between them
spriteBatch.Draw(ControllerTexture, ControllerPosition, Color.White);
if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed) spriteBatch.Draw(ATexture, APosition, Color.White);
and that's it
an upgraded version of the buttons360 project will be available at: buttons360.zip with more stuff than just showing the buttons, like doing text and following the sticks and triggers
i did copyright the code, so don't bite me and say its yours, but you are free to use it to learn how xna handles the controller stuff
the controller image is not mine and i just saved it off the xbox 360 help site - thanks m$
enjoy!
gina (radlogic)
radlogic@live.com
radlogicgames@live.com