Silverlight C # Game Development

Source: Internet
Author: User

In the previous section, we basically finished building a Silverlight3D world. Now we only need some logic and code to complete the game. Now I will add the last part: skyBox ). Speaking of the sky box, friends who have learned D3D before must be familiar with it. In fact, they are actually six-sided boxes. The illusion of pivoting is a spherical shape.

 

I can think about it. There are 6 images that can combine closed spaces. So I first prepared the above image and borrowed 6 standard SkyBox images from other places, for SkyBox images, you can ask a 3D artist for help or use network resources. In addition, there are some software dedicated to making SkyBox.

First, you need to prepare images and add them to the project.

For convenience, I will not build a large independent control this time, but will directly obtain the class I have previously written through inheritance:

 

Public class Lesson09: Lesson04
{
Public Lesson09 ()
{
}
}

 

 

For more information about Lesson04, see Silverlight C # Game Development: L4 model groups and simple animations.

We will complete the following results:

 

After the inheritance is complete, you need to make some minor changes to the lesson04 class, such as the Execution. game gives protected the execution method of the DispatcherTimer Tick event, which helps Lesson09 write less code.

Public class Lesson09: Lesson04
{
Public Lesson09 ()
{
// Create a sky box
Skybox skybox = new Skybox ();
// Specifies the texture in six directions of the sky box
Skybox. Back = new ImageMap (Runtime. Instance. ContentManager. Load <Balder. Imaging. Image> ("/Balder_Studio; component/SkyBox/cloudy_noon_BK.png "));
Skybox. Bottom = new ImageMap (Runtime. Instance. ContentManager. Load <Balder. Imaging. Image> ("/Balder_Studio; component/SkyBox/cloudy_noon_DN.png "));
Skybox. Front = new ImageMap (Runtime. Instance. ContentManager. Load <Balder. Imaging. Image> ("/Balder_Studio; component/SkyBox/cloudy_noon_FR.png "));
Skybox. Left = new ImageMap (Runtime. Instance. ContentManager. Load <Balder. Imaging. Image> ("/Balder_Studio; component/SkyBox/cloudy_noon_LF.png "));
Skybox. Right = new ImageMap (Runtime. Instance. ContentManager. Load <Balder. Imaging. Image> ("/Balder_Studio; component/SkyBox/cloudy_noon_RT.png "));
Skybox. Top = new ImageMap (Runtime. Instance. ContentManager. Load <Balder. Imaging. Image> ("/Balder_Studio; component/SkyBox/cloudy_noon_UP.png "));
// Activate the skybox. It is not displayed if it is not activated.
Skybox. IsEnabled = true;
// Specify
Game. Skybox = skybox;
}
Double _ sin = 0;
// Rewrite the Timer animation in Lesson04
Protected override void _ dispatchertimer_Tick (object sender, EventArgs e)
{
// First execute the original
Base. _ dispatchertimer_Tick (sender, e );
// Determine whether a camera exists
If (game. Camera = null)
Return;
// Calculate the values of x, y, and z based on the Sin curve to view the TargetPoint of Camera.
Var x = System. Math. Cos (_ sin) * 250;
Var y = System. Math. Sin (2 * _ sin) * 250;
Var z = System. Math. Sin (_ sin) * 150;
Game. Camera. Position. X = x;
Game. Camera. Position. Y = y;
Game. Camera. Position. Z = z;
// Change
_ Sin + = 0.016;
}
}

The above code completes the addition of the sky box. If you know the previous content, it looks very easy :)

Click to download the project view and test. The running effect is as follows:

 


If Balder. dll is missing in the project, download it quickly here: SL4_Balder.rar

We recommend the Silverlight game development blog:Dark blue right hand

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.