开发者

wp7 Haptic Feedback

开发者 https://www.devze.com 2023-01-26 12:08 出处:网络
Where could I fi开发者_如何学运维nd documentation on how to implement haptic feedback for windows phone 7?I want the phone to give short vibrations when a button is pressed.Basically all you need to m

Where could I fi开发者_如何学运维nd documentation on how to implement haptic feedback for windows phone 7? I want the phone to give short vibrations when a button is pressed.


Basically all you need to make the phone vibrate is this:

VibrateController.Default.Start(TimeSpan.FromMilliseconds(200));

I suggest to read this blog as it explains it quite well. The other chapters are interesting too if you haven't already seen them.


I created a vibration class for my buttons so that its easy to call. Here is my code. Please give me +1 if you like.

public class Vibration
    {
        public static void VibrateOnButtonPress()
        {
            Microsoft.Devices.VibrateController.Default.Start(TimeSpan.FromMilliseconds(50));
            System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 0, 200);
            timer.Tick += (tsender, tevt) =>
            {
                var t = tsender as System.Windows.Threading.DispatcherTimer;
                t.Stop();
                Microsoft.Devices.VibrateController.Default.Stop();
            };
            timer.Start();
        }
    }


Perhaps you can use the XNA API to set the vibration of the "GamePad"
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.setvibration.aspx

I'd be curious to know if you get it to work in silverlight, please comment after you try it :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消