I am working on an app that is going to use the accelerometer to control the character. The code below is a stripped down version of the Sample App Accelerator 1.
My question is, how do I speed up the movement of the Circle? I’ve tried multiplying, adding, subtracting, but the results I’ve received so far are weird. Any suggestions on how to speed the Circle up?
[code]
display.setStatusBar( display.HiddenStatusBar ) – hide status bar
– Create a circle that moves with Accelerator events (for visual effects)
local centerX = display.contentWidth / 2
local centerY = display.contentHeight / 2
w = display.contentWidth
h = display.contentHeight
print(w … h)
Circle = display.newCircle(0, 0, 20)
Circle.x = centerX
Circle.y = centerY
Circle:setFillColor( 0, 0, 255 ) – blue
local function onAccelerate( event )
frameUpdate = false – update done
– Move our object based on the accelerator values
if(Circle.x < 1) then
Circle.x = 0
elseif (Circle.x > w-3) then
Circle.x = w
else
Circle.x = centerX + (centerX * event.xGravity)
circlex.text = Circle.x … " : " … event.xGravity
end
if(Circle.y < 1) then
Circle.y = 0
elseif (Circle.y > h-3) then
Circle.y = h
else
Circle.y = centerY + (centerY * event.yGravity * -1)
circley.text = Circle.y … " : " … event.yGravity
end
– Display message and sound beep if Shake’n
if event.isShake == true then
– str, location, scrTime, size, color, font
media.playEventSound( soundID )
end
end
local function onFrame()
frameUpdate = true
end
circlex = display.newText(“X:” … Circle.x,5,25)
circley = display.newText(“Y:” … Circle.y,5,45)
Runtime:addEventListener (“accelerometer”, onAccelerate);
Runtime:addEventListener (“enterFrame”, onFrame);
[/code] [import]uid: 14218 topic_id: 7996 reply_id: 307996[/import]