建立一个Windows Phone 7益智游戏 附源代码

介绍

 现在我们用Windows Phone 7创造一个益智游戏,使用Silverlight和XNA框架音频API的功能。

    

入门

安装WP7的工具

安装vs 2010 

安装程序将自动下载并安装所需的组件。

如果你想使用的Expression Blend 4 WP7的拓展,下载并安装Expression Blend 。

一旦安装过程完成后,重新启动Visual Studio 2010中。

游戏界面

这是主要的用户界面 ApplicationPage。当你创建一个新的 Windows Phone 应用程序 这是默认的代码。

PageOrientation

Windows Phone应用程式的托管应用程序中的一个最明显的影响之一是如何与之设置的布局方向, ApplicationPage有一个可设置的属性命名SupportedOrientations。该枚举值可以是横屏或PortraitOrLandscape的。分配给它一个值,无论是在XAML或代码中,我们可以控制应用程序如何能变换。 

SecurityCritical是大多数Silverlight开发人员熟悉的属性。 

请注意,这是Silverlight的安全,并没有具体到 Windows 手机。 

<TextBlock Visibility="{Binding ElementName=Page, Path=PageOrientation, 
    Converter={StaticResource OrientationToVisibilityConverter}, 
				ConverterParameter= Landscape}" .../>
 
public object Convert(object value, Type targetType, 
		object parameter, CultureInfo culture)
{
	var orientation = (PageOrientation)value;

	string showWhenOrientation = parameter.ToString().ToLower();
	bool show = false;
	switch (orientation)
	{
		case PageOrientation.Portrait:
		case PageOrientation.PortraitDown:
		case PageOrientation.PortraitUp:
			show = showWhenOrientation == "vertical";
			break;
		case PageOrientation.Landscape:
		case PageOrientation.LandscapeLeft:
		case PageOrientation.LandscapeRight:
			show = showWhenOrientation == "landscape";
			break;
	}

	return show ? Visibility.Visible : Visibility.Collapsed;
}

使用XNA Framework的音频API

我惊喜的是我们可以容易的使用XNA框架来播放音效。需要即时播放。被警告,但它有挑剔的格式。我发现,只有PCM格式的WAV文件提供了支持。我用GoldWave保存所有到PCM格式的音频。对于较长的片段,如果用MP3,更有意义,但你需要使用MediaElement控件。

所有的声音效果在MainPage.xaml.cs中的代码定义旁边以下摘录演示:

readonly SoundEffect footStepSoundEffect = 
	SoundEffect.FromStream(TitleContainer.OpenStream("Audio/Footstep.wav"));


好了,由于时间关系,后面我们会慢慢分析后面的实现方式,以及相关技术。不过这次将放出所有源代码
该文章同步发布到codewp7 卤面网  wp7开发论坛:  http://www.codewp7.com/forum.php?mod=viewthread&tid=123&extra=

源代码请猛击这里



原文地址:https://www.cnblogs.com/sonyye/p/2367215.html