February 11th, 2012, 01:43 PM
|
#1 (permalink)
|
|
New Member
Join Date: Feb 2012
Posts: 3
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
|
move image around with sensor manager
Hey guys,
I'm trying to create a game. What I want to do first is have an airplane which is a image move around on the screen. I look all over the web and try some of the examples they have but I can't get mine to work. So basically I'm using the SensorManger to get the x,y,z values. Now with those values I want to move the image around. How would I do that? Or if there is a better way to do this please let me know. Thanks!
Code:
public
class ObitBlastActivity extends Activity
implements
SensorEventListener {
private SensorManager sensorManager;
TextView xCoor; // declare X axis object
TextView
yCoor; // declare Y axis object
TextView
zCoor; // declare Y axis object
ImageView
myPlane;
@Override
publicvoid onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
xCoor=(TextView)findViewById(R.id.xcoor);
yCoor=(TextView)findViewById(R.id.ycoor);
zCoor=(TextView)findViewById(R.id.zcoor);
myPlane = (ImageView)findViewById(R.id.mainAirPlane);
sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
// add listener. The listener will be HelloAndroid (this) class
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
}
publicvoid onAccuracyChanged(Sensor sensor,int accuracy){
}
publicvoid onSensorChanged(SensorEvent event){
// check sensor type
if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
// assign directions
float x=event.values[0];
float y=event.values[1];
float z=event.values[2];
xCoor.setText("X: "+x);
yCoor.setText("Y: "+y);
zCoor.setText("Z: "+z);
//Draw my plane here..........
}
}
}
|
|
|
Last edited by phamsta; February 11th, 2012 at 02:21 PM.
|
|