Sign in to follow this  
The_Game

XNA programming help

Recommended Posts

As the title says I need some help with programming with XNA. I remembered that months ago I actually signed up for this site but never used it. Now that I'm tired of being bored and wasting most of my time, I've decided to actually try programming something. I'm not sure if this is the right place to post this, but it's the XNA board so I figured it was a good place to start. I've used XNA before. I had a class in college where we used it and we did several projects with it (just last semester I think). To see how much I learned and to see if I was actually making any progress in learning what I need to know for the career I'm shooting for I decided to try to make a crude video game that was a completely indepedent project, unlike just replicating the projects in the books like I did in school. I planned to make a Mega Man rip-off just to see if I could do it. By looking at my old projects, reading the book and taking some snippets of code from my old projects I understood I managed to take a .png file with Mega Man X sprites and get them to appear on the screen. Now what I want to do is make it so that I can move the image on the screen by pressing the arrow keys, that where I'm stuck. I know the code for putting in controls goes like this: KeyboardState keyState = Keyboard.GetState(); if(keystate.KeyIsDown(Keys.Left)) { //This is the area where I don't know what to put in to get it to do what I want! } Sorry for the long post and perhaps sounding agitated, but I've been trying to do this for half the day and I still can't figure out how to do it! I've tried reusing code from other projects to get the results I want but none of them get the job done for this particular case! Any help would be appreciated, thanks.

Share this post


Link to post
Share on other sites
Change the position variables for your image. You'd subtract from the x on left, and add to it on Right.

vector2 Position;

Position.X -= Whatever;
Position.Y += Whatever;

Then in the drawing code, you draw your image at Position.

SpriteBatch.Draw(image,Position,Color.White);

Share this post


Link to post
Share on other sites
I'll jump in here for a little shameless self-promotion. I wrote up a nice beginners tutorial for making a Space Invaders-ish game that you can get from here. I also made a bunch of video tutorials for working on a tile-engine based game which you can find here. I'd suggest starting with the Space Invaders-ish game if you are still getting the hang of things. It's literally a start-to-finish "how to make a game". Hopefully between that and what you already know you'll be able to start making the game you really want to make.

Share this post


Link to post
Share on other sites
The thing is, I've actually worked on games in the past where it involves a player moving so object. I've got one for pong, I got one that rotates the ship and I got one for a top-down scroller (like those old Raiden games). Nothing I take from those works with what I'm trying to do.

I don't know if I gave enough information. I'm taking a rectangle that's part of a larger and putting it on the screen. The Top-down scroller game has some lines that seem to work:

Vector 2 delta = Vector2.Zero

in the later code I put in

delta.X = (float) (-player.MovePixelsPerSecond * elapsed)

That's like what Daaark is telling me. But when I put in the variable for the rectangle that holds the image for my guy it won't accept it. I tried doing it like this (m_texGuy is the rectangle I'm using):

m_texGuy -= m_texGuy.X

I don't think that file Nick gave me is going to work on this crappy PC I have here. I'm doing the programming on a laptop I'm leasing from school.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this