How to change the accelerometer to be faster...

Hello i can't seem to get the accelerometer tilt motion to work like it does on the game "Tilt Monster"... what i'm I doing wrong here ??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
display.setStatusBar (display.HiddenStatusBar)
--> Hides the status bar
 
local physics = require ("physics")
physics.start()
physics.setGravity(0,0)
--> start physics engine and set the gravity (I'm using 0 to start, you might want to change this.)
 
background = display.newImage ("background.png")
--> Sets the background
 
ball = display.newImage ("ball.png")
ball.x = 160
ball.y = 200
physics.addBody(ball, {friction = 1.0, bounce=0.6})
--> Adds the ball and adds physics to the ball
 
local motionx = 0
local motiony = 0
 
local function onAccelerate( event )
        motionx = 35 * event.xGravity
        motiony = 35 * event.yGravity
end
Runtime:addEventListener ("accelerometer", onAccelerate)
 
local function moveball (event)
ball.x = ball.x + motionx
ball.y = ball.y - motiony
end
Runtime:addEventListener("enterFrame", moveball)

well you can increase the 35 to 45 or 55 at motionx and motion y

local function onAccelerate( event )
motionx = 35 * event.xGravity
motiony = 35 * event.yGravity
end

You could setting the accelerometer by using: system.setAccelerometerInterval( x ).

it seems to be a delay once it hits the sides...

It's hard to comment on the sides issue because I don't see the code for that. I'm not sure this is the best/most efficient way of doing things but you could try just letting physics/gravity move the ball on it's own by replacing move ball/on accelerate with something like:

physics.setGravity(x*event.xGravity,-x*event.yGravity)

It's what I did in the one game I currently have released and it worked pretty well for me.

If you can share the code for the sides that would help.

The code is the same one above.. As soon the ball hits the wall (one side) there is a delay on the opposite movement, so for example if you till left and it hits the wall there is a delay when tilling right and the same goes the other way around... But i will try what you are using... If i can get it to work... I'm new to this and know nothing... Still learning. just wish these community was more active, is kinda dead....

Do you want the ball to bounce off the side? What exactly are you trying to achieve?

Well basically no lag, as soon as you move to one see the ball moves to the other, basically the same way as Tilt Monster... is so responsive to the tilt...

Hey,

I tried your code and it worked just. I've never played/looked at the source code for tilt monster (yet) but I'm not sure if you knew this but the whole game is open source now.

You can find the link here: http://developer.anscamobile.com/code/tilt-monster

Hopefully that you'll help you.

views:1425 update:2011/10/5 21:23:48
corona forums © 2003-2011