Hi - sorry, yet another basic question from me:
I’d like to put a speed meter on the screen to show some indication of the speed a display object is moving. I thought I’d be able to use getLinearVelocity for this, and I’m trying the following:
[lua]
function onEveryFrame( e )
local vx, vy = crate:getLinearVelocity()
print (“vx=” … vx)
speedx = vx
return speedx
end
Runtime:addEventListener( “enterFrame”, onEveryFrame )
local speed = display.newText( "speed: " … speedx, 80, 20, native.systemFont, 22 )
speed:setFillColor( 1, 0, 0.5 )
[/lua]
But this doesn’t work.
The values appear in the terminal, but nothing is passed through to the ‘speed’ display object.
My thinking is that
[lua]
return speedx
[/lua]
will feed the value back for the ‘speed’ display object to pick up.
I’ve tried using ‘vx’ instead of ‘speedx’ but it doesn’t help.
Another consideration is where I’m putting the Runtime listener - I’m using Composer and I thought the listener should go within scene:show … but that throws up errors.
(Mini question - I’m passing ‘e’ into the onEveryFrame function - would ‘event’ do just as well?)
Many thanks for any advice.