I developed some functions to deal with this as part of the Useful Community Functions project. Assuming what you want is for the sprite to move up, down, left and right, and set the calibration of the device to a position the user finds comfortable, then this will do the trick. I've already posted this on the forums, but here's a copy of my original post.
===========================
Here's an improved version of my accelerometer functions. The first is the same but I'll repost it anyway, the rest now have deadzone options in both X and Y, as well as sensitivity options so you can adjust the speed directly within the function. Again I used the accelerometer example from the App Game Kit examples folder as the basis for testing these functions.
Startup code:
Type _Acc
top as float
middle as float
bottom as float
range as float
multi as float
EndType
Global accel as _Acc
SetAccelerometer()
Function SetAccelerometer()
//start a loop and display this starting message
Repeat
Print("Hold your tablet in a natrual position.")
Print("And tap the screen to finish calibration.")
c# = GetDirectionY() //get the position of the device
Sync()
Until GetPointerPressed() = 1
accel.range = 1 - c# //this is the range of avilible movement
accel.multi = 1 / accel.range
accel.middle = c# //this is the resting position of the device
accel.top = accel.middle - accel.range //this sets the upper range of movement
accel.bottom = 1 //this sets the lower range of movement
EndFunction
float = GetDirectionYOffset(deadzone, sensitivity)
deadzone as float, range is always between 0 and 1
sensitivity as float, multiplies the outputted function value
Function GetDirectionYOffset(deadzone as float, sensitivity as float)
//get the position
y# = GetDirectionY()
//limit the overall values
if y# < accel.top then y# = accel.top
if y# > accel.bottom then y# = accel.bottom
//adjust the adjusted data between -1 and 1
y# = y# - accel.middle
If y# < 0
y# = abs(y#) * accel.multi
//apply the dead zone
If y# < deadzone
y# = 0
Else
y# = y# * sensitivity //apply sensitivity
y# = y# - y# - y#
EndIf
Else
y# = y# * accel.multi
If y# < deadzone then y# = 0
y# = y# * sensitivity
EndIf
EndFunction y#
float = GetDirectionXOffset(deadzone, sensitivity)
deadzone as float, range is always between 0 and 1
sensitivity as float, multiplies the outputted function value
Function GetDirectionXOffset(deadzone as float, sensitivity as float)
x# = GetDirectionX()
If x# < 0
x# = abs(x#)
If x# < deadzone
x# = 0
Else
x# = x# * sensitivity
x# = x# - x# - x#
EndIf
Else
If x# < deadzone
x# = 0
Else
x# = x# * sensitivity
EndIf
EndIf
EndFunction x#
example code (modified version of projects/input/accelerometer/)
// move a sprite around using the accelerometer, platforms like
// Windows, Mac and Meego can fall back to the keyboard
Type _Acc
top as float
middle as float
bottom as float
range as float
multi as float
EndType
Global accel as _Acc
// set a virtual resolution of 320 x 480
SetVirtualResolution ( 320, 480 )
SetAccelerometer()
// display a background
CreateSprite ( LoadImage ( "background3.jpg" ) )
// create a sprite and position it in the center of the screen
CreateSprite ( 1, LoadImage ( "peach.png" ) )
SetSpritePosition ( 1, 160, 200 )
// main loop
do
// display instructions
Print ( "Tilt the device to move the sprite" )
Print ( "Or use the arrow keys if a keyboard" )
Print ( "is present" )
Print ( "" )
// obtain information about the accelerometer
x# = GetDirectionXOffset( 0.25, 2 )
y# = GetDirectionYOffset(0.25, 2)
// print accelerometer data on screen
Print ( x# )
Print ( y# )
// add accelerometer data to our sprites position
SetSpritePosition ( 1, GetSpriteX ( 1 ) + x#, GetSpriteY ( 1 ) + y# )
// make sure sprite can't move past the left of the screen
if ( GetSpriteX ( 1 ) < 10 )
SetSpriteX ( 1, 10 )
endif
// make sure sprite can't move past the right of the screen
if ( GetSpriteX ( 1 ) > 260 )
SetSpriteX ( 1, 260 )
endif
// make sure sprite can't move past the top of the screen
if ( GetSpriteY ( 1 ) < 10 )
SetSpriteY ( 1, 10 )
endif
// make sure sprite can't move past the bottom of the screen
if ( GetSpriteY ( 1 ) > 430 )
SetSpriteY ( 1, 430 )
endif
// update the contents of the screen
sync ( )
loop
Function SetAccelerometer()
//start a loop and display this starting message
Repeat
Print("Hold your tablet in a natrual position.")
Print("And tap the screen to finish calibration.")
c# = GetDirectionY() //get the position of the device
Sync()
Until GetPointerPressed() = 1
accel.range = 1 - c# //this is the range of avilible movement
accel.multi = 1 / accel.range
accel.middle = c# //this is the resting position of the device
accel.top = accel.middle - accel.range //this sets the upper range of movement
accel.bottom = 1 //this sets the lower range of movement
EndFunction
Function GetDirectionYOffset(deadzone as float, sensitivity as float)
//get the position
y# = GetDirectionY()
//limit the overall values
if y# < accel.top then y# = accel.top
if y# > accel.bottom then y# = accel.bottom
//adjust the adjusted data between -1 and 1
y# = y# - accel.middle
If y# < 0
y# = abs(y#) * accel.multi
//apply the dead zone
If y# < deadzone
y# = 0
Else
y# = y# * sensitivity //apply sensitivity
y# = y# - y# - y#
EndIf
Else
y# = y# * accel.multi
If y# < deadzone then y# = 0
y# = y# * sensitivity
EndIf
EndFunction y#
Function GetDirectionXOffset(deadzone as float, sensitivity as float)
x# = GetDirectionX()
If x# < 0
x# = abs(x#)
If x# < deadzone
x# = 0
Else
x# = x# * sensitivity
x# = x# - x# - x#
EndIf
Else
If x# < deadzone
x# = 0
Else
x# = x# * sensitivity
EndIf
EndIf
EndFunction x#
=========================
The benefits of these functions, is that no matter the angle of the pad, the output value is always between 0 and 1 in both directions. So if you multiply them by x then you'll get a value between 0 and x. Also there's a deadzone setting, so your sprite doesn't twitch with every movement of the players tablet, you don't need a high value for this, at 1 it won't move at all, and 0 there's no deadzone at all, so play around with that one until you feel it's right.