Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Discussion > Android Games

Android Games Whether free or paid, put Games on your Android Phone and play them! Talk about, share and discuss games for Android here. New apps can be found and announced in the Applications Announcements forum linked below.



Reply
 
LinkBack Thread Tools
Old 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
Default 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.......... } } }


phamsta is offline  
Last edited by phamsta; February 11th, 2012 at 02:21 PM.
Reply With Quote
Sponsors
Reply

Bookmarks


Go Back   Android Forums > Android Discussion > Android Games User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 12:52 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo