如何使用Accelerometer进行Windows Phone应用程序? [英] How can I do Windows Phone Application with Accelerometer?

查看:65
本文介绍了如何使用Accelerometer进行Windows Phone应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好;



我正在制作Windows Phone应用程序。但我不习惯使用Accelerometer。



我想在Windows Phone中制作这个程序。

http:// oyunda.mynet.com/topu-kacir





Blue Ball与Accelerometer一起移动,我习惯了这段代码;

Hi all;

I''m make the Windows Phone Application.But I can''t used to Accelerometer.

I want make this program in the Windows Phone.
http://oyunda.mynet.com/topu-kacir


Blue Ball is move with Accelerometer and I used to this code;

if (e.X < 0 && blue_ball.Margin.Left > 0)
                blue_ball.Margin = new Thickness(blue_ball.Margin.Left + e.X * 1.7, blue_ball.Margin.Top, blue_ball.Margin.Right, blue_ball.Margin.Bottom);
            else if (e.X > 0 && blue_ball.Margin.Left < ContentPanel.Width - blue_ball.Width)
                blue_ball.Margin = new Thickness(blue_ball.Margin.Left + e.X * 1.7, blue_ball.Margin.Top, blue_ball.Margin.Right, blue_ball.Margin.Bottom);

            if (e.Y < 0 && blue_ball.Margin.Top < ContentPanel.Height - blue_ball.Height)
                blue_ball.Margin = new Thickness(blue_ball.Margin.Left, blue_ball.Margin.Top + (-e.Y * 1.7), blue_ball.Margin.Right, blue_ball.Margin.Bottom);
            else if (e.Y > 0 && blue_ball.Margin.Top > 0)
                blue_ball.Margin = new Thickness(blue_ball.Margin.Left, blue_ball.Margin.Top + (-e.Y * 1.7), blue_ball.Margin.Right, blue_ball.Margin.Bottom);





RedBall在Grid中随机移动。



如何确定与红球和蓝球的碰撞?



RedBall is move random in Grid.

How can I determine collision with Red and Blue ball?

推荐答案

private bool CheckCollision(FrameworkElement ctl1,FrameworkElement ctl2) 
{ 
     bool retval = false; 
     Point ptTopLeft = new Point(Convert.ToDouble(ctl1.GetValue(Canvas.LeftProperty)), Convert.ToDouble(ctl1.GetValue(Canvas.TopProperty))); 
     Point ptBottomRight = new Point(Convert.ToDouble(ctl1.GetValue(Canvas.LeftProperty)) + ctl1.Width, Convert.ToDouble(ctl1.GetValue(Canvas.TopProperty)) + ctl1.Height); 
     Rect r1 = new Rect(ptTopLeft, ptBottomRight); 
 
    //System.Diagnostics.Debug.WriteLine("+++x:" + ptTopLeft.X.ToString() + " Y " + ptTopLeft.Y.ToString() + " " + ptBottomRight.X.ToString() + " " + ptBottomRight.Y.ToString()); 

    Point ptTopLeft2 = new Point(Convert.ToDouble(ctl2.GetValue(Canvas.LeftProperty)), Convert.ToDouble(ctl2.GetValue(Canvas.TopProperty))); 

    Point ptBottomRight2 = new Point(Convert.ToDouble(ctl2.GetValue(Canvas.LeftProperty)) + ctl2.Width, Convert.ToDouble(ctl2.GetValue(Canvas.TopProperty)) + ctl2.Height); 

    Rect r2 = new Rect(ptTopLeft2, ptBottomRight2); 

    r1.Intersect(r2); 
    if (!r1.IsEmpty) 
    { 
       retval = true; 
    } 
    return retval; 
} 


这篇关于如何使用Accelerometer进行Windows Phone应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆