你如何在c#中将图像旋转到鼠标的位置? [英] how do you rotate an image to the position of the mouse in c#?

查看:54
本文介绍了你如何在c#中将图像旋转到鼠标的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个有坦克的游戏.我需要知道如何将炮塔旋转到鼠标的位置或触摸的位置(Windows Phone 7).我还想限制旋转,例如炮塔可以旋转超过 90° 和 270°.

i am making a game where there's a tank. I need to know how i can rotate the turret to the position of the mouse, or the position of a touch (windows phone 7). I would also like to limit the rotations, e.g the turret can rotate past 90° and 270°.

最简单、最有效的方法是什么?

What's the easiest and most efficient way to do this?

提前致谢.

推荐答案

笼统地说,知道你的坦克的位置,你可以从相关事件中得到触摸的位置,然后计算出两者之间的角度使用简单的三角函数.计算出角度后,您可以应用任何您想要将其限制在特定范围内的逻辑.

In loose terms, knowing the position of your tank, you can get the position of the touch from the relevant event, and then work out the angle between the two using simple trigonometry. Having worked out the angle, you can then apply whatever logic you want to limit it to a specific range.

有关 Windows Phone 7 中触摸事件的详细信息,Jeff Prosise 有一系列出色的博文:

For detailed information about the touch events in Windows Phone 7, Jeff Prosise has an excellent series of blog posts:

这篇关于你如何在c#中将图像旋转到鼠标的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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