Learn windows phone7 development together (. XNA application in Silverlight)

Source: Internet
Author: User

XNA is another framework of WP7. It is mainly used to develop games, but it also has some features that can be used in Silverlight to make up for some functions not available in Silverlight. To enable XNA to be used in silverlight, you must first simulate the XNA framework.

You can use DispatcherTimer to simulate the Update in the XNA framework.

DispatcherTimer dt = new DispatcherTimer ();

Dt. Interval = TimeSpan. FromMilliseconds (33 );

Dt. Tick + = new EventHandler (dt_Tick );

Dt. Start ();

Void dt_Tick (object sender, EventArgs e)

{

Try

{

FrameworkDispatcher. Update ();

}

Catch

{

}

}

I. Audio: It is generally used to play some very short Audio in wav format. However, MediaElement is also used for playing in Silverlight. Therefore, you can use Audio in XNA to play the Audio effects of these text messages. You need to read the audio file stream into the memory for playing. Set the value range of SampleRate in SoundEffect (8000-48000Hz)

SoundEffect sound = new SoundEffect (Stream. ToArray (), 8000, AudioChannels. Mono );

SoundEffectInstance inst = sound. CreateInstance ();

Inst. Play ();

II. music: In silveright, The MediaElement control is also used to play mp3 music. However, it is not appropriate to use it as background music, therefore, the Song and MediaPlayer classes provided by XNA can be used to load and play background music, which is also well controlled.

Song song = Song. FromUri ("Kalim", new uri(?kalimba=", UriKind. Relative ));

MediaPlayer. Play (song );

3. Microphone is used to record sound in silverlight.

Using Microsoft. Xna. Framework. Audio;

_ Microphone. BufferReady + = new EventHandler <EventArgs> (_ Microphone_BufferReady );

_ Microphone. GetData (buffer );

_ Microphone. Start ();

_ Microphone. Stop ();

Iv. Input: for the Input modeLearn WP7 XNA togetherGame Development (Iv. Input)As described in detail, in silverlight, The XNA method can only use touch and gesture, but cannot be obtained for the keyboard, so it can only be obtained using the event method.

I. Touch: The status is also very small, only Move, Press, Release.

TouchCollection touchState = TouchPanel. GetState ();

Foreach (TouchLocation location in touchState)

{

Switch (location. State)

{

Case TouchLocationState. Pressed:

Break;

Case TouchLocationState. Moved:

Break;

Case TouchLocationState. Released:

Break;

}

}

3. gesture: different applications can be triggered by different actions on the screen by hand. The touch is very similar, but it is much more than its status and needs to be specified.

TouchPanel. EnabledGestures = GestureType. FreeDrag; // This parameter must be set before a gesture is specified. Otherwise, an error is reported.

If (TouchPanel. EnabledGestures! = GestureType. None)

{

Switch (TouchPanel. ReadGesture ())

{

Case GestureType. Tap:

Break;

Case GestureType. DoubleTap:

Break;

Case GestureType. FreeDrag:

Break;

Case GestureType. DragComplete:

Break;

Case GestureType. Flick:

Break;

Case GestureType. Hold:

Break;

Case GestureType. HorizontalDrag:

Break;

Case GestureType. None:

Break;

Case GestureType. Pinch:

Break;

Case GestureType. PinchComplete:

Break;

Case GestureType. VerticalDrag:

Break;

}

}

}

Sample download: http://www.52winphone.com/bbs/viewthread.php? Tid = 32 & extra = page % 3D1

Related Article

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.