Hi Team,
I need some help to write a function that allow me to play sound if an arrow is rotating. I have arrow on compass to show direction . I could not find a way to play sound when the arrow is rotating .
thanks
Abdul
Hi Team,
I need some help to write a function that allow me to play sound if an arrow is rotating. I have arrow on compass to show direction . I could not find a way to play sound when the arrow is rotating .
thanks
Abdul
Hi Abdul,
How is the arrow rotating? By a touch response? By a transition? By physics methods? Please show some code for how you’re doing this…
Brent
Hi Brent ,
the rotation is happening at the animateDial function which is basically a runtime listener
Runtime:removeEventListener( “enterFrame”, animateDial )
… the arrow will rotate to point to fixed location. even if you rotate the device, the arrow should adjust and point itself to that location. that is why it is runtime event.
i hope this will help to understand the issue?
i tried this code but the sound keeps playing even there is no clear rotation… if possible to make happend if the rotation is more than cetain degrees . i am not sure if we can do that .
[lua]
animateDial = function( event )
curRotation = arrow.rotation
if soundOn then
audio.play( sfx.tune_snd, { channel=1, loops=0, fadein=100 })
end
--print("image rotation " … arrow.rotation)
local delta = dstRotation - curRotation
--detRotationText.text = dstRotation
if math.abs( delta ) >= 180 then
if delta < -180 then
delta = delta + 360
elseif delta > 180 then
delta = delta - 360
end
end
arrow.rotation = curRotation + delta*0.3
end
[/lua]
thx
Abdul
Hi team , any luck to help in this topic ?
Im confused… so when the arrow spins then you want the sound to play but as soon as the arrow stops spinning when you want the sound to stop? So post the function that includes the sound and the function that makes the arrow spin and comment out the parts where it starts spinning and where it stops…
Hi Sonic,
the script is above if you notice… it is diff to find out when the arrow spins because it is based on direction of compass … i am planning to have sound when the arrow is moving… the issue … i dont have control when it is moving because it is based on gps…
not sure if i need to do runtime function that calculate the x and y of the arrow and when it moves it plays the sound … i am looking for more creative solutions …
thx
Hey! so i dont know what exactly it is you want still but if im understanding correctly then you could use object:getLinearVelocity() to check if the object is moving… and if it is then you make a function that plays the sound…? is that what you want?
this is good idea but it the arrow is normal picture not physics … it just rotates when direction changes … I am still thinking if i can use object:getLinearVelocity() to track the rotation… you can imaging it as analog watch . you need add sound when the it moves clockwise and in this case it will stop somewhere…
ok so i made a sample of what i think you want… here it is… download that zip file…
so when the arrow turns you want a sound to play?
thanks SonicX for your help initiatives… yes I need to play sound when it rotates . the only difference in your code and my code is :
in your code, you know when it will rotate , so it is easy to add sound under your rotateArrow() function
in my code the rotation happened via update function linked to gbs to know the right direction then it adjust using :
as shown above in the code… i will try to simulate the complete code and send it if it is not clear.
thx
Abdulaziz
Do you have a function that makes the arrow rotate? (Im imagining what you want a a gps… like what you get in google maps?) like when a function is called then the other function is called to rotate the arrow? or is is just the gps that makes the arrow move and turn …?
Hi Sonix…
the function is above in the my first post second post it is runtime… i think it is not possible because the arrow will be moving almost all times even if it is .0001 so the sound will be played all times … i think i should change my idea to something else… thanks alot.
Abdul
Hi Abdul,
How is the arrow rotating? By a touch response? By a transition? By physics methods? Please show some code for how you’re doing this…
Brent
Hi Brent ,
the rotation is happening at the animateDial function which is basically a runtime listener
Runtime:removeEventListener( “enterFrame”, animateDial )
… the arrow will rotate to point to fixed location. even if you rotate the device, the arrow should adjust and point itself to that location. that is why it is runtime event.
i hope this will help to understand the issue?
i tried this code but the sound keeps playing even there is no clear rotation… if possible to make happend if the rotation is more than cetain degrees . i am not sure if we can do that .
[lua]
animateDial = function( event )
curRotation = arrow.rotation
if soundOn then
audio.play( sfx.tune_snd, { channel=1, loops=0, fadein=100 })
end
--print("image rotation " … arrow.rotation)
local delta = dstRotation - curRotation
--detRotationText.text = dstRotation
if math.abs( delta ) >= 180 then
if delta < -180 then
delta = delta + 360
elseif delta > 180 then
delta = delta - 360
end
end
arrow.rotation = curRotation + delta*0.3
end
[/lua]
thx
Abdul
Hi team , any luck to help in this topic ?
Im confused… so when the arrow spins then you want the sound to play but as soon as the arrow stops spinning when you want the sound to stop? So post the function that includes the sound and the function that makes the arrow spin and comment out the parts where it starts spinning and where it stops…
Hi Sonic,
the script is above if you notice… it is diff to find out when the arrow spins because it is based on direction of compass … i am planning to have sound when the arrow is moving… the issue … i dont have control when it is moving because it is based on gps…
not sure if i need to do runtime function that calculate the x and y of the arrow and when it moves it plays the sound … i am looking for more creative solutions …
thx
Hey! so i dont know what exactly it is you want still but if im understanding correctly then you could use object:getLinearVelocity() to check if the object is moving… and if it is then you make a function that plays the sound…? is that what you want?
this is good idea but it the arrow is normal picture not physics … it just rotates when direction changes … I am still thinking if i can use object:getLinearVelocity() to track the rotation… you can imaging it as analog watch . you need add sound when the it moves clockwise and in this case it will stop somewhere…
ok so i made a sample of what i think you want… here it is… download that zip file…
so when the arrow turns you want a sound to play?