开发者

How to move an image on a mobile phone with my finger?

I'm just getting started with Mobile Phone development and want to开发者_C百科 know how do I get an image (of a rock) to follow my fingers as I move it around the screen.

Also, how can I 'push' the rock and let it roll a few pixels?


You'll need to look at the MouseDown and MouseMove events. On MouseDown you'll want to capture the current x and y co-ordinates of the mouse:

private Point trackPoint;
trackPoint= new Point(x, y);

On MouseMove, you'll need to calculate the differences between the original points x and y and the new mouse positions x and y (where e is the EventArgs of the MouseMove event):

int xDiff = trackPoint.X - e.X;
int yDiff = trackPoint.Y - e.Y;

Then update the tracking position

trackPoint = new Point(e.X, e.Y);

Then, move the Image by the xDiff and yDiff:

Image.Location = new Point(Image.Location.X - xDiff, Image.Location.Y - yDiff);

This is completely untested and I don't guarantee the above will work as-is, but should point you in the right direction.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜