I am working on a sample game demo in which i just put an image in canvas and on android device sensor changes the canvas translate and move for appropriate position. I want to translate canvas just on y-axis (up-down), and rotate it on x-axis. but when i rotate the canvas first time my y-axis coordinates changes and the transformation done on x-axis.
I know the problem with angle of the canvas rotation and calculation of new x,y coordinates but i don’t know how to do it.
this is the sample code:
in my activity class
@Override
public void onSensorChanged(int sensor, float[] values) {
// TODO Auto-generated method stub
rotateX = values[0];
translateY = values[1];
Game.setDirection(rotateX,translateY);
}
now in Game view class in onDraw() method
canvas.rotate(rotateX, imageCenterX, imageCenterY);
canvas.translate(0,translateY);
Thanx in advance.
I solved my problem.
I just
swap the method of canvas.Like
Then it works fine.