开发者

Android: moving ball through touch

开发者 https://www.devze.com 2023-01-02 01:57 出处:网络
I am making a simple game for class on an Android phone in which you can change a ball\'s position by touch.I had it working in Processing by simply using mouse position.In Android, I am using the ges

I am making a simple game for class on an Android phone in which you can change a ball's position by touch. I had it working in Processing by simply using mouse position. In Android, I am using the gesture scanner and corresponding methods for various gestures, but I can't figure out the exact way to pull in the coordinates of the touch method into the ball objec开发者_如何学编程t's x/y coordinates. I hope that I am making sense! Thanks so much.


If your ball is an image in an ImageView, then you know the starting position of this ImageView object; save it in prevPosition variable. Whenever you encounter a touch event you will get the coordinates of the location where touch has taken place(currPosition), move your ball from prev location(prevPosition) to this new location and update your prevPosition variable(prevPosition=currPosition).

Hope this helps!!


go with this code it is now included in your new sdk check it here.., thanks, http://developer.android.com/resources/samples/RenderScript/index.html;

0

精彩评论

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