views:

41

answers:

1

I'm just getting started with Mobile Phone development and want to 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?

A: 

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.

GenericTypeTea
Thanks. I'll try this.
Bill
Did you have any luck with this?
GenericTypeTea