Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Game Development - Moving the phone

First of all, sorry for the vague title. I have no other ideas of what could possibly be put there, but you'll see this for yourself as you read on.

I am a very new Java developer for android and a martian to game development, therefore my question is not so related to particulars as it is related to theory and possibilities.

I'm interested in how I can develop my game so if holding the phone horizontally and it is tilted one way or another, an object will move in that direction. I'm sure this is very common and easily done but what about if I wanted the top speed to increase the further it was turned, and the acceleration to increase the quicker it was turned?

I honestly have no idea of the complexity of this question, whether you will laugh and give me one line of code or whether it's something you just can't teach.

Either way, thanks for reading, I look forward to your responses.

like image 407
Sam Jackson Avatar asked Sep 10 '11 16:09

Sam Jackson


2 Answers

Check this out http://mobilestrategist.blogspot.com/2010/01/android-accelerometer-and-orientation.html

This gives you what you need to do what you're asking for, but as the other answer suggests, you may be running before you crawl here. I have been writing Android for 2 years and have yet to take advantage of the accelerometer. Though if you're just looking to noodle around with the device's capabilities, this is as good a place to start as any, I suppose.

like image 156
Yevgeny Simkin Avatar answered Sep 30 '22 01:09

Yevgeny Simkin


You could read about sensors & sensor events.

TYPE_ACCELEROMETER is perhaps what you are looking for...

like image 30
loxxy Avatar answered Sep 30 '22 01:09

loxxy