简单的Windows Phone应用程序

时间:2015-03-05 08:58:49

标签: windows-phone

我想创建一个简单的Windows手机应用程序,它有一个球弹跳。是否有机会在不使用XNA的情况下创建此应用程序?

感谢。

2 个答案:

答案 0 :(得分:1)

当然,你可以使用XAML来做到这一点。在画布上创建一个球。然后使用Canvas.LeftCanvast.Top属性更改其位置。创建DispatcherTimer以获得游戏循环

<强> MainPage.xaml中

<Canvas>
    <Ellipse x:Name="MyBall" 
             Width="64" 
             Height="64" 
             Fill="Red" />
</Canvas>

用计时器更改球的位置(下面的代码)。

<强> MainPage.xaml.cs中

// Your "game loop" timer
DispatcherTimer timer;

// Ball position
int x = 0; 
int y = 0;

public MainPage()
{
    InitializeComponent();

    timer = new DispatcherTimer();
    timer.Tick += OnTimerTick;
    timer.Interval = TimeSpan.Zero; // It's about 60 fps
    timer.Start();
}

// This is your "game loop", where you can change things, move, animate, etc.
private void OnTimerTick(object sender, EventArgs e)
{
    // Change ball position
    x++;
    y++;

    // Apply new position
    Canvas.SetLeft(MyBall, x); // Set x
    Canvas.SetTop(MyBall, y); // Set y
}

答案 1 :(得分:0)

你可以使用Codeplex的Physics Helper Xaml来做到这一点:

https://physicshelperxaml.codeplex.com/

这里有一些较旧的例子,使用较旧版本的库在silverlight中执行它可能很有用:

http://channel9.msdn.com/coding4fun/articles/Creating-a-Pinball-Game-in-Silverlight-Using-the-Physics-Helper-Library--Farseer-Physics