开发者

rotate image depending on user touch on screen

开发者 https://www.devze.com 2023-01-24 07:14 出处:网络
i am developing game.i am displaying gun object center bottom of the screen.when user tap on screen i need to rotate g开发者_JS百科un that direction.i done rotating image.but when user tap on screen i

i am developing game.i am displaying gun object center bottom of the screen.when user tap on screen i need to rotate g开发者_JS百科un that direction.i done rotating image.but when user tap on screen i need to rotate image that direction.can you please help me

Thanks in advance

Aswan


is your image a bitmap? could you convert it to one? Would an onClick listener not work and when the user clicks do something like.. http://www.anddev.org/resize_and_rotate_image_-_example-t621.html

Seeing some code as to what you've attempting would be nice also. The following will help you with checking if the bitmap has been clicked in case you're stuck on that also http://developer.android.com/reference/android/view/View.html . I've never attemped this myself but I think that would work. Try redrawing the bitmap when you have resized it.


Just use onTouchListener for your View and use this code for that

     @Override
 public boolean onTouch(View v, MotionEvent event) {
    float currentX = event.getX();
    float currentY = event.getY();
    Log.i(TAG, "action type is"+event.getAction());
    switch (event.getAction()) {
    case MotionEvent.ACTION_MOVE: {
        Log.i(TAG, "Entering in onTouch");
        double rotationAngleRadians = Math.atan2(currentX - dialer.centerX,      dialer.centerY - currentY);
        dialer.rotationAngle = (int) Math.toDegrees(rotationAngleRadians);
        Log.i(TAG, "rotaion angle"+dialer.rotationAngle);
        dialer.invalidate();
        return true;
    }
    }
    return true;
}
0

精彩评论

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