How Do You Stop Object.rotation = Object.rotation + 1

Hi everyone…

I have a non-physics object, that’s rotating in my game, @horacebury, yes it’s that turn-table again… It’s driven by a ‘FrameEnter’ Event Listener. I would like to use a collision event (on an unassociated object) to stop it dead in it’s tracks. Simply setting object.rotation to ‘0’ and removing the EventListener, just resets the object to it’s ‘start position’… I know probably need to get the object ‘angle’ first, but I’m at a bit of a loss.

Mark

***Additional note: Object.angularVelocity = 0  doesn’t work.

Why not set a variable that dictates whether the object should rotate or not:

 
 

 

[lua]
 

local rotateIt = true
 

local gameLoop = function (event)

if rotateIt == true then

object.rotation = object.rotation + 1

 

end

end

 

Runtime:addEventListener(“enterFrame”,gameLoop)

 

[/lua]

Then in your collision event set rotateIt to false.

Superstar!!! Worked a treat… This is the problem when Art Directors decide they’re going to make a game… They always look sexy, but when it comes to coding, we couldn’t write:

<lua> local idiot = true </lua>

on a steamed up window.

Thankyou

No problem.

Actually a neater way to do it would be to put rotateIt as a property of the object like this:

[lua]

object.rotateIt = true

if object.rotateIt == true then

object.rotation = object.rotation + 1

end

[/lua]

This way you could have a rotateIt property on any number of objects that you might want to rotate, if you put them all in a table you could then loop through, check the rotateIt status of each and then rotate or not rotate accordingly.

You also get one of your 200 local variables back into the bargain.

Nice solution Nick!

***Additional note: Object.angularVelocity = 0  doesn’t work.

Why not set a variable that dictates whether the object should rotate or not:

 
 

 

[lua]
 

local rotateIt = true
 

local gameLoop = function (event)

if rotateIt == true then

object.rotation = object.rotation + 1

 

end

end

 

Runtime:addEventListener(“enterFrame”,gameLoop)

 

[/lua]

Then in your collision event set rotateIt to false.

Superstar!!! Worked a treat… This is the problem when Art Directors decide they’re going to make a game… They always look sexy, but when it comes to coding, we couldn’t write:

<lua> local idiot = true </lua>

on a steamed up window.

Thankyou

No problem.

Actually a neater way to do it would be to put rotateIt as a property of the object like this:

[lua]

object.rotateIt = true

if object.rotateIt == true then

object.rotation = object.rotation + 1

end

[/lua]

This way you could have a rotateIt property on any number of objects that you might want to rotate, if you put them all in a table you could then loop through, check the rotateIt status of each and then rotate or not rotate accordingly.

You also get one of your 200 local variables back into the bargain.

Nice solution Nick!

can any one help me with trajectory object not stopping http://forums.coronalabs.com/topic/43378-object-not-stoping-in-my-trajectory-function/?p=225880

can any one help me with trajectory object not stopping http://forums.coronalabs.com/topic/43378-object-not-stoping-in-my-trajectory-function/?p=225880