XNa advanced programming: Xbox 360 and Windows 2-4/2-5

Source: Internet
Author: User


2.4 try on Xbox 360

Now, the game has been completed and many tests have been conducted on the Windows platform. As I explained in chapter 1, it takes several key steps to configure and run the xNa framework on Xbox 360. If the xNa game launcher on Xbox 360 has been started, you can try to compile your xNa pong game and deploy it on the console.

Important to Xbox 360:

  • Do not use any external DLL unless necessary-- Although xNa game dll can be used, most DLL files on Windows platforms call windows system DLL files, which cannot be used on the Xbox 360 platform, furthermore, for security reasons, the Xbox 360 platform does not support the use of pointer (p-invoke) to call Unmanaged DLL files. In addition, do not use non-securityCodeIt is a waste of time to try to call external code, access devices, or use unsupported features.
  • Don't wait with the testing-- If you change the output settings to Xbox 360 during development, you need to test whether your code can be compiled properly, because many of the methods you use do not exist on Xbox 360. For example, there is no tryparse method in the dynamic library system. dll on Xbox 360, and some xNa methods and classes (such as the mousestate class) are not supported at all and do not exist.
  • Do not load content directly-- On Windows, you can directly load textures and shaders with texture2d or compiledeffect constructor. On Xbox 360, these methods do not exist. You can only use content pipelines to load content. If you use dynamic loading or reload textures and shaders code, they only work on Windows platforms, so they are built for Xbox 360ProgramUse the flag # If! Xbox 360... # Endif include the code.
  • Save the game and load other content-- To save the game, you can use the content namespace and many other helper classes. With storagecontaine. titlelocation (this can also be used on Windows platforms, and the output folder is used) to load content. You must always ensure that the correct path is used, loading from other locations in Xbox 360 causes Access Denied exceptions.
  • Test resolution-- The Xbox 360 supports resolution solutions on many PCs, so you must test at least two or three solutions to ensure that the game can run properly.
  • Allow gamepad to operate everything-- Most xNa games I have seen make a mistake in that they only support keyboard input or gamepad input, this means that they can only run on windows, or on Xbox 360. Supporting enough devices makes sense for your game.
  • Debug and unit test on Xbox 360-- There is no difference between debugging and unit testing on the Xbox 360 console and Windows platform. You can use the same rules. It may be difficult to track errors and record error information, but xNa can still be used for single-step debugging and test unit testing. Make good use of this. By the way: on the Windows platform, if the code is modified during debugging, it can still be executed, but it cannot be used for Xbox 360 games. This is unpleasant, but you generally complete major development on the Windows platform.

This xNa pong game always takes into account the Xbox 360 when coding, and all the methods and features you use are supported on the Xbox 360. Therefore, testing this game on Xbox 360 is not a big problem. You can directly deploy it and then run it, as shown in Figure 2-11:
Figure 2-11

2.5 challenge: improve your pong game

Now it's your turn to make some improvements to the game. You can change the picture or sound or adjust the gameplay. If you have gamepad, you can also add rumble support, and if you read this book, you should indeed have a gamepad controller, even if you do not have Xbox 360. Many xNa games require the Xbox 360 controller, and some games use the Xbox 360 controller to be more fun than the keyboard.

The following code adds rumble support to gamepad:

Gamepad. setvibration (playerindex. One, leftrumble, rightrumble );


When the ball hits the racket, use the above Code to shake the Controller for a while (leftrumble and rightrumble use the same value, so that the entire controller will shake ). When a player loses his or her life, he or she can also shake it for a long time and shake it strongly.

You can view the sample projects in this chapter to see the challenges and solutions. Your challenge solution does not need to be the same as this, but it is helpful to take a look. Maybe you can learn how to solve a specific problem in a simpler way.

Enjoy your xNa game!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.