XNA Creators Club Online

beginner's guide

2D Lessons

1 Introducing the 2D Tutorial
2 Creating the Game Project
3 Adding Assets
4 Drawing the Background
5 Creating a Cannon
6 Firing Cannonballs
7 Adding Enemies
8 Destroying Enemies
9 Keeping Score
x Extra Credit - Community Tutorials

5. Creating a Cannon

Create a class to hold your game data and create your first game object - a player-controlled cannon that takes Xbox 360 controller or keyboard input.

Step 1

Watch Video
Create a new GameObject class that defines your in-game objects, and create a cannon GameObject.
More Details

Step 2

Watch Video
Use the GamePad and Keyboard classes to take input to rotate the cannon, and clamp the input with MathHelper to keep it within bounds.
More Details

Step 3

Watch Video
Use an overloaded version of SpriteBatch.Draw to draw the cannon rotated based on player input.
Download source code
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG