Get the angle of rotation?

Arghhh, I can't find anything in the API documentation, I am either blind or to exited ;)

Problem: I am having a object that is rotating. I do need to read the angle of the object, is it possible?

E.g: local Angle = myObject.angle

Joakim

myObject.rotation

I tested that but it only accumulates the value...so I can end up with a value of a couple of thousand...or should I divide it by 360 to get the accurate angle?

Joakim

you can set up a function that will restore rotation to 0 if 360 was achieved...

Yes, but the question is - how do I calculate that when the function is acumulating the value?

Joakim

like that, i did something like that long time ago)

1
2
3
4
5
6
7
8
9
10
11
12
13
local function rotate()
 
obj.rotation = obj.rotation + 10
 
if obj.rotation >= 360 then
obj.rotation = 0
end
 
print("this object rotation is: ".. obj.rotation)
 
end
 
Runtime:addEventListener("enterFrame", rotate)

or you can just do
object.rotation = object.rotation %360
after you add or subtract from the rotation

1
2
3
4
5
6
7
function Loop()
object.rotation = object.rotation +1
object.rotation = object.rotation %360
print(object.rotation)
end
 
Runtime:addEventListener( "enterFrame", Loop )

BrightWaveGames

what does % symbol do?

% = modulus. in this case it limits the range of the rotation to values from 1-360

wow, great to know, definitely useful little symbol)

Woww, thats so great...I have to look in the API documentation about this. Works perfect, just tried it. Big thanks!

Joakim

views:1934 update:2011/12/30 9:10:41
corona forums © 2003-2011