Balder 3D Development Series-first encounter with Sprite

Source: Internet
Author: User
1. Balder
 

Balder is an open source 3D graphics engine that supports Silverlight, Windows Phone 7, xNa and OpenGL.

It is as follows:

Http://balder.codeplex.com/releases/view/53579 before getting in touch with Sprite this time, you have to download it first (assuming you haven't downloaded it yet :))

Why use it? Because currently, 3D is not supported in silverlight4, we should use it for the moment. Besides, it is really good. If it is not used, it will be a waste. If it is not used, I am sorry for the author.

The last Balder developed 3D map: http://maps.esri.com/sldemos/terrainmap/default.html

Of course, in the near future, Silverlight 5 will have its own 3D API. At that time, Silverlight developers will have another option. How happy it is. Well, I will not talk much about it, and so on... I almost forgot. Finally, I recommend a good blog about Balder: nowpaper.

 

Ii. Sprite classes

 

It is located in the namespace of Balder. Objects. Flat.

Inheritance hierarchy:

System. Object
System. Windows. dependencyobject
System. Windows. uielement
System. Windows. frameworkelement
System. Windows. Controls. Control
System. Windows. Controls. itemscontrol
Balder. Node
Balder. hierarchicalnode
Balder. renderablenode
Balder. Objects. Flat. Sprite
From this, we can see that it is closest to itemcontrol.

Let's take a look at its definition:

Namespace Balder. Objects. Flat
{
Public class sprite: renderablenode, iasset
{
Public static dependencyproperty <Sprite, Uri> assetnameproperty;

Public sprite ();
Public sprite (icontentmanager contentmanager, ispritecontext spritecontext );

Public URI assetname {Get; set ;}
Public Image currentframe {Get ;}

Public iassetpart [] getassetparts ();
Public override void prepare (viewport );
Public override void render (viewport, detaillevel );
Public void setassetparts (ienumerable <iassetpart> assetparts );
}
}

The most common use of Sprite is to use it to load and display an image, and then operate it through animation, deformation, and so on. As it means, Genie, if you have read the deep blue article, you can easily understand it. in 2D games, a Sprite mainly consists of: image, a vector, this Sprite in the Balder is similar to other first-off information. The difference is that it is a Sprite defined in a three-dimensional coordinate system, z) to determine its position in the three-dimensional space. As for its other attributes and methods, it will be used in the future. Today we mainly use the assetname attribute to complete a small instance.

 

3. A small example to understand the basic creation method of Sprite

 

First of all, add reference to the downloaded Balder DLL file to the Assembly, how to operate and about the basic structure of the Balder please refer to: http://www.cnblogs.com/nowpaper/archive/2010/11/05/1869705.html here to write very detailed, I will not be too long.

After completing the above steps, you will start to work.

Open the mainpage. XAML file and add the following at the beginning:

 

Then we start to construct a Sprite example:

<Execution: Game width = "640" Height = "480">
<Execution: game. Camera>
<View: Camera X: Name = "camera" position = "120,-" target = ", 0"/>
</Execution: game. Camera>

<Lighting: omnilight position = "-100,100, 0"/>
<Geometries: Box Dimension = "20, 20, 20" interactionenabled = "true"/>
<Flat: SPRITE position = "-50, 0, 0" assetname = "/spritetest1; component/assets/sprite.jpg"/>
<Flat: SPRITE position = "50, 0, 0" assetname = "/spritetest1; component/assets/sprite.jpg"/>
<Flat: SPRITE position = "0, 0, 50" assetname = "/spritetest1; component/assets/sprite.jpg"/>
</Execution: Game>

 

 

Game is a scenario class. We put the following things into this scenario: light (light) camera (CAMERA), box (cube box), three sprite (genie ). In fact, there are not many things, because everything is composed of very similar attributes. For example, the position is a coordinate of (x, y, z). Is it easy to understand? The other difference is that there is an interactionenabled = "true" on the box side. This allows the box to be rotated with the mouse. Sprite has a different assetname attribute. In fact, it is a URI, But it implements a type conversion from URI to image. In this way, you only need to enter the URI of the image to get the corresponding image. Therefore, you must import an image to the project in advance.

Finally, we are implementing some animation effects. Here we can achieve the animation by changing the position of camera. Can you imagine? If you take this camera to take a picture of the outside, as long as the camera moves, then some items or things you take will change. Are they actually moving? Of course they are moving, because the earth is moving (hahaha ~).

Okay. Let's see what you add.

 

<Grid. triggers>
<Eventtrigger routedevent = "grid. Loaded">
<Beginstoryboard>
<Storyboard autoreverse = "true" repeatbehavior = "forever">
<Doubleanimation storyboard. targetname = "camera" storyboard. targetproperty = "(camera. position ). (x) "from ="-100 "to =" 100 "Duration =" 00:00:05 ">
<Doubleanimation. easingfunction>
<Elasticease/>
</Doubleanimation. easingfunction>
</Doubleanimation>
</Storyboard>
</Beginstoryboard>
</Eventtrigger>
</Grid. triggers>

 

 

 

Finally, let's see how it works:

 

 

:)~~~~~~~

 


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.