Why use xna game studio




















Happ adds: "Because all of the code is open source, if it doesn't do something you want, you can just change it. It isn't locked behind some corporation so there's no danger that it will disappear the way XNA did. It's worth mentioning at this point that MonoGame Team isn't a company, but a non-profit, all volunteer organisation that relies on donations.

MonoGame's current project leads are Tom Spilman, co-founder of developer and porting house Sickhead Games, and veteran developer Steve Williams, currently specialist manager in consulting at Deloitte Digital.

MonoGame is the perfect framework for coders, with C allowing for rapid iteration, making it easy to prototype and get projects running quickly -- should you have that C experience, of course. My experience with Unity is very limited, but I've heard horror tales of Unity updates breaking Asset Store items during crucial crunch periods. Major continues: "For us, the strength of MonoGame comes with its fast iteration process thanks to C.

The fact that it's very lightweight is also a plus. We are the owners of all these systems. If anything doesn't run right, chances are it's our fault and we do have the power to fix it ourselves. We never wait on a partner to solve it for us or need to work around the shortcomings of an engine.

With C being a common programming language, recruitment is quite easy if you make a game using MonoGame -- and we can thank Unity for that.

Some of MonoGame's weaknesses will be obvious if you've read the previous section. The first thing is that it doesn't handle 3D very well -- that doesn't mean it can't, but if your project is in 3D you should probably be looking into Unreal , Unity or even CryEngine instead of MonoGame. If you're looking into starting your first project and you don't have a lot of experience, it's likely MonoGame is not really the engine for you. You can get going if you have a minimum understanding of C , but if you don't and your project is in 2D, GameMaker will more likely be a good fit for you.

MonoGame requires a lot of building upon. You have no tools or pre-built game components. This can be very daunting to someone just starting out and can slow your process of getting up and running with your first project. Happ continues: "It is definitely more geared towards people who can program their own thing. Because MonoGame finds its roots in XNA, which has been retired for almost seven years, online resources are scarce.

There is a small but strong online community of MonoGame developers more on that below but few official resources. MonoGame experts are also quite under the radar. Since they work documentation-less through a decade of practice, they don't disseminate that much knowledge. You can find some documentation on this page , but don't expect official support.

Since it's not a paid engine or service I don't think there's any customer support, so you need to go into things understanding that. While Happ reckons recruiting experienced MonoGame developers is essentially as simple as finding C coders, some of our interviewees believe it's actually not so easy.

Another topic about which our respondents were in disagreement is how quick it is to get something working with MonoGame. To begin gathering user input from the keyboard correctly you will add some new class-level objects to the game.

Add the following code to the beginning of the Game1. You will query what keys are pressed and what keys are not being pressed at a given point in time.

The KeyboardState object you created will store the previous state of the keyboard so you can check to see if a key that the user is currently pressing was pressed last time you checked the state. This allows you to do things like enforce that the user must release a key before an action is taken again.

That is where the mPreviousKeyboardSate comes into play. The second object, the integer, stores how far you will move the car in the X direction. Add the following line of code to the StartGame method. You want the car to switch lanes when the user presses the Spacebar and you want to make sure they have released the Spacebar before you move it again. Add the following lines of code to the Update method. This code starts off collecting information about the current state of the keyboard. Next, it checks to see if the user has pressed the Escape key.

That indicates that the user wants to exit the game. Now using that information from the current state of the keyboard, you then check to see if the Spacebar has been pressed and that it was not pressed since the last time you checked this prevents the user from holding it down to continually switch lanes.

If the user pressed the Spacebar, then you move the car between the lanes by changing its current X position. Finally, you store the current state of the keyboard in the mPreviousKeyboardState object for use next time through the Update method.

Go ahead and build the project again. When you press the Spacebar, the car should move between the lanes as it zooms along the scrolling road. Similar to keyboard support, you can easily add gamepad support to your game for any wired Xbox or wireless with the appropriate dongle adapter controller. To begin gathering input from the gamepad correctly, you need to add some more class-level objects to the game. You just need a way to check to see if the user has pressed and released a button on the gamepad.

Now you need to add some code to the Update method to check to see if the user has pressed a button on the gamepad. If so, then exit the game. This code gets the current state of the gamepad then checks to see if the user has pressed the Back button on the controller or the Escape key on the keyboard.

Finally, the code stores the current state of the gamepad in the previous gamepad state object for use next time through the Update method. Go ahead and build the project. You should be able to use your Xbox controller to move the car between the lanes and exit the game.

This code uses the Texture2D object to store the car image and the Rectangle object will hold the size and current position of the hazard on the screen. You now will need to initialize this position, so add the following code to the StartGame method to set the initialize size and starting position for the hazard. Finally, you will need to draw the hazard image to the screen so you will need to add the following code to the Draw method.

Place this code before the SpriteBatch. End but after the road and car have been drawn. Remember that the order in which things are drawn is important. Now you should build the project and verify that your code properly draws the hazard image to the screen Figure 7. The hazards will scroll down through the screen on the road and as they exit the bottom of the screen they will reappear randomly in the right or left lane and repeat the process all over again.

To introduce this randomness, you first need to add a Random object. When working with Random objects in a game, it is useful to typically only make one and use it throughout the entire game. This helps ensure that your randomness is as random as it can be. Initializing multiple random objects can often lead to the same numbers being generated, especially if the random objects were created on similar ticks.

That way it does not look like the hazards just magically pop in at the top. This code will move the hazard down the screen. It will check to make sure the hazard has not moved past the boundaries of the screen. If the hazard has moved past the boundaries of the screen, then this means the player can no longer see the hazard.

When you run the game, you should see the hazards scrolling down the screen one after the other and randomly appearing in the lanes. This game will simply keep track of the number of hazards that the car has successfully passed. The XNA Framework provides a pretty nice way of getting text to display in a game.

To begin the process, you need to add a new item to your project. So right-click on your project and choose Add New Item from the context menu. This will add a new SpriteFont object to your project, which is basically an XML file that gives some information about a system font that you want to use in your game.

The integer object will keep track of how many hazards the player has successfully passed. The SpriteFont object allows you to load a font into the game, which you can use to write text to the screen. The code snippet below will initialize the number of hazards passed in the StartGame method. That way, every time the user starts or restarts the game, the number of hazards the player has passed can reset to 0. Next you need to load the font into the SpriteFont object.

Add the following line of code to the LoadGraphicsContent method. Every time a hazard has scrolled off the screen-criteria for the player successfully passing a hazard-you need to increment the hazards passed counter.

Build the game and check your handiwork. As the hazards scroll off the screen, you should see the number in the upper left of the window display the number of hazards and increase as shown in Figure This brings me to the topic of game state. Game state, in its simplest form, is just a way of keeping track of what state your game is in.

So once again you need to add some new objects to your game class. You want an enum to define the various states the game can be in and an object to indicate which state the game currently is in. Next you need to make sure that when the game starts you initialize the current state to running. Basically you are taking the existing code in the Update method and putting it within a Switch block for the case when the current state is running.

The Keyboard state still remains outside of the block, but has been shown for context. Without collision detection, the game is pretty easy to play. Luckily, adding simple collision detection into the game is fairly easy as well. The XNA Framework has functionality built into the Rectangle objects that allow you to check if another Rectangle object is intersecting them. When a collision does occur, then you need to switch the current game state to Crash.

Once a crash has occurred, the game will be over but you need a way to allow the user to play the game again or exit and you should probably tell them how to do that. Go ahead and add the following code to the Update method. This code replaces the existing UpdateHazard call. This code checks for a collision by using the Intersects method of the Rectangle object. When a collision is detected, the current state of the game changes to Crash to reflect this.

You also want to add the following lines of code within the Crash case of the Switch block within the Update method. If either of them has been pressed then it calls the StartGame method, which will restart the game for the player. Now that the code responds to the various states of the game in the Update method, you need to do the same within the Draw method.

Add the following code just after the line of code that draws the current number of hazards that the car has passed. This code displays some informational text to the player, but only if the current state of the game is Crash. The user then knows how they can exit the game or replay. You now have a functional game. Dictionary Dictionary Term of the Day. Natural Language Processing.

Techopedia Terms. Connect with us. Sign up. Term of the Day. Best of Techopedia weekly. News and Special Offers occasional. XNA Game Studio. Techopedia Explains XNA Game Studio Game development often requires the developers to create code to animate character movements, define interactions and other graphic aspects.



0コメント

  • 1000 / 1000