弹来弹去跑马灯!

WP 一个判断角度的场景

准备写个WP版打小鸟的游戏。
当鼠标点击屏幕的时候要炮火方向旋转的角度适应点击的角度;

如图:

逻辑代码:
double stageHeight = 60;//炮底座高度
Point touchPoint = new Point();//记录点击是点坐标
Size PanelSize = new Size();//保存舞台的大小
private void ContentPanel_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
PanelSize = ContentPanel.RenderSize;
touchPoint = e.GetPosition(ContentPanel);
//弧度转角度:除以Math.PI乘以180
double res = 0;
if (touchPoint.X >( PanelSize.Width/2))
{
res = Math.Atan(((PanelSize.Height - stageHeight - touchPoint.Y) / ( touchPoint.X- PanelSize.Width/2))) / Math.PI * 180d;

t1.Rotation =(90- res);
}
else
{
res = Math.Atan(((PanelSize.Height - stageHeight - touchPoint.Y) / ( PanelSize.Width / 2- touchPoint.X))) / Math.PI * 180d;

t1.Rotation = -(90d-res );
}

txt.Text = "" + res;//弧度抓角度:处以Math.PI乘以180

}


AXML代码
<phone:PhoneApplicationPage
x:Class="Birds.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">



<Grid.RowDefinitions>


</Grid.RowDefinitions>





<Rectangle.RenderTransform>

</Rectangle.RenderTransform>

<!--取消注释,以显示对齐网格,从而帮助确保
控件在公用边界上对齐。图像在系统栏中显示时的边距
上为 -32px。如果隐藏了系统栏,则将此值设为 0
(或完全删除边距)。

在发送之前删除此 XAML 和图像本身。-->

</phone:PhoneApplicationPage>

posted @ 2015-11-25 21:52  wgscd  阅读(155)  评论(0)    收藏  举报